Skip to content

Commit

Permalink
Lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmelnikow committed Apr 12, 2019
1 parent fc43ec8 commit ae284f7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 14 additions & 7 deletions tests/http.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
6 changes: 3 additions & 3 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit ae284f7

Please sign in to comment.