@@ -298,20 +298,20 @@ describe.only('a suite', () => {
298
298
299
299
## Filtering tests by name
300
300
301
- The [ ` --test-name-pattern ` ] [ ] command-line option can be used to only run tests
302
- whose name matches the provided pattern. Test name patterns are interpreted as
303
- JavaScript regular expressions. The ` --test-name-pattern ` option can be
304
- specified multiple times in order to run nested tests. For each test that is
305
- executed, any corresponding test hooks, such as ` beforeEach() ` , are also
306
- run. Tests that are not executed are omitted from the test runner output.
307
-
308
- Given the following test file, starting Node.js with the
309
- ` --test-name-pattern="test [1-3]" ` option would cause the test runner to execute
310
- ` test 1 ` , ` test 2 ` , and ` test 3 ` . If ` test 1 ` did not match the test name
311
- pattern, then its subtests would not execute, despite matching the pattern. The
312
- same set of tests could also be executed by passing ` -- test-name-pattern `
313
- multiple times (e.g. ` --test-name-pattern="test 1" ` ,
314
- ` --test-name-pattern="test 2" ` , etc.).
301
+ The [ ` --test-name-pattern ` ] [ ] and [ ` --test-skip-pattern ` ] [ ] command-line
302
+ options provide flexibility in selecting which tests to run and which to
303
+ skip based on their names.
304
+
305
+ ### Using ` -- test-name-pattern `
306
+
307
+ The ` --test-name-pattern ` option filters tests based on their names by
308
+ matching them against the provided pattern, which is interpreted as a
309
+ JavaScript regular expression. This option can be specified multiple times
310
+ to include nested tests. When a test matches the pattern and is executed,
311
+ any corresponding test hooks, such as ` beforeEach() ` , are also run. Tests
312
+ that do not match the pattern are omitted from the test runner output.
313
+
314
+ Consider the following test file:
315
315
316
316
``` js
317
317
test (' test 1' , async (t ) => {
@@ -325,14 +325,19 @@ test('Test 4', async (t) => {
325
325
});
326
326
```
327
327
328
- Test name patterns can also be specified using regular expression literals. This
329
- allows regular expression flags to be used. In the previous example, starting
330
- Node.js with ` --test-name-pattern="/test [4-5]/i" ` would match ` Test 4 ` and
331
- ` Test 5 ` because the pattern is case-insensitive.
328
+ Using Node.js with the ` --test-name-pattern="test [1-3]" ` option would
329
+ execute ` test 1 ` , ` test 2 ` , and ` test 3 ` . If ` test 1 ` did not match the
330
+ pattern, its subtests would not execute, even if they match the pattern.
331
+ Alternatively, specifying the pattern multiple times (e.g.,
332
+ ` --test-name-pattern="test 1" ` , ` --test-name-pattern="test 2" ` , etc.)
333
+ achieves the same result.
334
+
335
+ Regular expression literals can also be used, allowing regular expression flags.
336
+ For instance, using ` --test-name-pattern="/test [4-5]/i" ` would match ` Test 4 `
337
+ and ` Test 5 ` due to the case-insensitive flag.
332
338
333
- To match a single test with a pattern, you can prefix it with all its ancestor
334
- test names separated by space, to ensure it is unique.
335
- For example, given the following test file:
339
+ To match a single test uniquely, prefix its name with all its ancestor test
340
+ names separated by spaces. For example:
336
341
337
342
``` js
338
343
describe (' test 1' , (t ) => {
@@ -344,10 +349,20 @@ describe('test 2', (t) => {
344
349
});
345
350
```
346
351
347
- Starting Node.js with ` --test-name-pattern="test 1 some test" ` would match
348
- only ` some test ` in ` test 1 ` .
352
+ Using ` --test-name-pattern="test 1 some test" ` would match only ` some test ` in ` test 1 ` .
353
+
354
+ ### Using ` --test-skip-pattern `
355
+
356
+ Similarly, the ` --test-skip-pattern ` option allows skipping tests based on their
357
+ names by matching them against the provided pattern, interpreted as JavaScript
358
+ regular expressions. If a test's name matches the skip pattern, it will be
359
+ excluded from execution.
360
+
361
+ If both ` --test-name-pattern ` and ` --test-skip-pattern ` are
362
+ supplied, ` --test-name-pattern ` will take precedence.
349
363
350
- Test name patterns do not change the set of files that the test runner executes.
364
+ Test name patterns and skip patterns do not alter the set of files executed by
365
+ the test runner.
351
366
352
367
## Extraneous asynchronous activity
353
368
@@ -3157,6 +3172,7 @@ Can be used to abort test subtasks when the test has been aborted.
3157
3172
[ `--test-only` ] : cli.md#--test-only
3158
3173
[ `--test-reporter-destination` ] : cli.md#--test-reporter-destination
3159
3174
[ `--test-reporter` ] : cli.md#--test-reporter
3175
+ [ `--test-skip-pattern` ] : cli.md#--test-name-pattern
3160
3176
[ `--test` ] : cli.md#--test
3161
3177
[ `MockFunctionContext` ] : #class-mockfunctioncontext
3162
3178
[ `MockTimers` ] : #class-mocktimers
0 commit comments