test: refactor test-worker

PR-URL: https://github.com/nodejs/node/pull/32509
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
This commit is contained in:
himself65 authored and Beth Griggs committed 2020-04-07 16:30:14 +01:00
1 parent 57856bc769
commit dbd030a930
2 files changed
+7 -5

No files matched your search

+4 -2
View File
@@ -3,15 +3,17 @@ const common = require('../common');
const assert = require('assert');
const { Worker, isMainThread, parentPort } = require('worker_threads');
const kTestString = 'Hello, world!';
if (isMainThread) {
const w = new Worker(__filename);
w.on('message', common.mustCall((message) => {
assert.strictEqual(message, 'Hello, world!');
assert.strictEqual(message, kTestString);
}));
} else {
setImmediate(() => {
process.nextTick(() => {
parentPort.postMessage('Hello, world!');
parentPort.postMessage(kTestString);
});
});
}
+3 -3
View File
@@ -2,17 +2,17 @@ import { mustCall } from '../common/index.mjs';
import assert from 'assert';
import { Worker, isMainThread, parentPort } from 'worker_threads';
const TEST_STRING = 'Hello, world!';
const kTestString = 'Hello, world!';
if (isMainThread) {
const w = new Worker(new URL(import.meta.url));
w.on('message', mustCall((message) => {
assert.strictEqual(message, TEST_STRING);
assert.strictEqual(message, kTestString);
}));
} else {
setImmediate(() => {
process.nextTick(() => {
parentPort.postMessage(TEST_STRING);
parentPort.postMessage(kTestString);
});
});
}