borp 0.4.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/borp.js +17 -1
- package/fixtures/gc/gc.test.js +8 -0
- package/lib/run.js +5 -0
- package/package.json +1 -1
- package/test/cli.test.js +19 -0
package/README.md
CHANGED
|
@@ -91,6 +91,7 @@ Note the use of `incremental: true`, which speed up compilation massively.
|
|
|
91
91
|
* `--timeout` or `-t`, timeouts the tests after a given time; default is 30000 ms
|
|
92
92
|
* `--coverage-exclude` or `-X`, a list of comma-separated patterns to exclude from the coverage report. All tests files are ignored by default.
|
|
93
93
|
* `--ignore` or `-i`, ignore a glob pattern, and not look for tests there
|
|
94
|
+
* `--expose-gc`, exposes the gc() function to tests
|
|
94
95
|
* `--pattern` or `-p`, run tests matching the given glob pattern
|
|
95
96
|
|
|
96
97
|
## License
|
package/borp.js
CHANGED
|
@@ -9,6 +9,7 @@ import posix from 'node:path/posix'
|
|
|
9
9
|
import runWithTypeScript from './lib/run.js'
|
|
10
10
|
import { Report } from 'c8'
|
|
11
11
|
import os from 'node:os'
|
|
12
|
+
import { execa } from 'execa'
|
|
12
13
|
|
|
13
14
|
let reporter
|
|
14
15
|
/* c8 ignore next 4 */
|
|
@@ -30,17 +31,32 @@ const args = parseArgs({
|
|
|
30
31
|
timeout: { type: 'string', short: 't', default: '30000' },
|
|
31
32
|
'coverage-exclude': { type: 'string', short: 'X', multiple: true },
|
|
32
33
|
ignore: { type: 'string', short: 'i', multiple: true },
|
|
34
|
+
'expose-gc': { type: 'boolean' },
|
|
33
35
|
help: { type: 'boolean', short: 'h' }
|
|
34
36
|
},
|
|
35
37
|
allowPositionals: true
|
|
36
38
|
})
|
|
37
39
|
|
|
38
|
-
/* c8 ignore next
|
|
40
|
+
/* c8 ignore next 5 */
|
|
39
41
|
if (args.values.help) {
|
|
40
42
|
console.log(await readFile(new URL('./README.md', import.meta.url), 'utf8'))
|
|
41
43
|
process.exit(0)
|
|
42
44
|
}
|
|
43
45
|
|
|
46
|
+
if (args.values['expose-gc'] && typeof global.gc !== 'function') {
|
|
47
|
+
try {
|
|
48
|
+
await execa('node', ['--expose-gc', ...process.argv.slice(1)], {
|
|
49
|
+
stdio: 'inherit',
|
|
50
|
+
env: {
|
|
51
|
+
...process.env
|
|
52
|
+
}
|
|
53
|
+
})
|
|
54
|
+
process.exit(0)
|
|
55
|
+
} catch (error) {
|
|
56
|
+
process.exit(1)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
44
60
|
if (args.values.concurrency) {
|
|
45
61
|
args.values.concurrency = parseInt(args.values.concurrency)
|
|
46
62
|
}
|
package/lib/run.js
CHANGED
|
@@ -17,6 +17,10 @@ function deferred () {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export default async function runWithTypeScript (config) {
|
|
20
|
+
// This is a hack to override
|
|
21
|
+
// https://github.com/nodejs/node/commit/d5c9adf3df
|
|
22
|
+
delete process.env.NODE_TEST_CONTEXT
|
|
23
|
+
|
|
20
24
|
const { cwd } = config
|
|
21
25
|
let pushable = []
|
|
22
26
|
const tsconfigPath = await findUp('tsconfig.json', { cwd })
|
|
@@ -36,6 +40,7 @@ export default async function runWithTypeScript (config) {
|
|
|
36
40
|
if (!config.watch) {
|
|
37
41
|
const start = Date.now()
|
|
38
42
|
await execa('node', [tscPath], { cwd: dirname(tsconfigPath) })
|
|
43
|
+
process.stdout.write(`TypeScript compilation complete (${Date.now() - start}ms)\n`)
|
|
39
44
|
pushable.push({
|
|
40
45
|
type: 'test:diagnostic',
|
|
41
46
|
data: {
|
package/package.json
CHANGED
package/test/cli.test.js
CHANGED
|
@@ -23,3 +23,22 @@ test('failing test set correct status code', async () => {
|
|
|
23
23
|
cwd: join(import.meta.url, '..', 'fixtures', 'fails')
|
|
24
24
|
}))
|
|
25
25
|
})
|
|
26
|
+
|
|
27
|
+
test('--expose-gc flag enables garbage collection in tests', async () => {
|
|
28
|
+
await execa('node', [
|
|
29
|
+
borp,
|
|
30
|
+
'--expose-gc'
|
|
31
|
+
], {
|
|
32
|
+
cwd: join(import.meta.url, '..', 'fixtures', 'gc')
|
|
33
|
+
})
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
test('failing test with --expose-gc flag sets correct status code', async () => {
|
|
37
|
+
// execa rejects if status code is not 0
|
|
38
|
+
await rejects(execa('node', [
|
|
39
|
+
borp,
|
|
40
|
+
'--expose-gc'
|
|
41
|
+
], {
|
|
42
|
+
cwd: join(import.meta.url, '..', 'fixtures', 'fails')
|
|
43
|
+
}))
|
|
44
|
+
})
|