You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.3 KiB
61 lines
1.3 KiB
3 years ago
|
'use strict'
|
||
|
|
||
|
const { test } = require('tap')
|
||
|
const { join } = require('path')
|
||
|
const { file } = require('./helper')
|
||
|
const ThreadStream = require('..')
|
||
|
|
||
|
test('bundlers support with .js file', function (t) {
|
||
|
t.plan(1)
|
||
|
|
||
|
globalThis.__bundlerPathsOverrides = {
|
||
|
'thread-stream-worker': join(__dirname, 'custom-worker.js')
|
||
|
}
|
||
|
|
||
|
const dest = file()
|
||
|
|
||
|
process.on('uncaughtException', error => {
|
||
|
console.log(error)
|
||
|
})
|
||
|
|
||
|
const stream = new ThreadStream({
|
||
|
filename: join(__dirname, 'to-file.js'),
|
||
|
workerData: { dest },
|
||
|
sync: true
|
||
|
})
|
||
|
|
||
|
stream.worker.removeAllListeners('message')
|
||
|
stream.worker.once('message', message => {
|
||
|
t.equal(message.code, 'CUSTOM-WORKER-CALLED')
|
||
|
})
|
||
|
|
||
|
stream.end()
|
||
|
})
|
||
|
|
||
|
test('bundlers support with .mjs file', function (t) {
|
||
|
t.plan(1)
|
||
|
|
||
|
globalThis.__bundlerPathsOverrides = {
|
||
|
'thread-stream-worker': join(__dirname, 'custom-worker.js')
|
||
|
}
|
||
|
|
||
|
const dest = file()
|
||
|
|
||
|
process.on('uncaughtException', error => {
|
||
|
console.log(error)
|
||
|
})
|
||
|
|
||
|
const stream = new ThreadStream({
|
||
|
filename: join(__dirname, 'to-file.mjs'),
|
||
|
workerData: { dest },
|
||
|
sync: true
|
||
|
})
|
||
|
|
||
|
stream.worker.removeAllListeners('message')
|
||
|
stream.worker.once('message', message => {
|
||
|
t.equal(message.code, 'CUSTOM-WORKER-CALLED')
|
||
|
})
|
||
|
|
||
|
stream.end()
|
||
|
})
|