Skip to content

Commit fbaeb6e

Browse files
committed
fix: missing file
1 parent 54d6a54 commit fbaeb6e

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

scripts/test.mjs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
'use strict'
2+
3+
// As node 20 test runner does not support glob patterns in input
4+
// and considering that we could have multiple OS we manually
5+
// resolve the test files and pass them to the test runner
6+
7+
import { spawnSync } from 'node:child_process'
8+
import { parseArgs } from 'node:util'
9+
import { globSync } from 'glob'
10+
11+
const options = {
12+
pattern: {
13+
type: 'string',
14+
short: 'p',
15+
description: 'Glob pattern to match test files',
16+
default: 'test/**/*test.js'
17+
},
18+
coverage: {
19+
type: 'boolean',
20+
short: 'c',
21+
description: 'Run tests with coverage',
22+
default: false
23+
},
24+
only: {
25+
type: 'boolean',
26+
short: 'o',
27+
description: 'Run only tests marked with { only: true }',
28+
default: false
29+
}
30+
}
31+
32+
const { values } = parseArgs({ args: process.argv.slice(2), options })
33+
34+
const pattern = values.pattern
35+
const isCoverage = values.coverage
36+
const runOnly = values.only
37+
38+
const testFiles = globSync(pattern, { absolute: true })
39+
40+
const args = [runOnly ? '--test-only' : '--test', ...testFiles]
41+
42+
let result
43+
44+
// we skip coverage for node 20
45+
// because this issuse happen https://github.com/nodejs/node/pull/53315
46+
if (isCoverage && !process.version.startsWith('v20.')) {
47+
result = spawnSync(
48+
'node',
49+
[
50+
'--experimental-test-coverage',
51+
'--test-reporter=lcov',
52+
'--test-reporter-destination=lcov.info',
53+
'--test-reporter=spec',
54+
'--test-reporter-destination=stdout',
55+
...args
56+
],
57+
{ stdio: 'inherit' }
58+
)
59+
} else {
60+
result = spawnSync('node', args, { stdio: 'inherit' })
61+
}
62+
63+
process.exit(result.status)

0 commit comments

Comments
 (0)