2021-12-22 00:24:07 +09:00
|
|
|
import { join } from 'path'
|
|
|
|
import { Worker } from 'worker_threads'
|
|
|
|
|
|
|
|
import test from 'ava'
|
|
|
|
|
2021-12-22 01:12:21 +09:00
|
|
|
import { DEFAULT_COST, Animal, Kind } from '../index'
|
2021-12-22 00:24:07 +09:00
|
|
|
|
|
|
|
test('should be able to require in worker thread', (t) => {
|
|
|
|
const w = new Worker(join(__dirname, 'worker.js'))
|
|
|
|
return new Promise<void>((resolve) => {
|
|
|
|
w.on('message', (msg) => {
|
2021-12-22 01:12:21 +09:00
|
|
|
t.is(msg, Animal.withKind(Kind.Cat).whoami() + DEFAULT_COST)
|
2021-12-22 00:24:07 +09:00
|
|
|
resolve()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.then(() => w.terminate())
|
|
|
|
.then(() => {
|
|
|
|
t.pass()
|
|
|
|
})
|
|
|
|
})
|