1import * as common from '../common/index.mjs'; 2import * as fixtures from '../common/fixtures.mjs'; 3import tmpdir from '../common/tmpdir.js'; 4import assert from 'node:assert'; 5import path from 'node:path'; 6import fs from 'node:fs/promises'; 7import { NodeInstance } from '../common/inspector-helper.js'; 8 9 10common.skipIfInspectorDisabled(); 11tmpdir.refresh(); 12 13{ 14 const child = new NodeInstance( 15 ['--test', '--inspect-brk=0'], 16 undefined, 17 fixtures.path('test-runner/default-behavior/index.test.js') 18 ); 19 20 let stdout = ''; 21 let stderr = ''; 22 child.on('stdout', (line) => stdout += line); 23 child.on('stderr', (line) => stderr += line); 24 25 const session = await child.connectInspectorSession(); 26 27 await session.send([ 28 { method: 'Runtime.enable' }, 29 { method: 'Runtime.runIfWaitingForDebugger' }]); 30 31 session.disconnect(); 32 assert.match(stderr, 33 /Warning: Using the inspector with --test forces running at a concurrency of 1\. Use the inspectPort option to run with concurrency/); 34} 35 36 37{ 38 const args = ['--test', '--inspect=0', fixtures.path('test-runner/index.js')]; 39 const { stderr, stdout, code, signal } = await common.spawnPromisified(process.execPath, args); 40 41 assert.match(stderr, 42 /Warning: Using the inspector with --test forces running at a concurrency of 1\. Use the inspectPort option to run with concurrency/); 43 assert.match(stdout, /not ok 1 - .+index\.js/); 44 assert.strictEqual(code, 1); 45 assert.strictEqual(signal, null); 46} 47 48 49{ 50 // File not found. 51 const args = ['--test', '--inspect=0', 'a-random-file-that-does-not-exist.js']; 52 const { stderr, stdout, code, signal } = await common.spawnPromisified(process.execPath, args); 53 54 assert.strictEqual(stdout, ''); 55 assert.match(stderr, /^Could not find/); 56 assert.doesNotMatch(stderr, /Warning: Using the inspector with --test forces running at a concurrency of 1\. Use the inspectPort option to run with concurrency/); 57 assert.strictEqual(code, 1); 58 assert.strictEqual(signal, null); 59} 60 61 62// Outputs coverage when event loop is drained, with no async logic. 63{ 64 const coverageDirectory = path.join(tmpdir.path, 'coverage'); 65 async function getCoveredFiles() { 66 const coverageFiles = await fs.readdir(coverageDirectory); 67 const files = new Set(); 68 for (const coverageFile of coverageFiles) { 69 const coverage = JSON.parse(await fs.readFile(path.join(coverageDirectory, coverageFile))); 70 for (const { url } of coverage.result) { 71 if (!url.startsWith('node:')) files.add(url); 72 } 73 } 74 return files; 75 } 76 77 const { stderr, code, signal } = await common 78 .spawnPromisified(process.execPath, 79 ['--test', fixtures.path('v8-coverage/basic.js')], 80 { env: { ...process.env, NODE_V8_COVERAGE: coverageDirectory } }); 81 82 assert.strictEqual(stderr, ''); 83 assert.strictEqual(code, 0); 84 assert.strictEqual(signal, null); 85 const files = await getCoveredFiles(coverageDirectory); 86 assert.ok(files.has(fixtures.fileURL('v8-coverage/basic.js').href)); 87} 88