mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
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:
1 parent
57856bc769
commit
dbd030a930
2 files changed
+7
-5
No files matched your search
@@ -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);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user