1'use strict'; 2const { 3 prepareMainThreadExecution, 4 markBootstrapComplete, 5} = require('internal/process/pre_execution'); 6const { getOptionValue } = require('internal/options'); 7const { isUsingInspector } = require('internal/util/inspector'); 8const { run } = require('internal/test_runner/runner'); 9const { setupTestReporters } = require('internal/test_runner/utils'); 10const { 11 codes: { 12 ERR_INVALID_ARG_VALUE, 13 }, 14} = require('internal/errors'); 15const { 16 NumberParseInt, 17 RegExpPrototypeExec, 18 StringPrototypeSplit, 19} = primordials; 20let debug = require('internal/util/debuglog').debuglog('test_runner', (fn) => { 21 debug = fn; 22}); 23 24prepareMainThreadExecution(false); 25markBootstrapComplete(); 26 27let concurrency = getOptionValue('--test-concurrency') || true; 28let inspectPort; 29 30if (isUsingInspector()) { 31 process.emitWarning('Using the inspector with --test forces running at a concurrency of 1. ' + 32 'Use the inspectPort option to run with concurrency'); 33 concurrency = 1; 34 inspectPort = process.debugPort; 35} 36 37let shard; 38const shardOption = getOptionValue('--test-shard'); 39if (shardOption) { 40 if (!RegExpPrototypeExec(/^\d+\/\d+$/, shardOption)) { 41 process.exitCode = 1; 42 43 throw new ERR_INVALID_ARG_VALUE( 44 '--test-shard', 45 shardOption, 46 'must be in the form of <index>/<total>', 47 ); 48 } 49 50 const { 0: indexStr, 1: totalStr } = StringPrototypeSplit(shardOption, '/'); 51 52 const index = NumberParseInt(indexStr, 10); 53 const total = NumberParseInt(totalStr, 10); 54 55 shard = { 56 __proto__: null, 57 index, 58 total, 59 }; 60} 61 62const options = { 63 concurrency, 64 inspectPort, 65 watch: getOptionValue('--watch'), 66 setup: setupTestReporters, 67 shard, 68}; 69debug('test runner configuration:', options); 70run(options).on('test:fail', (data) => { 71 if (data.todo === undefined || data.todo === false) { 72 process.exitCode = 1; 73 } 74}); 75