borp 0.20.2 → 1.0.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/.claude/settings.local.json +7 -0
- package/.github/workflows/ci.yml +1 -4
- package/.github/workflows/publish-release.yml +43 -0
- package/README.md +86 -48
- package/borp.js +35 -27
- package/fixtures/conf/cov-html.yaml +2 -0
- package/fixtures/conf/coverage.yaml +7 -0
- package/fixtures/only-src/src/add.test.ts +1 -1
- package/fixtures/only-src/src/add2.test.ts +1 -1
- package/fixtures/ts-esm/test/add.test.ts +1 -1
- package/fixtures/ts-esm/test/add2.test.ts +1 -1
- package/fixtures/ts-esm-check-coverage/test/add.test.ts +1 -1
- package/fixtures/ts-esm2/test/add.test.ts +1 -1
- package/fixtures/ts-esm2/test/add2.test.ts +1 -1
- package/lib/conf.js +18 -0
- package/lib/run.js +18 -214
- package/package.json +5 -2
- package/scripts/sync-version.mjs +20 -0
- package/test/basic.test.js +40 -145
- package/test/cli-help.test.js +2 -0
- package/test/cli.test.js +4 -43
- package/test/config.test.js +28 -0
- package/test/coverage.test.js +25 -0
- package/test/watch.test.js +19 -105
- package/fixtures/monorepo/package-lock.json +0 -35
- package/fixtures/monorepo/package.json +0 -15
- package/fixtures/monorepo/package1/package.json +0 -13
- package/fixtures/monorepo/package1/src/lib/add.ts +0 -3
- package/fixtures/monorepo/package1/src/test/add.test.ts +0 -7
- package/fixtures/monorepo/package1/src/test/add2.test.ts +0 -7
- package/fixtures/monorepo/package1/tsconfig.json +0 -10
- package/fixtures/monorepo/package2/package.json +0 -15
- package/fixtures/monorepo/package2/src/lib/add.ts +0 -4
- package/fixtures/monorepo/package2/src/test/add.test.ts +0 -7
- package/fixtures/monorepo/package2/src/test/add2.test.ts +0 -7
- package/fixtures/monorepo/package2/tsconfig.json +0 -11
- package/fixtures/monorepo/tsconfig.base.json +0 -24
- package/fixtures/monorepo/tsconfig.json +0 -7
- package/fixtures/src-to-dist/src/lib/add.ts +0 -3
- package/fixtures/src-to-dist/src/test/add.test.ts +0 -7
- package/fixtures/src-to-dist/src/test/add2.test.ts +0 -7
- package/fixtures/src-to-dist/tsconfig.json +0 -24
- package/fixtures/ts-cjs/package.json +0 -3
- package/fixtures/ts-cjs/src/add.ts +0 -3
- package/fixtures/ts-cjs/test/add.test.ts +0 -7
- package/fixtures/ts-cjs/test/add2.test.ts +0 -7
- package/fixtures/ts-cjs/tsconfig.json +0 -24
- package/fixtures/ts-cjs-post-compile/package.json +0 -3
- package/fixtures/ts-cjs-post-compile/postCompile.ts +0 -1
- package/fixtures/ts-cjs-post-compile/src/add.ts +0 -3
- package/fixtures/ts-cjs-post-compile/test/add.test.ts +0 -7
- package/fixtures/ts-cjs-post-compile/test/add2.test.ts +0 -7
- package/fixtures/ts-cjs-post-compile/tsconfig.json +0 -24
- package/fixtures/ts-esm-post-compile/postCompile.ts +0 -1
- package/fixtures/ts-esm-post-compile/src/add.ts +0 -3
- package/fixtures/ts-esm-post-compile/test/add.test.ts +0 -7
- package/fixtures/ts-esm-post-compile/test/add2.test.ts +0 -7
- package/fixtures/ts-esm-post-compile/tsconfig.json +0 -24
- package/fixtures/ts-esm-source-map/src/add.ts +0 -3
- package/fixtures/ts-esm-source-map/test/add.test.ts +0 -7
- package/fixtures/ts-esm-source-map/tsconfig.json +0 -24
- package/test/sourceMap.test.js +0 -87
package/.github/workflows/ci.yml
CHANGED
|
@@ -16,11 +16,8 @@ jobs:
|
|
|
16
16
|
|
|
17
17
|
strategy:
|
|
18
18
|
matrix:
|
|
19
|
-
node-version: [
|
|
19
|
+
node-version: [22.x, 24.x, 25.x]
|
|
20
20
|
os: [ubuntu-latest, windows-latest]
|
|
21
|
-
exclude:
|
|
22
|
-
- os: windows-latest
|
|
23
|
-
node-version: 21.x
|
|
24
21
|
steps:
|
|
25
22
|
- uses: actions/checkout@v4
|
|
26
23
|
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
name: Publish release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
inputs:
|
|
6
|
+
version:
|
|
7
|
+
description: 'The version number to tag and release'
|
|
8
|
+
required: true
|
|
9
|
+
type: string
|
|
10
|
+
prerelease:
|
|
11
|
+
description: 'Release as pre-release'
|
|
12
|
+
required: false
|
|
13
|
+
type: boolean
|
|
14
|
+
default: false
|
|
15
|
+
|
|
16
|
+
jobs:
|
|
17
|
+
release-npm:
|
|
18
|
+
runs-on: ubuntu-latest
|
|
19
|
+
environment: main
|
|
20
|
+
permissions:
|
|
21
|
+
contents: write
|
|
22
|
+
id-token: write
|
|
23
|
+
steps:
|
|
24
|
+
- uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
|
|
25
|
+
- uses: actions/setup-node@v4
|
|
26
|
+
with:
|
|
27
|
+
node-version: '22'
|
|
28
|
+
registry-url: 'https://registry.npmjs.org'
|
|
29
|
+
- run: npm install npm -g
|
|
30
|
+
- run: npm install
|
|
31
|
+
- name: Change version number and sync
|
|
32
|
+
run: |
|
|
33
|
+
node scripts/sync-version.mjs ${{ inputs.version }}
|
|
34
|
+
- name: GIT commit and push all changed files
|
|
35
|
+
run: |
|
|
36
|
+
git config --global user.name "mcollina"
|
|
37
|
+
git config --global user.email "hello@matteocollina.com"
|
|
38
|
+
git commit -n -a -m "Bumped v${{ inputs.version }}"
|
|
39
|
+
git push origin HEAD:${{ github.ref }}
|
|
40
|
+
- run: npm publish --access public --tag ${{ inputs.prerelease == true && 'next' || 'latest' }}
|
|
41
|
+
- name: 'Create release notes'
|
|
42
|
+
run: |
|
|
43
|
+
npx @matteo.collina/release-notes -a ${{ secrets.GITHUB_TOKEN }} -t v${{ inputs.version }} -r mcollina -o borp ${{ github.event.inputs.prerelease == 'true' && '-p' || '' }} -c ${{ github.ref }}
|
package/README.md
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
# borp
|
|
2
2
|
|
|
3
|
-
Borp is a
|
|
4
|
-
|
|
3
|
+
Borp is a TypeScript-aware test runner for `node:test` with built-in code coverage support via [c8](https://npm.im/c8).
|
|
4
|
+
|
|
5
|
+
Borp uses Node.js native [type stripping](https://nodejs.org/api/typescript.html) to run TypeScript files directly without compilation. No build step required!
|
|
5
6
|
|
|
6
7
|
Borp is self-hosted, i.e. Borp runs its own tests.
|
|
7
8
|
|
|
9
|
+
## Requirements
|
|
10
|
+
|
|
11
|
+
- Node.js >= 22.6.0 (22.19.0+ or 24.x+ recommended for best TypeScript support)
|
|
12
|
+
|
|
8
13
|
## Install
|
|
9
14
|
|
|
10
15
|
```bash
|
|
@@ -14,40 +19,47 @@ npm i borp --save-dev
|
|
|
14
19
|
## Usage
|
|
15
20
|
|
|
16
21
|
```bash
|
|
22
|
+
# Run all tests
|
|
23
|
+
borp
|
|
24
|
+
|
|
25
|
+
# With code coverage
|
|
17
26
|
borp --coverage
|
|
18
27
|
|
|
19
|
-
#
|
|
28
|
+
# With coverage threshold checking
|
|
20
29
|
borp --coverage --check-coverage --lines 95
|
|
21
30
|
|
|
22
|
-
#
|
|
31
|
+
# With a node_modules located reporter
|
|
23
32
|
borp --reporter foo
|
|
24
33
|
|
|
25
|
-
#
|
|
34
|
+
# With a node_modules located reporter writing to stderr
|
|
26
35
|
borp --reporter foo:stderr
|
|
27
36
|
|
|
28
|
-
#
|
|
37
|
+
# With a local custom reporter
|
|
29
38
|
borp --reporter ./lib/some-reporter.mjs
|
|
30
39
|
|
|
31
|
-
#
|
|
40
|
+
# Matching all test.js files except ones in nested node_modules directories
|
|
32
41
|
borp 'test/**/*.test.js' '!test/**/node_modules/**/*.test.js'
|
|
33
42
|
```
|
|
34
43
|
|
|
35
|
-
Borp will automatically run all
|
|
44
|
+
Borp will automatically run all test files matching `*.test.{js|ts|mts|cts}`.
|
|
45
|
+
|
|
46
|
+
## TypeScript Support
|
|
47
|
+
|
|
48
|
+
Borp uses Node.js native type stripping to run TypeScript files directly. No compilation step is required!
|
|
36
49
|
|
|
37
50
|
### Example project setup
|
|
38
51
|
|
|
39
52
|
```
|
|
40
53
|
.
|
|
41
54
|
├── src
|
|
42
|
-
│
|
|
43
|
-
│
|
|
44
|
-
│
|
|
45
|
-
│
|
|
46
|
-
└──
|
|
47
|
-
|
|
55
|
+
│ ├── lib
|
|
56
|
+
│ │ └── math.ts
|
|
57
|
+
│ └── test
|
|
58
|
+
│ └── math.test.ts
|
|
59
|
+
└── package.json
|
|
48
60
|
```
|
|
49
61
|
|
|
50
|
-
As an example, consider having a `src/lib/math.ts` file
|
|
62
|
+
As an example, consider having a `src/lib/math.ts` file:
|
|
51
63
|
|
|
52
64
|
```typescript
|
|
53
65
|
export function math (x: number, y: number): number {
|
|
@@ -59,7 +71,7 @@ and a `src/test/math.test.ts` file:
|
|
|
59
71
|
|
|
60
72
|
```typescript
|
|
61
73
|
import { test } from 'node:test'
|
|
62
|
-
import { math } from '../lib/math.
|
|
74
|
+
import { math } from '../lib/math.ts'
|
|
63
75
|
import { strictEqual } from 'node:assert'
|
|
64
76
|
|
|
65
77
|
test('math', () => {
|
|
@@ -67,43 +79,51 @@ test('math', () => {
|
|
|
67
79
|
})
|
|
68
80
|
```
|
|
69
81
|
|
|
70
|
-
|
|
82
|
+
Note: Use `.ts` extensions in your imports, not `.js`!
|
|
83
|
+
|
|
84
|
+
### TypeScript Constraints
|
|
85
|
+
|
|
86
|
+
Type stripping has some limitations compared to full TypeScript compilation. Your code must follow these rules:
|
|
87
|
+
|
|
88
|
+
- **Use type-only imports**: Use `import type { Foo }` or `import { type Foo }` for type imports
|
|
89
|
+
- **No enums**: Use const objects with `as const` instead
|
|
90
|
+
- **No namespaces**: Use regular modules instead
|
|
91
|
+
- **No parameter properties**: Explicitly declare class properties in the constructor body
|
|
92
|
+
- **File extensions**: Import `.ts` files with `.ts` extension
|
|
93
|
+
|
|
94
|
+
See the [Node.js TypeScript documentation](https://nodejs.org/api/typescript.html) for full details.
|
|
95
|
+
|
|
96
|
+
### Optional tsconfig.json
|
|
97
|
+
|
|
98
|
+
A `tsconfig.json` is not required for borp to work, but you can include one for IDE support and type checking:
|
|
71
99
|
|
|
72
100
|
```json
|
|
73
101
|
{
|
|
74
|
-
"$schema": "https://json.schemastore.org/tsconfig",
|
|
75
102
|
"compilerOptions": {
|
|
76
|
-
"outDir": "dist",
|
|
77
|
-
"sourceMap": true,
|
|
78
103
|
"target": "ES2022",
|
|
79
104
|
"module": "NodeNext",
|
|
80
105
|
"moduleResolution": "NodeNext",
|
|
81
|
-
"esModuleInterop": true,
|
|
82
106
|
"strict": true,
|
|
83
|
-
"
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"noUnusedLocals": true,
|
|
87
|
-
"noFallthroughCasesInSwitch": true,
|
|
107
|
+
"noEmit": true,
|
|
108
|
+
"allowImportingTsExtensions": true,
|
|
109
|
+
"verbatimModuleSyntax": true,
|
|
88
110
|
"isolatedModules": true,
|
|
89
|
-
"
|
|
90
|
-
"skipLibCheck": true,
|
|
91
|
-
"lib": [
|
|
92
|
-
"ESNext"
|
|
93
|
-
],
|
|
94
|
-
"incremental": true
|
|
111
|
+
"skipLibCheck": true
|
|
95
112
|
}
|
|
96
113
|
}
|
|
97
114
|
```
|
|
98
115
|
|
|
99
|
-
|
|
116
|
+
Key options:
|
|
117
|
+
- `noEmit: true` - No compilation output needed
|
|
118
|
+
- `allowImportingTsExtensions: true` - Allow `.ts` imports
|
|
119
|
+
- `verbatimModuleSyntax: true` - Enforce type-only imports
|
|
100
120
|
|
|
101
121
|
## Options
|
|
102
122
|
|
|
103
123
|
* `--concurrency` or `-c`, to set the number of concurrent tests. Defaults to the number of available CPUs minus one.
|
|
104
124
|
* `--coverage` or `-C`, enables code coverage
|
|
105
|
-
* `--only` or `-o`, only run `node:test` with the `only` option set
|
|
106
|
-
* `--watch` or `-w`, re-run tests on changes
|
|
125
|
+
* `--only` or `-o`, only run `node:test` with the `only` option set
|
|
126
|
+
* `--watch` or `-w`, re-run tests on file changes using Node.js native watch mode
|
|
107
127
|
* `--timeout` or `-t`, timeouts the tests after a given time; default is 30000 ms
|
|
108
128
|
* `--no-timeout`, disables the timeout
|
|
109
129
|
* `--coverage-exclude` or `-X`, a list of comma-separated patterns to exclude from the coverage report. All tests files are ignored by default.
|
|
@@ -111,14 +131,16 @@ Note the use of `incremental: true`, which speed up compilation massively.
|
|
|
111
131
|
* `--expose-gc`, exposes the gc() function to tests
|
|
112
132
|
* `--pattern` or `-p`, run tests matching the given glob pattern
|
|
113
133
|
* `--reporter` or `-r`, set up a reporter, use a colon to set a file destination. Reporter may either be a module name resolvable by standard `node_modules` resolution, or a path to a script relative to the process working directory (must be an ESM script). Default: `spec`.
|
|
114
|
-
* `--no-typescript` or `-T`, disable automatic TypeScript compilation if `tsconfig.json` is found.
|
|
115
|
-
* `--post-compile` or `-P`, the path to a file that will be executed after each typescript compilation.
|
|
116
134
|
* `--check-coverage`, enables c8 check coverage; default is false
|
|
135
|
+
* `--coverage-html`, generates c8 html report; default is false
|
|
136
|
+
|
|
117
137
|
### Check coverage options
|
|
138
|
+
|
|
118
139
|
* `--lines`, set the lines threshold when check coverage is active; default is 100
|
|
119
140
|
* `--functions`, set the functions threshold when check coverage is active; default is 100
|
|
120
141
|
* `--statements`, set the statements threshold when check coverage is active; default is 100
|
|
121
142
|
* `--branches`, set the branches threshold when check coverage is active; default is 100
|
|
143
|
+
|
|
122
144
|
## Reporters
|
|
123
145
|
|
|
124
146
|
Here are the available reporters:
|
|
@@ -131,24 +153,30 @@ Here are the available reporters:
|
|
|
131
153
|
|
|
132
154
|
## Config File Support
|
|
133
155
|
|
|
134
|
-
A limited set of options may be specified via a configuration file. The
|
|
135
|
-
configuration file is expected to be in the process's working directory, and
|
|
136
|
-
named either `.borp.yaml` or `.borp.yml`; it may also be specified by
|
|
137
|
-
defining the environment variable `BORP_CONF_FILE` and setting it to the
|
|
138
|
-
full path to some yaml file.
|
|
156
|
+
A limited set of options may be specified via a configuration file. The configuration file is expected to be in the process's working directory, and named either `.borp.yaml` or `.borp.yml`; it may also be specified by defining the environment variable `BORP_CONF_FILE` and setting it to the full path to some yaml file.
|
|
139
157
|
|
|
140
158
|
The current supported options are:
|
|
141
159
|
|
|
142
|
-
+ `
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
160
|
+
+ `coverage` (object): A hash of options relating to test coverage. By defining this configuration object, coverage reporting will be enabled.
|
|
161
|
+
- `check-coverage` (boolean): Set to `true` to enable coverage checking. Omit to disable coverage checking.
|
|
162
|
+
- `coverage-html` (boolean): Set to `true` to generate an HTML coverage report.
|
|
163
|
+
- `branches` (number): Define the percentage of acceptable coverage for branches. Default: 100.
|
|
164
|
+
- `functions` (number): Define the percentage of acceptable coverage for functions. Default: 100.
|
|
165
|
+
- `lines` (number): Define the percentage of acceptable coverage for lines. Default: 100.
|
|
166
|
+
- `statements` (number): Define the percentage of acceptable coverage for statements. Default: 100.
|
|
167
|
+
+ `files` (string[]): An array of test files to include. Globs are supported. Note: any glob that starts with a `!` (bang character) will be treated as an ignore glob, e.g. `'!test/**/node_modules/**/*'` will ignore all files in nested `node_modules` directories that would otherwise be matched.
|
|
168
|
+
+ `reporters` (string[]): An array of reporters to use. May be relative path strings, or module name strings.
|
|
148
169
|
|
|
149
170
|
### Example
|
|
150
171
|
|
|
151
172
|
```yaml
|
|
173
|
+
coverage:
|
|
174
|
+
check-coverage: true
|
|
175
|
+
branches: 99
|
|
176
|
+
functions: 98
|
|
177
|
+
lines: 97
|
|
178
|
+
statements: 96
|
|
179
|
+
|
|
152
180
|
files:
|
|
153
181
|
- 'test/one.test.js'
|
|
154
182
|
- 'test/foo/*.test.js'
|
|
@@ -159,6 +187,16 @@ reporters:
|
|
|
159
187
|
- '@reporters/silent'
|
|
160
188
|
```
|
|
161
189
|
|
|
190
|
+
## Migration from borp < 1.0
|
|
191
|
+
|
|
192
|
+
If you're upgrading from an older version of borp, here are the key changes:
|
|
193
|
+
|
|
194
|
+
1. **No compilation step**: Tests run directly from source files
|
|
195
|
+
2. **Import extensions**: Change `.js` to `.ts` in your TypeScript imports
|
|
196
|
+
3. **No outDir**: Remove `outDir` from tsconfig or set to your source directory
|
|
197
|
+
4. **Removed options**: `--no-typescript` and `--post-compile` are removed
|
|
198
|
+
5. **Type constraints**: See TypeScript Constraints section above
|
|
199
|
+
|
|
162
200
|
## License
|
|
163
201
|
|
|
164
202
|
MIT
|
package/borp.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import { parseArgs } from 'node:util'
|
|
4
|
+
import runTests from './lib/run.js'
|
|
4
5
|
import Reporters from 'node:test/reporters'
|
|
5
6
|
import { findUp } from 'find-up'
|
|
6
7
|
import { mkdtemp, rm, readFile } from 'node:fs/promises'
|
|
7
8
|
import { createWriteStream } from 'node:fs'
|
|
8
9
|
import { finished } from 'node:stream/promises'
|
|
9
|
-
import { join,
|
|
10
|
-
import posix from 'node:path/posix'
|
|
11
|
-
import runWithTypeScript from './lib/run.js'
|
|
10
|
+
import { join, resolve } from 'node:path'
|
|
12
11
|
import githubReporter from '@reporters/github'
|
|
13
12
|
import { Report } from 'c8'
|
|
14
13
|
import { checkCoverages } from 'c8/lib/commands/check-coverage.js'
|
|
@@ -17,6 +16,10 @@ import { execa } from 'execa'
|
|
|
17
16
|
import { pathToFileURL } from 'node:url'
|
|
18
17
|
import loadConfig from './lib/conf.js'
|
|
19
18
|
|
|
19
|
+
// This is a hack to override
|
|
20
|
+
// https://github.com/nodejs/node/commit/d5c9adf3df
|
|
21
|
+
delete process.env.NODE_TEST_CONTEXT
|
|
22
|
+
|
|
20
23
|
/* c8 ignore next 4 */
|
|
21
24
|
process.on('unhandledRejection', (err) => {
|
|
22
25
|
console.error(err)
|
|
@@ -38,10 +41,9 @@ Options:
|
|
|
38
41
|
-X, --coverage-exclude Exclude patterns from coverage (can be used multiple times)
|
|
39
42
|
-i, --ignore <pattern> Ignore glob pattern (can be used multiple times)
|
|
40
43
|
--expose-gc Expose the gc() function to tests
|
|
41
|
-
-T, --no-typescript Disable automatic TypeScript compilation
|
|
42
|
-
-P, --post-compile <file> Execute file after TypeScript compilation
|
|
43
44
|
-r, --reporter <name> Set reporter (can be used multiple times, default: spec)
|
|
44
45
|
--check-coverage Enable coverage threshold checking
|
|
46
|
+
--coverage-html Generate HTML coverage report
|
|
45
47
|
--lines <threshold> Set lines coverage threshold (default: 100)
|
|
46
48
|
--branches <threshold> Set branches coverage threshold (default: 100)
|
|
47
49
|
--functions <threshold> Set functions coverage threshold (default: 100)
|
|
@@ -58,6 +60,7 @@ Examples:
|
|
|
58
60
|
const foundConfig = await loadConfig()
|
|
59
61
|
if (foundConfig.length > 0) {
|
|
60
62
|
Array.prototype.push.apply(process.argv, foundConfig)
|
|
63
|
+
process.stderr.write(`parsed config: ${foundConfig.join(' ')}\n`)
|
|
61
64
|
}
|
|
62
65
|
|
|
63
66
|
const optionsConfig = {
|
|
@@ -72,8 +75,6 @@ const optionsConfig = {
|
|
|
72
75
|
ignore: { type: 'string', short: 'i', multiple: true },
|
|
73
76
|
'expose-gc': { type: 'boolean' },
|
|
74
77
|
help: { type: 'boolean', short: 'h' },
|
|
75
|
-
'no-typescript': { type: 'boolean', short: 'T' },
|
|
76
|
-
'post-compile': { type: 'string', short: 'P' },
|
|
77
78
|
reporter: {
|
|
78
79
|
type: 'string',
|
|
79
80
|
short: 'r',
|
|
@@ -81,6 +82,7 @@ const optionsConfig = {
|
|
|
81
82
|
multiple: true
|
|
82
83
|
},
|
|
83
84
|
'check-coverage': { type: 'boolean' },
|
|
85
|
+
'coverage-html': { type: 'boolean' },
|
|
84
86
|
lines: { type: 'string', default: '100' },
|
|
85
87
|
branches: { type: 'string', default: '100' },
|
|
86
88
|
functions: { type: 'string', default: '100' },
|
|
@@ -115,16 +117,16 @@ if (args.values.help) {
|
|
|
115
117
|
|
|
116
118
|
/* c8 ignore next 20 */
|
|
117
119
|
if (args.values['expose-gc'] && typeof global.gc !== 'function') {
|
|
118
|
-
const
|
|
120
|
+
const spawnArgs = [...process.argv.slice(1)]
|
|
119
121
|
const nodeVersion = process.version.split('.').map((v) => parseInt(v.replace('v', '')))[0]
|
|
120
122
|
if (nodeVersion >= 24) {
|
|
121
123
|
process.env.NODE_OPTIONS = (process.env.NODE_OPTIONS ? process.env.NODE_OPTIONS + ' ' : '') + '--expose-gc'
|
|
122
124
|
} else {
|
|
123
|
-
|
|
125
|
+
spawnArgs.unshift('--expose-gc')
|
|
124
126
|
}
|
|
125
127
|
|
|
126
128
|
try {
|
|
127
|
-
await execa('node',
|
|
129
|
+
await execa('node', spawnArgs, {
|
|
128
130
|
stdio: 'inherit',
|
|
129
131
|
env: {
|
|
130
132
|
...process.env
|
|
@@ -154,14 +156,6 @@ if (args.values.coverage) {
|
|
|
154
156
|
process.env.NODE_V8_COVERAGE = covDir
|
|
155
157
|
}
|
|
156
158
|
|
|
157
|
-
const config = {
|
|
158
|
-
...args.values,
|
|
159
|
-
typescript: !args.values['no-typescript'],
|
|
160
|
-
files: args.positionals,
|
|
161
|
-
pattern: args.values.pattern,
|
|
162
|
-
cwd: process.cwd()
|
|
163
|
-
}
|
|
164
|
-
|
|
165
159
|
try {
|
|
166
160
|
const pipes = []
|
|
167
161
|
|
|
@@ -204,7 +198,14 @@ try {
|
|
|
204
198
|
pipes.push([reporter, output])
|
|
205
199
|
}
|
|
206
200
|
|
|
207
|
-
const
|
|
201
|
+
const config = {
|
|
202
|
+
...args.values,
|
|
203
|
+
files: args.positionals,
|
|
204
|
+
pattern: args.values.pattern,
|
|
205
|
+
cwd: process.cwd()
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const stream = await runTests(config)
|
|
208
209
|
|
|
209
210
|
stream.on('test:fail', () => {
|
|
210
211
|
process.exitCode = 1
|
|
@@ -217,18 +218,25 @@ try {
|
|
|
217
218
|
await finished(stream)
|
|
218
219
|
|
|
219
220
|
if (covDir) {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
if (exclude && config.prefix) {
|
|
223
|
-
const localPrefix = relative(process.cwd(), config.prefix)
|
|
224
|
-
exclude = exclude.map((file) => posix.join(localPrefix, file))
|
|
225
|
-
}
|
|
221
|
+
const exclude = args.values['coverage-exclude']
|
|
226
222
|
const nycrc = await findUp(['.c8rc', '.c8rc.json', '.nycrc', '.nycrc.json'], { cwd: config.cwd })
|
|
223
|
+
const nycrcConfig = nycrc ? JSON.parse(await readFile(nycrc, 'utf8')) : {}
|
|
224
|
+
const configuredReporters = Array.isArray(nycrcConfig.reporter)
|
|
225
|
+
? nycrcConfig.reporter
|
|
226
|
+
: typeof nycrcConfig.reporter === 'string' && nycrcConfig.reporter.length > 0
|
|
227
|
+
? [nycrcConfig.reporter]
|
|
228
|
+
: ['text']
|
|
229
|
+
|
|
230
|
+
const coverageReporters = args.values['coverage-html']
|
|
231
|
+
? Array.from(new Set([...configuredReporters, 'html']))
|
|
232
|
+
: configuredReporters
|
|
233
|
+
|
|
234
|
+
delete nycrcConfig.reporter
|
|
227
235
|
const report = Report({
|
|
228
|
-
reporter:
|
|
236
|
+
reporter: coverageReporters,
|
|
229
237
|
tempDirectory: covDir,
|
|
230
238
|
exclude,
|
|
231
|
-
...
|
|
239
|
+
...nycrcConfig
|
|
232
240
|
})
|
|
233
241
|
|
|
234
242
|
if (args.values['check-coverage']) {
|
package/lib/conf.js
CHANGED
|
@@ -59,6 +59,24 @@ async function loadConfig () {
|
|
|
59
59
|
return result
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
if (options.coverage) {
|
|
63
|
+
result.push('--coverage')
|
|
64
|
+
const allowed = ['branches', 'functions', 'lines', 'statements']
|
|
65
|
+
for (const [option, value] of Object.entries(options.coverage)) {
|
|
66
|
+
if (option === 'check-coverage' && value === true) {
|
|
67
|
+
result.push('--check-coverage')
|
|
68
|
+
continue
|
|
69
|
+
}
|
|
70
|
+
if (option === 'coverage-html' && value === true) {
|
|
71
|
+
result.push('--coverage-html')
|
|
72
|
+
continue
|
|
73
|
+
}
|
|
74
|
+
if (allowed.includes(option) === false) continue
|
|
75
|
+
if (isNaN(parseInt(value, 10)) === true) continue
|
|
76
|
+
result.push(`--${option}=${value}`)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
62
80
|
if (options.reporters) {
|
|
63
81
|
for (const reporter of options.reporters) {
|
|
64
82
|
result.push('--reporter')
|