Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: refactor test-worker #32509

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions test/parallel/test-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
}
6 changes: 3 additions & 3 deletions test/parallel/test-worker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
}