From ae284f73862531fd863be5fa435aa28a420b71c7 Mon Sep 17 00:00:00 2001 From: Paul Melnikow Date: Fri, 12 Apr 2019 12:56:15 -0400 Subject: [PATCH] Lint fixes --- index.js | 4 ++-- tests/http.js | 21 ++++++++++++++------- tests/index.js | 6 +++--- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index 691ed96..9ada897 100644 --- a/index.js +++ b/index.js @@ -20,11 +20,11 @@ function propagate(events, source, dest) { // Returns true if the event had listeners, false otherwise. // https://nodejs.org/api/events.html#events_emitter_emit_eventname_args source.emit = (eventName, ...args) => { - let oldEmitHadListeners = oldEmit.call(source, eventName, ...args) + const oldEmitHadListeners = oldEmit.call(source, eventName, ...args) let destEmitHadListeners = false if (events === undefined || events.includes(eventName)) { - destEmitHadListeners = dest.emit.call(dest, eventName, ...args) + destEmitHadListeners = dest.emit(eventName, ...args) } return oldEmitHadListeners || destEmitHadListeners diff --git a/tests/http.js b/tests/http.js index e565e30..ef87b29 100644 --- a/tests/http.js +++ b/tests/http.js @@ -1,22 +1,29 @@ -var test = require('tap').test -var EventEmitter = require('events').EventEmitter -var propagate = require('..') -var http = require('http') +// I checked this in by accident. I'm ambivalent about whether we ought to +// include it. It's a reproduction of the bug from https://github.com/nock/propagate/pull/17 +// though it doesn't elucidate the fix as well as directly testing the return +// values from .emit() + +'use strict' + +const { test } = require('tap') +const { EventEmitter } = require('events') +const propagate = require('..') +const http = require('http') test('is able to propagate response from http.ClientRequest', function(t) { t.plan(1) - var request = http.request({ + const request = http.request({ hostname: 'google.com', path: '/', method: 'GET', }) - var ee1 = new EventEmitter() + const ee1 = new EventEmitter() propagate(request, ee1) - var retrievedData = '' + let retrievedData = '' ee1.on('response', response => { response.on('data', data => { retrievedData = data.toString('utf8') diff --git a/tests/index.js b/tests/index.js index f8ef3f3..6612a68 100644 --- a/tests/index.js +++ b/tests/index.js @@ -146,9 +146,9 @@ test('is able to propagate and map certain events', t => { test('is able to propagate a single event', t => { t.plan(5) - var ee1 = new EventEmitter() - var ee2 = new EventEmitter() - var p = propagate('event-1', ee1, ee2) + const ee1 = new EventEmitter() + const ee2 = new EventEmitter() + const p = propagate('event-1', ee1, ee2) ee2.on('event-1', () => { t.ok(true, 'event 1 received')