Skip to content

Commit fa59a8d

Browse files
committed
doc: clarify filtered test behavior
- fix outdated `npm run unit` examples - explain that `--filter` affects test execution, not compilation scope - note that `npm test --filter=...` still triggers the default full rebuild
1 parent f65113b commit fa59a8d

File tree

2 files changed

+35
-16
lines changed

2 files changed

+35
-16
lines changed

CONTRIBUTING.md

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,27 +70,37 @@ npm test --NAPI_VERSION=X
7070

7171
where X is the version of Node-API you want to target.
7272

73-
To run a specific unit test, filter conditions are available
73+
To run a subset of the test suite, filter conditions are available.
74+
The `--filter` option limits which JavaScript test modules are executed by
75+
`node test`. The default `pretest` step is still `node-gyp rebuild -C test`,
76+
so `npm test --filter=...` still performs a full rebuild of the test addon
77+
targets before the filtered tests run.
7478

7579
**Example:**
76-
compile and run only tests on objectwrap.cc and objectwrap.js
80+
perform the default test rebuild, then run only the `objectwrap` test module
7781
```
78-
npm run unit --filter=objectwrap
82+
npm test --filter=objectwrap
7983
```
8084

81-
Multiple unit tests cane be selected with wildcards
85+
Multiple test modules can be selected with wildcards.
8286

8387
**Example:**
84-
compile and run all test files ending with "reference" -> function_reference.cc, object_reference.cc, reference.cc
88+
perform the default test rebuild, then run all test modules ending with
89+
`reference`:
90+
`function_reference`, `object_reference`, and `reference`
8591
```
86-
npm run unit --filter=*reference
92+
npm test --filter=*reference
8793
```
8894

89-
Multiple filter conditions can be joined to broaden the test selection
95+
Multiple filter conditions can be joined to broaden the test selection.
9096

9197
**Example:**
92-
compile and run all tests under folders threadsafe_function and typed_threadsafe_function and also the objectwrap.cc file
93-
npm run unit --filter='*function objectwrap'
98+
perform the default test rebuild, then run all tests under
99+
`threadsafe_function` and `typed_threadsafe_function`, and also the
100+
`objectwrap` test module
101+
```
102+
npm test --filter='*function objectwrap'
103+
```
94104

95105
As an alternative, `ninja` can be used to build the tests. Please
96106
follow the instructions in [Build with ninja](doc/contributing/build_with_ninja.md).
@@ -203,4 +213,3 @@ The downside of this approach is the following:
203213
authors might not find the right patterns and instead implement things themselves
204214
- There might be greater friction for the Node-API WG in evolving APIs since the
205215
ecosystem would have taken dependencies on the API shape of **node-addon-api**
206-

unit-test/README.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,38 @@
11

22
# Enable running tests with specific filter conditions:
33

4+
The `--filter` option limits which test modules are executed by `node test`.
5+
The default `pretest` step is still `node-gyp rebuild -C test`, so
6+
`npm test --filter=...` still performs a full rebuild of the test addon
7+
targets before the filtered tests run.
8+
49
### Example:
510

6-
- compile and run only tests on objectwrap.cc and objectwrap.js
11+
- perform the default test rebuild, then run only the `objectwrap`
12+
test module
713
```
8-
npm run test --filter=objectwrap
14+
npm test --filter=objectwrap
915
```
1016

1117

1218
# Wildcards are also possible:
1319

1420
### Example:
1521

16-
- compile and run all tests files ending with reference -> function_reference.cc object_reference.cc reference.cc
22+
- perform the default test rebuild, then run all test modules ending
23+
with `reference`
24+
(`function_reference`, `object_reference`, and `reference`)
1725
```
18-
npm run test --filter=*reference
26+
npm test --filter=*reference
1927
```
2028

2129
# Multiple filter conditions are also allowed
2230

2331
### Example:
2432

25-
- compile and run all tests under folders threadsafe_function and typed_threadsafe_function and also the objectwrap.cc file
33+
- perform the default test rebuild, then run all tests under
34+
`threadsafe_function` and `typed_threadsafe_function`, and also the
35+
`objectwrap` test module
2636
```
27-
npm run test --filter='*function objectwrap'
37+
npm test --filter='*function objectwrap'
2838
```

0 commit comments

Comments
 (0)