diff --git a/lib/internal/test_runner/test.js b/lib/internal/test_runner/test.js index e27a700424a076..3d5230b082c3e6 100644 --- a/lib/internal/test_runner/test.js +++ b/lib/internal/test_runner/test.js @@ -222,7 +222,7 @@ class Test extends AsyncResource { } } - const test = new Factory({ fn, name, parent, ...options, ...overrides }); + const test = new Factory({ __proto__: null, fn, name, parent, ...options, ...overrides }); if (parent.waitingOn === 0) { parent.waitingOn = test.testNumber; diff --git a/test/fixtures/test-runner/protoMutation.js b/test/fixtures/test-runner/protoMutation.js new file mode 100644 index 00000000000000..20071b9ecf7c75 --- /dev/null +++ b/test/fixtures/test-runner/protoMutation.js @@ -0,0 +1,3 @@ +'use strict'; + +Object.prototype.skip = true; diff --git a/test/parallel/test-runner-cli.js b/test/parallel/test-runner-cli.js index 8d16205cdaf1bc..7c75396c8abb45 100644 --- a/test/parallel/test-runner-cli.js +++ b/test/parallel/test-runner-cli.js @@ -34,6 +34,22 @@ const testFixtures = fixtures.path('test-runner'); assert(/ok 4 - .+random\.cjs/.test(stdout)); } +{ + // Same but with a prototype mutation in require scripts. + const args = ['--require', join(testFixtures, 'protoMutation.js'), '--test', testFixtures]; + const child = spawnSync(process.execPath, args); + + const stdout = child.stdout.toString(); + assert.match(stdout, /ok 1 - .+index\.test\.js/); + assert.match(stdout, /not ok 2 - .+random\.test\.mjs/); + assert.match(stdout, /not ok 1 - this should fail/); + assert.match(stdout, /ok 3 - .+subdir.+subdir_test\.js/); + assert.match(stdout, /ok 4 - .+random\.cjs/); + assert.strictEqual(child.status, 1); + assert.strictEqual(child.signal, null); + assert.strictEqual(child.stderr.toString(), ''); +} + { // User specified files that don't match the pattern are still run. const args = ['--test', testFixtures, join(testFixtures, 'index.js')];