nodejs/test/parallel/test-worker-relative-path-d...

17 lines
532 B
JavaScript
Raw Normal View History

2022-08-16 11:12:47 +08:00
'use strict';
const common = require('../common');
const path = require('path');
const assert = require('assert');
const { Worker, isMainThread, parentPort } = require('worker_threads');
if (isMainThread) {
const cwdName = path.relative('../', '.');
const relativePath = path.relative('.', __filename);
const w = new Worker(path.join('..', cwdName, relativePath));
w.on('message', common.mustCall((message) => {
assert.strictEqual(message, 'Hello, world!');
}));
} else {
parentPort.postMessage('Hello, world!');
}