test(napi): make worker_threads test more complex

This commit is contained in:
LongYinan 2021-12-22 00:12:21 +08:00
parent de27470552
commit 0dbda09cb3
No known key found for this signature in database
GPG key ID: C3666B7FC82ADAD7
2 changed files with 5 additions and 3 deletions

View file

@ -3,13 +3,13 @@ import { Worker } from 'worker_threads'
import test from 'ava'
import { DEFAULT_COST } from '../index'
import { DEFAULT_COST, Animal, Kind } from '../index'
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) => {
t.is(msg, DEFAULT_COST)
t.is(msg, Animal.withKind(Kind.Cat).whoami() + DEFAULT_COST)
resolve()
})
})

View file

@ -2,4 +2,6 @@ const { parentPort } = require('worker_threads')
const native = require('../index')
parentPort.postMessage(native.DEFAULT_COST)
parentPort.postMessage(
native.Animal.withKind(native.Kind.Cat).whoami() + native.DEFAULT_COST,
)