2022-09-10 20:01:42 +03:00
import * as common from '../common/index.mjs' ;
import * as fixtures from '../common/fixtures.mjs' ;
2023-08-11 08:07:30 +09:00
import tmpdir from '../common/tmpdir.js' ;
2022-09-10 20:01:42 +03:00
import assert from 'node:assert' ;
2022-10-20 21:21:20 +03:00
import path from 'node:path' ;
import fs from 'node:fs/promises' ;
2022-09-10 20:01:42 +03:00
import { NodeInstance } from '../common/inspector-helper.js' ;
common . skipIfInspectorDisabled ( ) ;
tmpdir . refresh ( ) ;
{
2023-07-26 20:16:31 +03:00
const child = new NodeInstance (
2024-08-26 20:54:22 -04:00
[ '--test' , '--test-reporter=tap' , '--inspect-brk=0' ] ,
2023-07-26 20:16:31 +03:00
undefined ,
fixtures . path ( 'test-runner/default-behavior/index.test.js' )
) ;
2022-09-10 20:01:42 +03:00
let stdout = '' ;
let stderr = '' ;
child . on ( 'stdout' , ( line ) => stdout += line ) ;
child . on ( 'stderr' , ( line ) => stderr += line ) ;
const session = await child . connectInspectorSession ( ) ;
2024-02-23 14:46:29 -08:00
await session . send ( { method : 'NodeRuntime.enable' } ) ;
await session . waitForNotification ( 'NodeRuntime.waitingForDebugger' ) ;
2022-09-10 20:01:42 +03:00
await session . send ( [
{ method : 'Runtime.enable' } ,
{ method : 'Runtime.runIfWaitingForDebugger' } ] ) ;
2024-02-23 14:46:29 -08:00
await session . send ( { method : 'NodeRuntime.disable' } ) ;
2022-09-10 20:01:42 +03:00
session . disconnect ( ) ;
assert . match ( stderr ,
/Warning: Using the inspector with --test forces running at a concurrency of 1\. Use the inspectPort option to run with concurrency/ ) ;
}
{
2024-08-26 20:54:22 -04:00
const args = [
'--test' , '--test-reporter=tap' , '--inspect=0' ,
fixtures . path ( 'test-runner/index.js' ) ,
] ;
2022-09-10 20:01:42 +03:00
const { stderr , stdout , code , signal } = await common . spawnPromisified ( process . execPath , args ) ;
assert . match ( stderr ,
/Warning: Using the inspector with --test forces running at a concurrency of 1\. Use the inspectPort option to run with concurrency/ ) ;
assert . match ( stdout , /not ok 1 - .+index\.js/ ) ;
assert . strictEqual ( code , 1 ) ;
assert . strictEqual ( signal , null ) ;
}
{
// File not found.
const args = [ '--test' , '--inspect=0' , 'a-random-file-that-does-not-exist.js' ] ;
const { stderr , stdout , code , signal } = await common . spawnPromisified ( process . execPath , args ) ;
assert . strictEqual ( stdout , '' ) ;
assert . match ( stderr , /^Could not find/ ) ;
assert . doesNotMatch ( stderr , /Warning: Using the inspector with --test forces running at a concurrency of 1\. Use the inspectPort option to run with concurrency/ ) ;
assert . strictEqual ( code , 1 ) ;
assert . strictEqual ( signal , null ) ;
}
2022-10-20 21:21:20 +03:00
// Outputs coverage when event loop is drained, with no async logic.
{
2023-08-15 22:45:44 +09:00
const coverageDirectory = tmpdir . resolve ( 'coverage' ) ;
2022-10-20 21:21:20 +03:00
async function getCoveredFiles ( ) {
const coverageFiles = await fs . readdir ( coverageDirectory ) ;
const files = new Set ( ) ;
for ( const coverageFile of coverageFiles ) {
const coverage = JSON . parse ( await fs . readFile ( path . join ( coverageDirectory , coverageFile ) ) ) ;
for ( const { url } of coverage . result ) {
if ( ! url . startsWith ( 'node:' ) ) files . add ( url ) ;
}
}
return files ;
}
const { stderr , code , signal } = await common
. spawnPromisified ( process . execPath ,
[ '--test' , fixtures . path ( 'v8-coverage/basic.js' ) ] ,
{ env : { ... process . env , NODE _V8 _COVERAGE : coverageDirectory } } ) ;
assert . strictEqual ( stderr , '' ) ;
assert . strictEqual ( code , 0 ) ;
assert . strictEqual ( signal , null ) ;
const files = await getCoveredFiles ( coverageDirectory ) ;
assert . ok ( files . has ( fixtures . fileURL ( 'v8-coverage/basic.js' ) . href ) ) ;
}