Skip to content

Commit

Permalink
wdio-local-runner: unpipe streams in the end (#3882)
Browse files Browse the repository at this point in the history
* wdio-local-runner: unpipe streams in the end

* wdio-local-runner: transformStream _final test
  • Loading branch information
mgrybyk authored and christian-bromann committed Apr 25, 2019
1 parent 6e5d2a0 commit 45962bc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
10 changes: 3 additions & 7 deletions packages/wdio-local-runner/src/transformStream.js
Expand Up @@ -19,12 +19,8 @@ export default class RunnerTransformStream extends Transform {
callback()
}

_final () {
/**
* we don't want to do anything here otherwise we would end the
* stream of the local runner that captures stdout/stderr or all
* runners and therefor would loose all incoming messages after
* the first runner finishes.
*/
_final (callback) {
this.unpipe()
callback()
}
}
35 changes: 23 additions & 12 deletions packages/wdio-local-runner/tests/transformStream.test.js
@@ -1,27 +1,38 @@
import RunnerTransformStream from '../src/transformStream'
import { DEBUGGER_MESSAGES } from '../src/constants'

jest.mock('stream', () => {
class TransformMock {
constructor () {
this.push = jest.fn()
}
}

return { Transform: TransformMock }
})

test('should add cid to message', () => {
const stream = new RunnerTransformStream('0-5')
const cb = jest.fn()
const pushSpy = jest.spyOn(stream, 'push')

stream._transform('foobar', null, cb)
expect(stream.push).toBeCalledWith('[0-5] foobar')
expect(pushSpy).toBeCalledWith('[0-5] foobar')
expect(cb).toBeCalled()
})

test('should ignore debugger messages', () => {
const stream = new RunnerTransformStream('0-5')
const cb = jest.fn()
const pushSpy = jest.spyOn(stream, 'push')

DEBUGGER_MESSAGES.forEach(m => stream._transform(`${m} foobar`, null, cb))
expect(stream.push).toBeCalledTimes(0)
expect(pushSpy).toBeCalledTimes(0)
})

test('should ignore debugger messages', (done) => {
const stream = new RunnerTransformStream('0-5')
const stream2 = new RunnerTransformStream('0-6')

stream2.pipe(stream)
const cb = jest.fn()
stream.on('unpipe', cb)

const finalSpy = jest.spyOn(stream, '_final')

stream.end(() => {
expect(cb).toBeCalled()
expect(finalSpy).toBeCalled()
done()
})
})

0 comments on commit 45962bc

Please sign in to comment.