11cb0ef41Sopenharmony_ciimport * as common from '../common/index.mjs'; 21cb0ef41Sopenharmony_ciimport * as fixtures from '../common/fixtures.mjs'; 31cb0ef41Sopenharmony_ciimport tmpdir from '../common/tmpdir.js'; 41cb0ef41Sopenharmony_ciimport assert from 'node:assert'; 51cb0ef41Sopenharmony_ciimport path from 'node:path'; 61cb0ef41Sopenharmony_ciimport fs from 'node:fs/promises'; 71cb0ef41Sopenharmony_ciimport { NodeInstance } from '../common/inspector-helper.js'; 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_cicommon.skipIfInspectorDisabled(); 111cb0ef41Sopenharmony_citmpdir.refresh(); 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ci{ 141cb0ef41Sopenharmony_ci const child = new NodeInstance( 151cb0ef41Sopenharmony_ci ['--test', '--inspect-brk=0'], 161cb0ef41Sopenharmony_ci undefined, 171cb0ef41Sopenharmony_ci fixtures.path('test-runner/default-behavior/index.test.js') 181cb0ef41Sopenharmony_ci ); 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ci let stdout = ''; 211cb0ef41Sopenharmony_ci let stderr = ''; 221cb0ef41Sopenharmony_ci child.on('stdout', (line) => stdout += line); 231cb0ef41Sopenharmony_ci child.on('stderr', (line) => stderr += line); 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ci const session = await child.connectInspectorSession(); 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ci await session.send([ 281cb0ef41Sopenharmony_ci { method: 'Runtime.enable' }, 291cb0ef41Sopenharmony_ci { method: 'Runtime.runIfWaitingForDebugger' }]); 301cb0ef41Sopenharmony_ci 311cb0ef41Sopenharmony_ci session.disconnect(); 321cb0ef41Sopenharmony_ci assert.match(stderr, 331cb0ef41Sopenharmony_ci /Warning: Using the inspector with --test forces running at a concurrency of 1\. Use the inspectPort option to run with concurrency/); 341cb0ef41Sopenharmony_ci} 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ci{ 381cb0ef41Sopenharmony_ci const args = ['--test', '--inspect=0', fixtures.path('test-runner/index.js')]; 391cb0ef41Sopenharmony_ci const { stderr, stdout, code, signal } = await common.spawnPromisified(process.execPath, args); 401cb0ef41Sopenharmony_ci 411cb0ef41Sopenharmony_ci assert.match(stderr, 421cb0ef41Sopenharmony_ci /Warning: Using the inspector with --test forces running at a concurrency of 1\. Use the inspectPort option to run with concurrency/); 431cb0ef41Sopenharmony_ci assert.match(stdout, /not ok 1 - .+index\.js/); 441cb0ef41Sopenharmony_ci assert.strictEqual(code, 1); 451cb0ef41Sopenharmony_ci assert.strictEqual(signal, null); 461cb0ef41Sopenharmony_ci} 471cb0ef41Sopenharmony_ci 481cb0ef41Sopenharmony_ci 491cb0ef41Sopenharmony_ci{ 501cb0ef41Sopenharmony_ci // File not found. 511cb0ef41Sopenharmony_ci const args = ['--test', '--inspect=0', 'a-random-file-that-does-not-exist.js']; 521cb0ef41Sopenharmony_ci const { stderr, stdout, code, signal } = await common.spawnPromisified(process.execPath, args); 531cb0ef41Sopenharmony_ci 541cb0ef41Sopenharmony_ci assert.strictEqual(stdout, ''); 551cb0ef41Sopenharmony_ci assert.match(stderr, /^Could not find/); 561cb0ef41Sopenharmony_ci assert.doesNotMatch(stderr, /Warning: Using the inspector with --test forces running at a concurrency of 1\. Use the inspectPort option to run with concurrency/); 571cb0ef41Sopenharmony_ci assert.strictEqual(code, 1); 581cb0ef41Sopenharmony_ci assert.strictEqual(signal, null); 591cb0ef41Sopenharmony_ci} 601cb0ef41Sopenharmony_ci 611cb0ef41Sopenharmony_ci 621cb0ef41Sopenharmony_ci// Outputs coverage when event loop is drained, with no async logic. 631cb0ef41Sopenharmony_ci{ 641cb0ef41Sopenharmony_ci const coverageDirectory = path.join(tmpdir.path, 'coverage'); 651cb0ef41Sopenharmony_ci async function getCoveredFiles() { 661cb0ef41Sopenharmony_ci const coverageFiles = await fs.readdir(coverageDirectory); 671cb0ef41Sopenharmony_ci const files = new Set(); 681cb0ef41Sopenharmony_ci for (const coverageFile of coverageFiles) { 691cb0ef41Sopenharmony_ci const coverage = JSON.parse(await fs.readFile(path.join(coverageDirectory, coverageFile))); 701cb0ef41Sopenharmony_ci for (const { url } of coverage.result) { 711cb0ef41Sopenharmony_ci if (!url.startsWith('node:')) files.add(url); 721cb0ef41Sopenharmony_ci } 731cb0ef41Sopenharmony_ci } 741cb0ef41Sopenharmony_ci return files; 751cb0ef41Sopenharmony_ci } 761cb0ef41Sopenharmony_ci 771cb0ef41Sopenharmony_ci const { stderr, code, signal } = await common 781cb0ef41Sopenharmony_ci .spawnPromisified(process.execPath, 791cb0ef41Sopenharmony_ci ['--test', fixtures.path('v8-coverage/basic.js')], 801cb0ef41Sopenharmony_ci { env: { ...process.env, NODE_V8_COVERAGE: coverageDirectory } }); 811cb0ef41Sopenharmony_ci 821cb0ef41Sopenharmony_ci assert.strictEqual(stderr, ''); 831cb0ef41Sopenharmony_ci assert.strictEqual(code, 0); 841cb0ef41Sopenharmony_ci assert.strictEqual(signal, null); 851cb0ef41Sopenharmony_ci const files = await getCoveredFiles(coverageDirectory); 861cb0ef41Sopenharmony_ci assert.ok(files.has(fixtures.fileURL('v8-coverage/basic.js').href)); 871cb0ef41Sopenharmony_ci} 88