Skip to content

Commit

Permalink
test: use stream.emit('message') to send messages to worker (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
10xLaCroixDrinker authored Apr 24, 2024
1 parent bade284 commit 4f022e0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"snazzy": "^9.0.0",
"standard": "^17.0.0",
"tap": "^16.0.0",
"thread-stream": "^2.4.1",
"thread-stream": "^2.6.0",
"tsd": "^0.31.0"
},
"tsd": {
Expand Down
21 changes: 7 additions & 14 deletions test/worker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ function workerTest (filename, description = '') {
errorKey: 'err'
}

stream.worker.postMessage({ code: 'PINO_CONFIG', config: pinoConfig })
// stream.emit('message', { code: 'PINO_CONFIG', config: pinoConfig })
stream.emit('message', { code: 'PINO_CONFIG', config: pinoConfig })

port2.on('message', function (message) {
same(expected.shift(), message.data)
Expand Down Expand Up @@ -156,8 +155,7 @@ function workerTest (filename, description = '') {
})

const lines = expected.map(JSON.stringify).join('\n')
stream.worker.postMessage({ code: 'PINO_CONFIG', config: pinoConfig })
// stream.emit('message', { code: 'PINO_CONFIG', config: pinoConfig })
stream.emit('message', { code: 'PINO_CONFIG', config: pinoConfig })
stream.write(lines)
stream.end()
})
Expand Down Expand Up @@ -209,12 +207,9 @@ function workerTest (filename, description = '') {
})

const lines = expected.map(JSON.stringify).join('\n')
stream.worker.postMessage('not a PINO_CONFIG')
// stream.emit('message', 'not a PINO_CONFIG')
stream.worker.postMessage({ code: 'NOT_PINO_CONFIG', config: { levels: 'foo', messageKey: 'bar', errorKey: 'baz' } })
// stream.emit('message', { code: 'NOT_PINO_CONFIG', config: { levels: 'foo', messageKey: 'bar', errorKey: 'baz' } })
stream.worker.postMessage({ code: 'PINO_CONFIG', config: pinoConfig })
// stream.emit('message', { code: 'PINO_CONFIG', config: pinoConfig })
stream.emit('message', 'not a PINO_CONFIG')
stream.emit('message', { code: 'NOT_PINO_CONFIG', config: { levels: 'foo', messageKey: 'bar', errorKey: 'baz' } })
stream.emit('message', { code: 'PINO_CONFIG', config: pinoConfig })
stream.write(lines)
stream.end()
})
Expand Down Expand Up @@ -267,8 +262,7 @@ function workerTest (filename, description = '') {

const lines = expected.map(JSON.stringify).join('\n')
stream.write(lines)
stream.worker.postMessage({ code: 'PINO_CONFIG', config: pinoConfig })
// stream.emit('message', { code: 'PINO_CONFIG', config: pinoConfig })
stream.emit('message', { code: 'PINO_CONFIG', config: pinoConfig })
stream.end()
})

Expand Down Expand Up @@ -357,8 +351,7 @@ test('waits for the pino config when pipelining', function ({ same, plan }) {
same(expected.shift(), message.data)
})

stream.worker.postMessage({ code: 'PINO_CONFIG', config: pinoConfig })
// stream.emit('message', { code: 'PINO_CONFIG', config: pinoConfig })
stream.emit('message', { code: 'PINO_CONFIG', config: pinoConfig })
stream.write(lines)
stream.end()
})

0 comments on commit 4f022e0

Please sign in to comment.