diff --git a/test/async-hooks/init-hooks.js b/test/async-hooks/init-hooks.js index 509f443b29a671..14969d8e753b68 100644 --- a/test/async-hooks/init-hooks.js +++ b/test/async-hooks/init-hooks.js @@ -1,7 +1,7 @@ 'use strict'; // Flags: --expose-gc -require('../common'); +const common = require('../common'); const assert = require('assert'); const async_hooks = require('async_hooks'); const util = require('util'); @@ -162,6 +162,10 @@ class ActivityCollector { const stub = { uid, type: 'Unknown', handleIsObject: true }; this._activities.set(uid, stub); return stub; + } else if (!common.isMainThread) { + // Worker threads start main script execution inside of an AsyncWrap + // callback, so we don't yield errors for these. + return null; } else { const err = new Error(`Found a handle whose ${hook}` + ' hook was invoked but not its init hook'); diff --git a/test/async-hooks/test-crypto-pbkdf2.js b/test/async-hooks/test-crypto-pbkdf2.js index 2a0b44db8ce7a8..ed7270d191e903 100644 --- a/test/async-hooks/test-crypto-pbkdf2.js +++ b/test/async-hooks/test-crypto-pbkdf2.js @@ -3,6 +3,8 @@ const common = require('../common'); if (!common.hasCrypto) common.skip('missing crypto'); +if (!common.isMainThread) + common.skip('Worker bootstrapping works differently -> different async IDs'); const assert = require('assert'); const tick = require('./tick'); diff --git a/test/async-hooks/test-crypto-randomBytes.js b/test/async-hooks/test-crypto-randomBytes.js index 76f8f7759503c4..67f5221a5e0b30 100644 --- a/test/async-hooks/test-crypto-randomBytes.js +++ b/test/async-hooks/test-crypto-randomBytes.js @@ -3,6 +3,8 @@ const common = require('../common'); if (!common.hasCrypto) common.skip('missing crypto'); +if (!common.isMainThread) + common.skip('Worker bootstrapping works differently -> different async IDs'); const assert = require('assert'); const tick = require('./tick'); diff --git a/test/async-hooks/test-emit-before-after.js b/test/async-hooks/test-emit-before-after.js index e7744eb4b7bdf0..6a9ceaeefb8c0a 100644 --- a/test/async-hooks/test-emit-before-after.js +++ b/test/async-hooks/test-emit-before-after.js @@ -7,6 +7,9 @@ const spawnSync = require('child_process').spawnSync; const async_hooks = require('internal/async_hooks'); const initHooks = require('./init-hooks'); +if (!common.isMainThread) + common.skip('Worker bootstrapping works differently -> different async IDs'); + switch (process.argv[2]) { case 'test_invalid_async_id': async_hooks.emitBefore(-2, 1); diff --git a/test/async-hooks/test-enable-disable.js b/test/async-hooks/test-enable-disable.js index 27e13efdd8b3fd..df093da608c29c 100644 --- a/test/async-hooks/test-enable-disable.js +++ b/test/async-hooks/test-enable-disable.js @@ -88,6 +88,10 @@ const assert = require('assert'); const tick = require('./tick'); const initHooks = require('./init-hooks'); const { checkInvocations } = require('./hook-checks'); + +if (!common.isMainThread) + common.skip('Worker bootstrapping works differently -> different timing'); + // Include "Unknown"s because hook2 will not be able to identify // the type of the first Immediate since it will miss its `init` invocation. const types = [ 'Immediate', 'Unknown' ]; diff --git a/test/async-hooks/test-fseventwrap.js b/test/async-hooks/test-fseventwrap.js index 2d9e697501efb6..56ada05b760eb6 100644 --- a/test/async-hooks/test-fseventwrap.js +++ b/test/async-hooks/test-fseventwrap.js @@ -1,5 +1,5 @@ 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); const initHooks = require('./init-hooks'); @@ -7,6 +7,9 @@ const tick = require('./tick'); const { checkInvocations } = require('./hook-checks'); const fs = require('fs'); +if (!common.isMainThread) + common.skip('Worker bootstrapping works differently -> different async IDs'); + const hooks = initHooks(); hooks.enable(); diff --git a/test/async-hooks/test-fsreqwrap-readFile.js b/test/async-hooks/test-fsreqwrap-readFile.js index a40b9a35fd4b0b..064cd80a48279e 100644 --- a/test/async-hooks/test-fsreqwrap-readFile.js +++ b/test/async-hooks/test-fsreqwrap-readFile.js @@ -7,6 +7,9 @@ const initHooks = require('./init-hooks'); const { checkInvocations } = require('./hook-checks'); const fs = require('fs'); +if (!common.isMainThread) + common.skip('Worker bootstrapping works differently -> different async IDs'); + const hooks = initHooks(); hooks.enable(); diff --git a/test/async-hooks/test-getaddrinforeqwrap.js b/test/async-hooks/test-getaddrinforeqwrap.js index 787ea26fd344c8..298c4931cce74e 100644 --- a/test/async-hooks/test-getaddrinforeqwrap.js +++ b/test/async-hooks/test-getaddrinforeqwrap.js @@ -7,6 +7,9 @@ const initHooks = require('./init-hooks'); const { checkInvocations } = require('./hook-checks'); const dns = require('dns'); +if (!common.isMainThread) + common.skip('Worker bootstrapping works differently -> different async IDs'); + const hooks = initHooks(); hooks.enable(); diff --git a/test/async-hooks/test-getnameinforeqwrap.js b/test/async-hooks/test-getnameinforeqwrap.js index 071462dddc9b10..a32814e5b5df4a 100644 --- a/test/async-hooks/test-getnameinforeqwrap.js +++ b/test/async-hooks/test-getnameinforeqwrap.js @@ -7,6 +7,9 @@ const initHooks = require('./init-hooks'); const { checkInvocations } = require('./hook-checks'); const dns = require('dns'); +if (!common.isMainThread) + common.skip('Worker bootstrapping works differently -> different async IDs'); + const hooks = initHooks(); hooks.enable(); diff --git a/test/async-hooks/test-graph.signal.js b/test/async-hooks/test-graph.signal.js index 770fe00da4b4a6..4c5b857fc2e08f 100644 --- a/test/async-hooks/test-graph.signal.js +++ b/test/async-hooks/test-graph.signal.js @@ -1,9 +1,10 @@ 'use strict'; const common = require('../common'); -if (common.isWindows) { +if (common.isWindows) common.skip('no signals on Windows'); -} +if (!common.isMainThread) + common.skip('No signal handling available in Workers'); const initHooks = require('./init-hooks'); const verifyGraph = require('./verify-graph'); diff --git a/test/async-hooks/test-no-assert-when-disabled.js b/test/async-hooks/test-no-assert-when-disabled.js index 12742bd5d4f014..70114d1e1140f8 100644 --- a/test/async-hooks/test-no-assert-when-disabled.js +++ b/test/async-hooks/test-no-assert-when-disabled.js @@ -1,6 +1,9 @@ 'use strict'; // Flags: --no-force-async-hooks-checks --expose-internals -require('../common'); +const common = require('../common'); + +if (!common.isMainThread) + common.skip('Workers don\'t inherit per-env state like the check flag'); const async_hooks = require('internal/async_hooks'); diff --git a/test/async-hooks/test-pipewrap.js b/test/async-hooks/test-pipewrap.js index 066458841fabab..f2b5bf985225b9 100644 --- a/test/async-hooks/test-pipewrap.js +++ b/test/async-hooks/test-pipewrap.js @@ -10,6 +10,9 @@ const initHooks = require('./init-hooks'); const { checkInvocations } = require('./hook-checks'); const spawn = require('child_process').spawn; +if (!common.isMainThread) + common.skip('Worker bootstrapping works differently -> different async IDs'); + const hooks = initHooks(); hooks.enable(); diff --git a/test/async-hooks/test-promise.chain-promise-before-init-hooks.js b/test/async-hooks/test-promise.chain-promise-before-init-hooks.js index 00b53300c4d727..873fd272cf2d29 100644 --- a/test/async-hooks/test-promise.chain-promise-before-init-hooks.js +++ b/test/async-hooks/test-promise.chain-promise-before-init-hooks.js @@ -4,6 +4,10 @@ const common = require('../common'); const assert = require('assert'); const initHooks = require('./init-hooks'); const { checkInvocations } = require('./hook-checks'); + +if (!common.isMainThread) + common.skip('Worker bootstrapping works differently -> different async IDs'); + common.crashOnUnhandledRejection(); const p = new Promise(common.mustCall(function executor(resolve, reject) { diff --git a/test/async-hooks/test-promise.js b/test/async-hooks/test-promise.js index 2ee64962131005..d3070b7cbd594d 100644 --- a/test/async-hooks/test-promise.js +++ b/test/async-hooks/test-promise.js @@ -6,6 +6,9 @@ const assert = require('assert'); const initHooks = require('./init-hooks'); const { checkInvocations } = require('./hook-checks'); +if (!common.isMainThread) + common.skip('Worker bootstrapping works differently -> different async IDs'); + common.crashOnUnhandledRejection(); const hooks = initHooks(); diff --git a/test/async-hooks/test-signalwrap.js b/test/async-hooks/test-signalwrap.js index ae4f41c6a413ba..c94d763450ab24 100644 --- a/test/async-hooks/test-signalwrap.js +++ b/test/async-hooks/test-signalwrap.js @@ -3,6 +3,8 @@ const common = require('../common'); if (common.isWindows) common.skip('no signals in Windows'); +if (!common.isMainThread) + common.skip('No signal handling available in Workers'); const assert = require('assert'); const initHooks = require('./init-hooks'); diff --git a/test/async-hooks/test-statwatcher.js b/test/async-hooks/test-statwatcher.js index 52d146306405f8..8085ebf51b3b1d 100644 --- a/test/async-hooks/test-statwatcher.js +++ b/test/async-hooks/test-statwatcher.js @@ -1,12 +1,15 @@ 'use strict'; -require('../common'); +const common = require('../common'); const commonPath = require.resolve('../common'); const assert = require('assert'); const initHooks = require('./init-hooks'); const { checkInvocations } = require('./hook-checks'); const fs = require('fs'); +if (!common.isMainThread) + common.skip('Worker bootstrapping works differently -> different async IDs'); + const hooks = initHooks(); hooks.enable(); diff --git a/test/common/index.js b/test/common/index.js index f76e1cd38cf460..f9cf6ec663efe4 100644 --- a/test/common/index.js +++ b/test/common/index.js @@ -46,6 +46,14 @@ Object.defineProperty(exports, 'PORT', { enumerable: true }); +exports.isMainThread = (() => { + try { + return require('worker').isMainThread; + } catch { + // Worker module not enabled → only a single main thread exists. + return true; + } +})(); exports.isWindows = process.platform === 'win32'; exports.isWOW64 = exports.isWindows && @@ -746,6 +754,10 @@ exports.skipIfInspectorDisabled = function skipIfInspectorDisabled() { if (process.config.variables.v8_enable_inspector === 0) { exports.skip('V8 inspector is disabled'); } + if (!exports.isMainThread) { + // TODO(addaleax): Fix me. + exports.skip('V8 inspector is not available in Workers'); + } }; exports.skipIf32Bits = function skipIf32Bits() { diff --git a/test/known_issues/test-stdin-is-always-net.socket.js b/test/known_issues/test-stdin-is-always-net.socket.js index 9a4c524c4aecc7..8db33bd7a5ce37 100644 --- a/test/known_issues/test-stdin-is-always-net.socket.js +++ b/test/known_issues/test-stdin-is-always-net.socket.js @@ -19,5 +19,5 @@ const proc = spawn( // To double-check this test, set stdio to 'pipe' and uncomment the line below. // proc.stderr.pipe(process.stderr); proc.on('exit', common.mustCall(function(exitCode) { - process.exitCode = exitCode; + assert.strictEqual(exitCode, 0); })); diff --git a/test/parallel/test-async-hooks-disable-during-promise.js b/test/parallel/test-async-hooks-disable-during-promise.js index d6566661294734..ace9bca6799a13 100644 --- a/test/parallel/test-async-hooks-disable-during-promise.js +++ b/test/parallel/test-async-hooks-disable-during-promise.js @@ -3,6 +3,9 @@ const common = require('../common'); const async_hooks = require('async_hooks'); common.crashOnUnhandledRejection(); +if (!common.isMainThread) + common.skip('Worker bootstrapping works differently -> different AsyncWraps'); + const hook = async_hooks.createHook({ init: common.mustCall(2), before: common.mustCall(1), diff --git a/test/parallel/test-async-hooks-disable-gc-tracking.js b/test/parallel/test-async-hooks-disable-gc-tracking.js index a34739a9bb2b95..84c5043aad3335 100644 --- a/test/parallel/test-async-hooks-disable-gc-tracking.js +++ b/test/parallel/test-async-hooks-disable-gc-tracking.js @@ -8,7 +8,7 @@ const common = require('../common'); const async_hooks = require('async_hooks'); const hook = async_hooks.createHook({ - destroy: common.mustCall(1) // only 1 immediate is destroyed + destroy: common.mustCallAtLeast(1) // only 1 immediate is destroyed }).enable(); new async_hooks.AsyncResource('foobar', { requireManualDestroy: true }); diff --git a/test/parallel/test-async-hooks-enable-during-promise.js b/test/parallel/test-async-hooks-enable-during-promise.js index 17b3c884bb9284..29d25de9805de6 100644 --- a/test/parallel/test-async-hooks-enable-during-promise.js +++ b/test/parallel/test-async-hooks-enable-during-promise.js @@ -7,8 +7,8 @@ common.crashOnUnhandledRejection(); Promise.resolve(1).then(common.mustCall(() => { async_hooks.createHook({ init: common.mustCall(), - before: common.mustCall(), - after: common.mustCall(2) + before: common.mustCallAtLeast(), + after: common.mustCallAtLeast(2) }).enable(); process.nextTick(common.mustCall()); diff --git a/test/parallel/test-async-hooks-prevent-double-destroy.js b/test/parallel/test-async-hooks-prevent-double-destroy.js index 5cd9c5e9a017cb..689dc399f9d2f2 100644 --- a/test/parallel/test-async-hooks-prevent-double-destroy.js +++ b/test/parallel/test-async-hooks-prevent-double-destroy.js @@ -8,7 +8,7 @@ const common = require('../common'); const async_hooks = require('async_hooks'); const hook = async_hooks.createHook({ - destroy: common.mustCall(2) // 1 immediate + manual destroy + destroy: common.mustCallAtLeast(2) // 1 immediate + manual destroy }).enable(); { diff --git a/test/parallel/test-async-hooks-promise-triggerid.js b/test/parallel/test-async-hooks-promise-triggerid.js index 7afd005855fb3e..507a8a4ada2c7e 100644 --- a/test/parallel/test-async-hooks-promise-triggerid.js +++ b/test/parallel/test-async-hooks-promise-triggerid.js @@ -3,6 +3,9 @@ const common = require('../common'); const assert = require('assert'); const async_hooks = require('async_hooks'); +if (!common.isMainThread) + common.skip('Worker bootstrapping works differently -> different async IDs'); + common.crashOnUnhandledRejection(); const promiseAsyncIds = []; diff --git a/test/parallel/test-async-hooks-promise.js b/test/parallel/test-async-hooks-promise.js index 4b36f6026b36c6..be1509c7fc23f6 100644 --- a/test/parallel/test-async-hooks-promise.js +++ b/test/parallel/test-async-hooks-promise.js @@ -3,6 +3,9 @@ const common = require('../common'); const assert = require('assert'); const async_hooks = require('async_hooks'); +if (!common.isMainThread) + common.skip('Worker bootstrapping works differently -> different async IDs'); + const initCalls = []; const resolveCalls = []; diff --git a/test/parallel/test-async-hooks-top-level-clearimmediate.js b/test/parallel/test-async-hooks-top-level-clearimmediate.js index e7a5d8f5606118..cc5fcf48eb50b3 100644 --- a/test/parallel/test-async-hooks-top-level-clearimmediate.js +++ b/test/parallel/test-async-hooks-top-level-clearimmediate.js @@ -6,6 +6,9 @@ const common = require('../common'); const assert = require('assert'); const async_hooks = require('async_hooks'); +if (!common.isMainThread) + common.skip('Worker bootstrapping works differently -> different async IDs'); + let seenId, seenResource; async_hooks.createHook({ diff --git a/test/parallel/test-async-wrap-promise-after-enabled.js b/test/parallel/test-async-wrap-promise-after-enabled.js index 9535c080f246b7..5df8f13c008e19 100644 --- a/test/parallel/test-async-wrap-promise-after-enabled.js +++ b/test/parallel/test-async-wrap-promise-after-enabled.js @@ -5,6 +5,9 @@ const common = require('../common'); const assert = require('assert'); +if (!common.isMainThread) + common.skip('Worker bootstrapping works differently -> different timing'); + const async_hooks = require('async_hooks'); const seenEvents = []; diff --git a/test/parallel/test-child-process-custom-fds.js b/test/parallel/test-child-process-custom-fds.js index fbfc8776a37777..c3146564764295 100644 --- a/test/parallel/test-child-process-custom-fds.js +++ b/test/parallel/test-child-process-custom-fds.js @@ -5,6 +5,9 @@ const assert = require('assert'); const internalCp = require('internal/child_process'); const oldSpawnSync = internalCp.spawnSync; +if (!common.isMainThread) + common.skip('stdio is not associated with file descriptors in Workers'); + // Verify that customFds is used if stdio is not provided. { const msg = 'child_process: options.customFds option is deprecated. ' + diff --git a/test/parallel/test-child-process-http-socket-leak.js b/test/parallel/test-child-process-http-socket-leak.js index 30d8601b840626..553a3277532b04 100644 --- a/test/parallel/test-child-process-http-socket-leak.js +++ b/test/parallel/test-child-process-http-socket-leak.js @@ -6,7 +6,6 @@ const common = require('../common'); const assert = require('assert'); const { fork } = require('child_process'); const http = require('http'); -const { kTimeout } = require('internal/timers'); if (process.argv[2] === 'child') { process.once('message', (req, socket) => { @@ -19,6 +18,8 @@ if (process.argv[2] === 'child') { return; } +const { kTimeout } = require('internal/timers'); + let child; let socket; diff --git a/test/parallel/test-child-process-validate-stdio.js b/test/parallel/test-child-process-validate-stdio.js index 4c4f137110b67e..26e4c297672ef6 100644 --- a/test/parallel/test-child-process-validate-stdio.js +++ b/test/parallel/test-child-process-validate-stdio.js @@ -30,7 +30,8 @@ common.expectsError(() => _validateStdio(stdio2, true), { code: 'ERR_IPC_SYNC_FORK', type: Error } ); -{ + +if (common.isMainThread) { const stdio3 = [process.stdin, process.stdout, process.stderr]; const result = _validateStdio(stdio3, false); assert.deepStrictEqual(result, { @@ -42,4 +43,7 @@ common.expectsError(() => _validateStdio(stdio2, true), ipc: undefined, ipcFd: undefined }); +} else { + common.printSkipMessage( + 'stdio is not associated with file descriptors in Workers'); } diff --git a/test/parallel/test-cli-eval.js b/test/parallel/test-cli-eval.js index 201d5a6a49739b..7a2c7a82aa797f 100644 --- a/test/parallel/test-cli-eval.js +++ b/test/parallel/test-cli-eval.js @@ -34,6 +34,9 @@ const path = require('path'); const fixtures = require('../common/fixtures'); const nodejs = `"${process.execPath}"`; +if (!common.isMainThread) + common.skip('process.chdir is not available in Workers'); + if (process.argv.length > 2) { console.log(process.argv.slice(2).join(' ')); process.exit(0); diff --git a/test/parallel/test-cli-node-options-disallowed.js b/test/parallel/test-cli-node-options-disallowed.js index e4ae2d1aea28f2..0351f83c52b50b 100644 --- a/test/parallel/test-cli-node-options-disallowed.js +++ b/test/parallel/test-cli-node-options-disallowed.js @@ -2,6 +2,8 @@ const common = require('../common'); if (process.config.variables.node_without_node_options) common.skip('missing NODE_OPTIONS support'); +if (!common.isMainThread) + common.skip('process.chdir is not available in Workers'); // Test options specified by env variable. diff --git a/test/parallel/test-cli-node-options.js b/test/parallel/test-cli-node-options.js index 2383935f4bb7a3..d851f225fcbc35 100644 --- a/test/parallel/test-cli-node-options.js +++ b/test/parallel/test-cli-node-options.js @@ -2,6 +2,8 @@ const common = require('../common'); if (process.config.variables.node_without_node_options) common.skip('missing NODE_OPTIONS support'); +if (!common.isMainThread) + common.skip('process.chdir is not available in Workers'); // Test options specified by env variable. diff --git a/test/parallel/test-cluster-net-listen-relative-path.js b/test/parallel/test-cluster-net-listen-relative-path.js index ce9ead9e2eb958..7e61cf83da7882 100644 --- a/test/parallel/test-cluster-net-listen-relative-path.js +++ b/test/parallel/test-cluster-net-listen-relative-path.js @@ -11,6 +11,8 @@ const tmpdir = require('../common/tmpdir'); if (common.isWindows) common.skip('On Windows named pipes live in their own ' + 'filesystem and don\'t have a ~100 byte limit'); +if (!common.isMainThread) + common.skip('process.chdir is not available in Workers'); // Choose a socket name such that the absolute path would exceed 100 bytes. const socketDir = './unix-socket-dir'; diff --git a/test/parallel/test-console.js b/test/parallel/test-console.js index 4bac35c65dfc70..1b44ca9c4dac65 100644 --- a/test/parallel/test-console.js +++ b/test/parallel/test-console.js @@ -26,9 +26,10 @@ const assert = require('assert'); assert.ok(process.stdout.writable); assert.ok(process.stderr.writable); // Support legacy API -assert.strictEqual(typeof process.stdout.fd, 'number'); -assert.strictEqual(typeof process.stderr.fd, 'number'); - +if (common.isMainThread) { + assert.strictEqual(typeof process.stdout.fd, 'number'); + assert.strictEqual(typeof process.stderr.fd, 'number'); +} process.once('warning', common.mustCall((warning) => { assert(/no such label/.test(warning.message)); })); diff --git a/test/parallel/test-cwd-enoent-preload.js b/test/parallel/test-cwd-enoent-preload.js index b83ff6ff883a05..2077d9c1478335 100644 --- a/test/parallel/test-cwd-enoent-preload.js +++ b/test/parallel/test-cwd-enoent-preload.js @@ -3,6 +3,8 @@ const common = require('../common'); // Fails with EINVAL on SmartOS, EBUSY on Windows, EBUSY on AIX. if (common.isSunOS || common.isWindows || common.isAIX) common.skip('cannot rmdir current working directory'); +if (!common.isMainThread) + common.skip('process.chdir is not available in Workers'); const assert = require('assert'); const fs = require('fs'); diff --git a/test/parallel/test-cwd-enoent-repl.js b/test/parallel/test-cwd-enoent-repl.js index d42679d8688e06..5ea8abc7e42b52 100644 --- a/test/parallel/test-cwd-enoent-repl.js +++ b/test/parallel/test-cwd-enoent-repl.js @@ -3,6 +3,8 @@ const common = require('../common'); // Fails with EINVAL on SmartOS, EBUSY on Windows, EBUSY on AIX. if (common.isSunOS || common.isWindows || common.isAIX) common.skip('cannot rmdir current working directory'); +if (!common.isMainThread) + common.skip('process.chdir is not available in Workers'); const assert = require('assert'); const fs = require('fs'); diff --git a/test/parallel/test-cwd-enoent.js b/test/parallel/test-cwd-enoent.js index e5d93f46ce60c0..8beb1e3fbe0a05 100644 --- a/test/parallel/test-cwd-enoent.js +++ b/test/parallel/test-cwd-enoent.js @@ -3,6 +3,8 @@ const common = require('../common'); // Fails with EINVAL on SmartOS, EBUSY on Windows, EBUSY on AIX. if (common.isSunOS || common.isWindows || common.isAIX) common.skip('cannot rmdir current working directory'); +if (!common.isMainThread) + common.skip('process.chdir is not available in Workers'); const assert = require('assert'); const fs = require('fs'); diff --git a/test/parallel/test-debug-args.js b/test/parallel/test-debug-args.js index a4ed4f9f1ee719..bb7ec5582401a6 100644 --- a/test/parallel/test-debug-args.js +++ b/test/parallel/test-debug-args.js @@ -1,7 +1,10 @@ 'use strict'; // Flags: --debug-code -require('../common'); +const common = require('../common'); const assert = require('assert'); +if (!common.isMainThread) + common.skip('execArgv does not affect Workers'); + assert(process.execArgv.includes('--debug-code')); diff --git a/test/parallel/test-fs-realpath.js b/test/parallel/test-fs-realpath.js index d7efc748bc9662..599616f5224eb7 100644 --- a/test/parallel/test-fs-realpath.js +++ b/test/parallel/test-fs-realpath.js @@ -24,6 +24,9 @@ const common = require('../common'); const fixtures = require('../common/fixtures'); const tmpdir = require('../common/tmpdir'); +if (!common.isMainThread) + common.skip('process.chdir is not available in Workers'); + const assert = require('assert'); const fs = require('fs'); const path = require('path'); diff --git a/test/parallel/test-fs-write-file-sync.js b/test/parallel/test-fs-write-file-sync.js index 9a19b9f6e93439..2964ac368b5de4 100644 --- a/test/parallel/test-fs-write-file-sync.js +++ b/test/parallel/test-fs-write-file-sync.js @@ -28,6 +28,9 @@ let openCount = 0; let mode; let content; +if (!common.isMainThread) + common.skip('process.umask is not available in Workers'); + // Need to hijack fs.open/close to make sure that things // get closed once they're opened. fs._openSync = fs.openSync; diff --git a/test/parallel/test-module-cjs-helpers.js b/test/parallel/test-module-cjs-helpers.js index f6e80af032a2cd..8e50ecd314dc17 100644 --- a/test/parallel/test-module-cjs-helpers.js +++ b/test/parallel/test-module-cjs-helpers.js @@ -1,5 +1,5 @@ 'use strict'; -// Flags: --expose-internals +// Flags: --expose-internals --experimental-worker require('../common'); const assert = require('assert'); @@ -7,5 +7,5 @@ const { builtinLibs } = require('internal/modules/cjs/helpers'); const hasInspector = process.config.variables.v8_enable_inspector === 1; -const expectedLibs = hasInspector ? 33 : 32; +const expectedLibs = hasInspector ? 34 : 33; assert.strictEqual(builtinLibs.length, expectedLibs); diff --git a/test/parallel/test-preload.js b/test/parallel/test-preload.js index 60d52dbcf1c0cb..5941c0b96bc602 100644 --- a/test/parallel/test-preload.js +++ b/test/parallel/test-preload.js @@ -5,6 +5,8 @@ const fixtures = require('../common/fixtures'); // Refs: https://github.com/nodejs/node/pull/2253 if (common.isSunOS) common.skip('unreliable on SunOS'); +if (!common.isMainThread) + common.skip('process.chdir is not available in Workers'); const assert = require('assert'); const childProcess = require('child_process'); diff --git a/test/parallel/test-process-chdir-errormessage.js b/test/parallel/test-process-chdir-errormessage.js index e511688cc76bd9..0475d7940ce16a 100644 --- a/test/parallel/test-process-chdir-errormessage.js +++ b/test/parallel/test-process-chdir-errormessage.js @@ -1,8 +1,10 @@ 'use strict'; -const { expectsError } = require('../common'); +const common = require('../common'); +if (!common.isMainThread) + common.skip('process.chdir is not available in Workers'); -expectsError( +common.expectsError( () => { process.chdir('does-not-exist'); }, diff --git a/test/parallel/test-process-chdir.js b/test/parallel/test-process-chdir.js index c0a245ffd3483b..a0bfc1652d2216 100644 --- a/test/parallel/test-process-chdir.js +++ b/test/parallel/test-process-chdir.js @@ -1,10 +1,13 @@ 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); const fs = require('fs'); const path = require('path'); +if (!common.isMainThread) + common.skip('process.chdir is not available in Workers'); + const tmpdir = require('../common/tmpdir'); process.chdir('..'); diff --git a/test/parallel/test-process-euid-egid.js b/test/parallel/test-process-euid-egid.js index adae58abebdfb7..904aeacb93fe60 100644 --- a/test/parallel/test-process-euid-egid.js +++ b/test/parallel/test-process-euid-egid.js @@ -3,9 +3,11 @@ const common = require('../common'); const assert = require('assert'); -if (common.isWindows) { - assert.strictEqual(process.geteuid, undefined); - assert.strictEqual(process.getegid, undefined); +if (common.isWindows || !common.isMainThread) { + if (common.isMainThread) { + assert.strictEqual(process.geteuid, undefined); + assert.strictEqual(process.getegid, undefined); + } assert.strictEqual(process.seteuid, undefined); assert.strictEqual(process.setegid, undefined); return; diff --git a/test/parallel/test-process-exit-handler.js b/test/parallel/test-process-exit-handler.js index 22d84f34349b73..d74e320fe63082 100644 --- a/test/parallel/test-process-exit-handler.js +++ b/test/parallel/test-process-exit-handler.js @@ -1,11 +1,14 @@ 'use strict'; -require('../common'); +const common = require('../common'); + +if (!common.isMainThread) + common.skip('execArgv does not affect Workers'); // This test ensures that no asynchronous operations are performed in the 'exit' // handler. // https://github.com/nodejs/node/issues/12322 process.on('exit', () => { - setTimeout(process.abort, 0); // Should not run. + setTimeout(() => process.abort(), 0); // Should not run. for (const start = Date.now(); Date.now() - start < 10;); }); diff --git a/test/parallel/test-process-fatal-exception-tick.js b/test/parallel/test-process-fatal-exception-tick.js index 605f961f639228..f22273e01c9db8 100644 --- a/test/parallel/test-process-fatal-exception-tick.js +++ b/test/parallel/test-process-fatal-exception-tick.js @@ -3,6 +3,9 @@ const common = require('../common'); const assert = require('assert'); +if (!common.isMainThread) + common.skip('Error handling timing is different in Workers'); + // If a process encounters an uncaughtException, it should schedule // processing of nextTicks on the next Immediates cycle but not // before all Immediates are handled diff --git a/test/parallel/test-process-uid-gid.js b/test/parallel/test-process-uid-gid.js index d044c45a32783d..0076425c577b93 100644 --- a/test/parallel/test-process-uid-gid.js +++ b/test/parallel/test-process-uid-gid.js @@ -24,11 +24,13 @@ const common = require('../common'); const assert = require('assert'); -if (common.isWindows) { - // uid/gid functions are POSIX only - assert.strictEqual(process.getuid, undefined); +if (common.isWindows || !common.isMainThread) { + // uid/gid functions are POSIX only, setters are main-thread only. + if (common.isMainThread) { + assert.strictEqual(process.getuid, undefined); + assert.strictEqual(process.getgid, undefined); + } assert.strictEqual(process.setuid, undefined); - assert.strictEqual(process.getgid, undefined); assert.strictEqual(process.setgid, undefined); return; } diff --git a/test/parallel/test-process-umask-mask.js b/test/parallel/test-process-umask-mask.js index 8ec8fc0074ac1b..26ea5b1d9d21de 100644 --- a/test/parallel/test-process-umask-mask.js +++ b/test/parallel/test-process-umask-mask.js @@ -6,6 +6,9 @@ const common = require('../common'); const assert = require('assert'); +if (!common.isMainThread) + common.skip('process.umask is not available in Workers'); + let mask; if (common.isWindows) { diff --git a/test/parallel/test-process-umask.js b/test/parallel/test-process-umask.js index c0c00f3ba397f8..466e0f7d3ad7e0 100644 --- a/test/parallel/test-process-umask.js +++ b/test/parallel/test-process-umask.js @@ -22,6 +22,8 @@ 'use strict'; const common = require('../common'); const assert = require('assert'); +if (!common.isMainThread) + common.skip('process.umask is not available in Workers'); // Note in Windows one can only set the "user" bits. let mask; diff --git a/test/parallel/test-repl-require.js b/test/parallel/test-repl-require.js index 3d1af7f2f8c15e..ecab4ba698911b 100644 --- a/test/parallel/test-repl-require.js +++ b/test/parallel/test-repl-require.js @@ -5,6 +5,9 @@ const fixtures = require('../common/fixtures'); const assert = require('assert'); const net = require('net'); +if (!common.isMainThread) + common.skip('process.chdir is not available in Workers'); + process.chdir(fixtures.fixturesDir); const repl = require('repl'); diff --git a/test/parallel/test-repl-sigint-nested-eval.js b/test/parallel/test-repl-sigint-nested-eval.js index 7f15b7dfeb8b9d..3345de9b4b8b8b 100644 --- a/test/parallel/test-repl-sigint-nested-eval.js +++ b/test/parallel/test-repl-sigint-nested-eval.js @@ -4,6 +4,8 @@ if (common.isWindows) { // No way to send CTRL_C_EVENT to processes from JS right now. common.skip('platform not supported'); } +if (!common.isMainThread) + common.skip('No signal handling available in Workers'); const assert = require('assert'); const spawn = require('child_process').spawn; diff --git a/test/parallel/test-repl-sigint.js b/test/parallel/test-repl-sigint.js index 818111c39bf578..f394b8836e6063 100644 --- a/test/parallel/test-repl-sigint.js +++ b/test/parallel/test-repl-sigint.js @@ -4,6 +4,8 @@ if (common.isWindows) { // No way to send CTRL_C_EVENT to processes from JS right now. common.skip('platform not supported'); } +if (!common.isMainThread) + common.skip('No signal handling available in Workers'); const assert = require('assert'); const spawn = require('child_process').spawn; diff --git a/test/parallel/test-repl-tab-complete.js b/test/parallel/test-repl-tab-complete.js index 6485f8bd17f58b..57c1615e6ffe2b 100644 --- a/test/parallel/test-repl-tab-complete.js +++ b/test/parallel/test-repl-tab-complete.js @@ -26,6 +26,9 @@ const assert = require('assert'); const fixtures = require('../common/fixtures'); const hasInspector = process.config.variables.v8_enable_inspector === 1; +if (!common.isMainThread) + common.skip('process.chdir is not available in Workers'); + // We have to change the directory to ../fixtures before requiring repl // in order to make the tests for completion of node_modules work properly // since repl modifies module.paths. diff --git a/test/parallel/test-require-symlink.js b/test/parallel/test-require-symlink.js index d245c21dd1fdb4..7aad3ee0a7e7e9 100644 --- a/test/parallel/test-require-symlink.js +++ b/test/parallel/test-require-symlink.js @@ -4,6 +4,8 @@ const common = require('../common'); if (!common.canCreateSymLink()) common.skip('insufficient privileges'); +if (!common.isMainThread) + common.skip('process.chdir is not available in Workers'); const assert = require('assert'); const { spawn } = require('child_process'); diff --git a/test/parallel/test-setproctitle.js b/test/parallel/test-setproctitle.js index 1ab6bff6a30848..e5f6858f786ba3 100644 --- a/test/parallel/test-setproctitle.js +++ b/test/parallel/test-setproctitle.js @@ -5,6 +5,8 @@ const common = require('../common'); // FIXME add sunos support if (common.isSunOS) common.skip(`Unsupported platform [${process.platform}]`); +if (!common.isMainThread) + common.skip('Setting the process title from Workers is not supported'); const assert = require('assert'); const exec = require('child_process').exec; diff --git a/test/parallel/test-signal-args.js b/test/parallel/test-signal-args.js index d9fa6df347ddaa..7b72ed6dcb92d5 100644 --- a/test/parallel/test-signal-args.js +++ b/test/parallel/test-signal-args.js @@ -3,9 +3,10 @@ const common = require('../common'); const assert = require('assert'); -if (common.isWindows) { +if (common.isWindows) common.skip('Sending signals with process.kill is not supported on Windows'); -} +if (!common.isMainThread) + common.skip('No signal handling available in Workers'); process.once('SIGINT', common.mustCall((signal) => { assert.strictEqual(signal, 'SIGINT'); diff --git a/test/parallel/test-signal-handler.js b/test/parallel/test-signal-handler.js index a5c900695a54cb..05ec4e7f73faf5 100644 --- a/test/parallel/test-signal-handler.js +++ b/test/parallel/test-signal-handler.js @@ -25,6 +25,8 @@ const common = require('../common'); if (common.isWindows) common.skip('SIGUSR1 and SIGHUP signals are not supported'); +if (!common.isMainThread) + common.skip('Signal handling in Workers is not supported'); console.log(`process.pid: ${process.pid}`); diff --git a/test/parallel/test-stdio-pipe-access.js b/test/parallel/test-stdio-pipe-access.js index ef84bb83803b26..d32c5f0ba9c2e7 100644 --- a/test/parallel/test-stdio-pipe-access.js +++ b/test/parallel/test-stdio-pipe-access.js @@ -1,5 +1,7 @@ 'use strict'; -require('../common'); +const common = require('../common'); +if (!common.isMainThread) + common.skip('Workers don’t have process-like stdio'); // Test if Node handles acessing process.stdin if it is a redirected // pipe without deadlocking diff --git a/test/parallel/test-stdio-pipe-redirect.js b/test/parallel/test-stdio-pipe-redirect.js index b47f5b9cf44af5..60f16b5cb2f6df 100644 --- a/test/parallel/test-stdio-pipe-redirect.js +++ b/test/parallel/test-stdio-pipe-redirect.js @@ -1,5 +1,7 @@ 'use strict'; -require('../common'); +const common = require('../common'); +if (!common.isMainThread) + common.skip('Workers don’t have process-like stdio'); // Test if Node handles redirecting one child process stdout to another // process stdin without crashing. diff --git a/test/parallel/test-timers-immediate-unref-nested-once.js b/test/parallel/test-timers-immediate-unref-nested-once.js new file mode 100644 index 00000000000000..00efce9bcbc8d3 --- /dev/null +++ b/test/parallel/test-timers-immediate-unref-nested-once.js @@ -0,0 +1,9 @@ +'use strict'; + +const common = require('../common'); + +// This immediate should not execute as it was unrefed +// and nothing else is keeping the event loop alive +setImmediate(() => { + setImmediate(common.mustNotCall()).unref(); +}); diff --git a/test/parallel/test-timers-immediate-unref-simple.js b/test/parallel/test-timers-immediate-unref-simple.js index 68497460328c32..369894fcdebbae 100644 --- a/test/parallel/test-timers-immediate-unref-simple.js +++ b/test/parallel/test-timers-immediate-unref-simple.js @@ -2,6 +2,11 @@ const common = require('../common'); +if (!common.isMainThread) { + // Note that test-timers-immediate-unref-nested-once works instead. + common.skip('Worker bootstrapping works differently -> different timing'); +} + // This immediate should not execute as it was unrefed // and nothing else is keeping the event loop alive setImmediate(common.mustNotCall()).unref(); diff --git a/test/parallel/test-trace-events-all.js b/test/parallel/test-trace-events-all.js index 51d0f3c5a265f1..585d4acd18e6d8 100644 --- a/test/parallel/test-trace-events-all.js +++ b/test/parallel/test-trace-events-all.js @@ -4,6 +4,9 @@ const assert = require('assert'); const cp = require('child_process'); const fs = require('fs'); +if (!common.isMainThread) + common.skip('process.chdir is not available in Workers'); + const CODE = 'setTimeout(() => { for (var i = 0; i < 100000; i++) { "test" + i } }, 1)'; const FILE_NAME = 'node_trace.1.log'; diff --git a/test/parallel/test-trace-events-api.js b/test/parallel/test-trace-events-api.js index a68a2850a37c45..5dd4c623c022bb 100644 --- a/test/parallel/test-trace-events-api.js +++ b/test/parallel/test-trace-events-api.js @@ -5,6 +5,8 @@ const common = require('../common'); if (!common.hasTracing) common.skip('missing trace events'); +if (!common.isMainThread) + common.skip('process.chdir is not available in Workers'); const assert = require('assert'); const cp = require('child_process'); diff --git a/test/parallel/test-trace-events-async-hooks.js b/test/parallel/test-trace-events-async-hooks.js index e0b5e0625bea6f..9dd71eda4c6d73 100644 --- a/test/parallel/test-trace-events-async-hooks.js +++ b/test/parallel/test-trace-events-async-hooks.js @@ -5,6 +5,9 @@ const cp = require('child_process'); const fs = require('fs'); const util = require('util'); +if (!common.isMainThread) + common.skip('process.chdir is not available in Workers'); + const CODE = 'setTimeout(() => { for (var i = 0; i < 100000; i++) { "test" + i } }, 1)'; const FILE_NAME = 'node_trace.1.log'; diff --git a/test/parallel/test-trace-events-binding.js b/test/parallel/test-trace-events-binding.js index e52f1c769f5283..f50c1321840980 100644 --- a/test/parallel/test-trace-events-binding.js +++ b/test/parallel/test-trace-events-binding.js @@ -4,6 +4,9 @@ const assert = require('assert'); const cp = require('child_process'); const fs = require('fs'); +if (!common.isMainThread) + common.skip('process.chdir is not available in Workers'); + const CODE = ` process.binding("trace_events").emit( 'b'.charCodeAt(0), 'custom', diff --git a/test/parallel/test-trace-events-bootstrap.js b/test/parallel/test-trace-events-bootstrap.js index 6f8c76564a8ac4..c0f8a49c855b92 100644 --- a/test/parallel/test-trace-events-bootstrap.js +++ b/test/parallel/test-trace-events-bootstrap.js @@ -6,6 +6,9 @@ const path = require('path'); const fs = require('fs'); const tmpdir = require('../common/tmpdir'); +if (!common.isMainThread) + common.skip('process.chdir is not available in Workers'); + const names = [ 'environment', 'nodeStart', diff --git a/test/parallel/test-trace-events-category-used.js b/test/parallel/test-trace-events-category-used.js index a98cb350371da9..d5aff4e1361ce6 100644 --- a/test/parallel/test-trace-events-category-used.js +++ b/test/parallel/test-trace-events-category-used.js @@ -3,6 +3,9 @@ const common = require('../common'); const assert = require('assert'); const cp = require('child_process'); +if (!common.isMainThread) + common.skip('process.chdir is not available in Workers'); + const CODE = `console.log( process.binding("trace_events").categoryGroupEnabled("custom") );`; diff --git a/test/parallel/test-trace-events-file-pattern.js b/test/parallel/test-trace-events-file-pattern.js index 46059ad31d58b2..c8098a43979bb4 100644 --- a/test/parallel/test-trace-events-file-pattern.js +++ b/test/parallel/test-trace-events-file-pattern.js @@ -5,6 +5,9 @@ const assert = require('assert'); const cp = require('child_process'); const fs = require('fs'); +if (!common.isMainThread) + common.skip('process.chdir is not available in Workers'); + tmpdir.refresh(); process.chdir(tmpdir.path); diff --git a/test/parallel/test-trace-events-fs-sync.js b/test/parallel/test-trace-events-fs-sync.js index 60ab5efa3a1d3d..491679c9c03f22 100644 --- a/test/parallel/test-trace-events-fs-sync.js +++ b/test/parallel/test-trace-events-fs-sync.js @@ -4,6 +4,9 @@ const assert = require('assert'); const cp = require('child_process'); const fs = require('fs'); +if (!common.isMainThread) + common.skip('process.chdir is not available in Workers'); + const tests = new Array(); const traceFile = 'node_trace.1.log'; diff --git a/test/parallel/test-trace-events-metadata.js b/test/parallel/test-trace-events-metadata.js index 8b6e97ce35ff3c..440aa00a9c216c 100644 --- a/test/parallel/test-trace-events-metadata.js +++ b/test/parallel/test-trace-events-metadata.js @@ -4,6 +4,9 @@ const assert = require('assert'); const cp = require('child_process'); const fs = require('fs'); +if (!common.isMainThread) + common.skip('process.chdir is not available in Workers'); + const CODE = 'setTimeout(() => { for (var i = 0; i < 100000; i++) { "test" + i } }, 1)'; const FILE_NAME = 'node_trace.1.log'; diff --git a/test/parallel/test-trace-events-none.js b/test/parallel/test-trace-events-none.js index a3f0338f28af35..e6beea3b975355 100644 --- a/test/parallel/test-trace-events-none.js +++ b/test/parallel/test-trace-events-none.js @@ -4,6 +4,9 @@ const assert = require('assert'); const cp = require('child_process'); const fs = require('fs'); +if (!common.isMainThread) + common.skip('process.chdir is not available in Workers'); + const CODE = 'setTimeout(() => { for (var i = 0; i < 100000; i++) { "test" + i } }, 1)'; const FILE_NAME = 'node_trace.1.log'; diff --git a/test/parallel/test-trace-events-perf.js b/test/parallel/test-trace-events-perf.js index 57ac0e3142f66d..8ca5a41eac230e 100644 --- a/test/parallel/test-trace-events-perf.js +++ b/test/parallel/test-trace-events-perf.js @@ -6,6 +6,9 @@ const path = require('path'); const fs = require('fs'); const tmpdir = require('../common/tmpdir'); +if (!common.isMainThread) + common.skip('process.chdir is not available in Workers'); + if (process.argv[2] === 'child') { const { performance } = require('perf_hooks'); diff --git a/test/parallel/test-trace-events-process-exit.js b/test/parallel/test-trace-events-process-exit.js index 9f164ee6279720..aeb9fc19c2982d 100644 --- a/test/parallel/test-trace-events-process-exit.js +++ b/test/parallel/test-trace-events-process-exit.js @@ -4,6 +4,9 @@ const assert = require('assert'); const cp = require('child_process'); const fs = require('fs'); +if (!common.isMainThread) + common.skip('process.chdir is not available in Workers'); + const tmpdir = require('../common/tmpdir'); const FILE_NAME = 'node_trace.1.log'; diff --git a/test/parallel/test-trace-events-v8.js b/test/parallel/test-trace-events-v8.js index 49c34b8f17bbb2..325789e96865a8 100644 --- a/test/parallel/test-trace-events-v8.js +++ b/test/parallel/test-trace-events-v8.js @@ -4,6 +4,9 @@ const assert = require('assert'); const cp = require('child_process'); const fs = require('fs'); +if (!common.isMainThread) + common.skip('process.chdir is not available in Workers'); + const CODE = 'setTimeout(() => { for (var i = 0; i < 100000; i++) { "test" + i } }, 1)'; const FILE_NAME = 'node_trace.1.log'; diff --git a/test/parallel/test-trace-events-vm.js b/test/parallel/test-trace-events-vm.js index 3dc6e263e1b6a1..45724e3e4c88dc 100644 --- a/test/parallel/test-trace-events-vm.js +++ b/test/parallel/test-trace-events-vm.js @@ -6,6 +6,9 @@ const path = require('path'); const fs = require('fs'); const tmpdir = require('../common/tmpdir'); +if (!common.isMainThread) + common.skip('process.chdir is not available in Workers'); + const names = [ 'ContextifyScript::New', 'RunInThisContext', diff --git a/test/sequential/test-async-wrap-getasyncid.js b/test/sequential/test-async-wrap-getasyncid.js index af08d7b6567018..c16624a79e6c83 100644 --- a/test/sequential/test-async-wrap-getasyncid.js +++ b/test/sequential/test-async-wrap-getasyncid.js @@ -39,6 +39,8 @@ common.crashOnUnhandledRejection(); delete providers.STREAMPIPE; delete providers.MESSAGEPORT; delete providers.WORKER; + if (!common.isMainThread) + delete providers.INSPECTORJSBINDING; const objKeys = Object.keys(providers); if (objKeys.length > 0) @@ -281,7 +283,8 @@ if (common.hasCrypto) { // eslint-disable-line node-core/crypto-check testInitialized(req, 'SendWrap'); } -if (process.config.variables.v8_enable_inspector !== 0) { +if (process.config.variables.v8_enable_inspector !== 0 && + common.isMainThread) { const binding = process.binding('inspector'); const handle = new binding.Connection(() => {}); testInitialized(handle, 'Connection'); diff --git a/test/sequential/test-buffer-creation-regression.js b/test/sequential/test-buffer-creation-regression.js index 8c3a09848c9fa9..07deb1db0fe377 100644 --- a/test/sequential/test-buffer-creation-regression.js +++ b/test/sequential/test-buffer-creation-regression.js @@ -30,7 +30,6 @@ try { } catch (e) { if (e instanceof RangeError && acceptableOOMErrors.includes(e.message)) common.skip(`Unable to allocate ${size} bytes for ArrayBuffer`); - throw e; } diff --git a/test/sequential/test-fs-watch.js b/test/sequential/test-fs-watch.js index 3c8ae0eba7d278..1326e62bc10da4 100644 --- a/test/sequential/test-fs-watch.js +++ b/test/sequential/test-fs-watch.js @@ -28,6 +28,9 @@ const path = require('path'); const tmpdir = require('../common/tmpdir'); +if (!common.isMainThread) + common.skip('process.chdir is not available in Workers'); + const expectFilePath = common.isWindows || common.isLinux || common.isOSX || diff --git a/test/sequential/test-init.js b/test/sequential/test-init.js index 5dd8d9ab14ea4f..1b1b09ee833191 100644 --- a/test/sequential/test-init.js +++ b/test/sequential/test-init.js @@ -25,6 +25,9 @@ const assert = require('assert'); const child = require('child_process'); const fixtures = require('../common/fixtures'); +if (!common.isMainThread) + common.skip('process.chdir is not available in Workers'); + if (process.env.TEST_INIT) { return process.stdout.write('Loaded successfully!'); } diff --git a/test/sequential/test-inspector-overwrite-config.js b/test/sequential/test-inspector-overwrite-config.js index 8b641a0048484a..46cb922402f360 100644 --- a/test/sequential/test-inspector-overwrite-config.js +++ b/test/sequential/test-inspector-overwrite-config.js @@ -13,6 +13,10 @@ const common = require('../common'); const assert = require('assert'); + +if (!common.isMainThread) + common.skip('--require does not work with Workers'); + const inspector = require('inspector'); const msg = 'Test inspector logging'; let asserted = false; diff --git a/test/sequential/test-performance.js b/test/sequential/test-performance.js index c5065227a6a410..fdadb0be14ae5d 100644 --- a/test/sequential/test-performance.js +++ b/test/sequential/test-performance.js @@ -4,6 +4,9 @@ const common = require('../common'); const assert = require('assert'); const { performance } = require('perf_hooks'); +if (!common.isMainThread) + common.skip('bootstrapping workers works differently'); + assert(performance); assert(performance.nodeTiming); assert.strictEqual(typeof performance.timeOrigin, 'number'); diff --git a/tools/run-worker.js b/tools/run-worker.js new file mode 100644 index 00000000000000..a9dd773ecf304f --- /dev/null +++ b/tools/run-worker.js @@ -0,0 +1,11 @@ +'use strict'; +if (typeof require === 'undefined') { + console.log('1..0 # Skipped: Not being run as CommonJS'); + process.exit(0); +} + +const path = require('path'); +const { Worker } = require('worker'); + +new Worker(path.resolve(process.cwd(), process.argv[2])) + .on('exit', (code) => process.exitCode = code); diff --git a/tools/test.py b/tools/test.py index e5581e8da41c44..27a27224389e41 100755 --- a/tools/test.py +++ b/tools/test.py @@ -1375,6 +1375,8 @@ def BuildOptions(): help="Expect test cases to fail", default=False, action="store_true") result.add_option("--valgrind", help="Run tests through valgrind", default=False, action="store_true") + result.add_option("--worker", help="Run parallel tests inside a worker context", + default=False, action="store_true") result.add_option("--check-deopts", help="Check tests for permanent deoptimizations", default=False, action="store_true") result.add_option("--cat", help="Print the source of the tests", @@ -1617,6 +1619,11 @@ def Main(): options.node_args.append("--always-opt") options.progress = "deopts" + if options.worker: + run_worker = join(workspace, "tools", "run-worker.js") + options.node_args.append('--experimental-worker') + options.node_args.append(run_worker) + shell = abspath(options.shell) buildspace = dirname(shell)