Skip to content

Commit 3212dee

Browse files
authored
feat(command): Add --pattern flag for tests (#44)
With the `--pattern` flag available for the `test` and `start` commands, we can filter down which tests are being run. This is particularly useful when running tests in watch mode. This is probably more realistic than running `benmvp start` on the whole source code.
1 parent e09942e commit 3212dee

File tree

13 files changed

+319
-43
lines changed

13 files changed

+319
-43
lines changed

docs/api/build.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ build({
4444
})
4545
```
4646

47-
## Type
47+
## Signature
4848

4949
`build()` has the following [TypeScript](https://www.typescriptlang.org/) signature:
5050

docs/api/start.md

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ Looking for CLI docs? View companion [`benmvp start` documentation](../cli/start
66

77
## Examples
88

9-
To run all modes (default behavior):
9+
To continuously run all modes on all files (default behavior):
1010

1111
```js
1212
import {start} from '@benmvp/cli'
1313

1414
start()
1515
```
1616

17-
To run just type-checking:
17+
To continuously run just type-checking on all files:
1818

1919
```js
2020
import {start} from '@benmvp/cli'
@@ -24,7 +24,7 @@ start({
2424
})
2525
```
2626

27-
To run linting & unit tests:
27+
To continuously run linting & unit tests on all files:
2828

2929
```sh
3030
import {start} from '@benmvp/cli'
@@ -34,12 +34,39 @@ start({
3434
})
3535
```
3636

37-
## Type
37+
To continuously run all modes only on files within `utils/` directories:
38+
39+
```js
40+
import {test} from '@benmvp/cli'
41+
42+
start({
43+
pattern: 'utils/',
44+
})
45+
```
46+
47+
To continuously run just linting on files within `api/` directories:
48+
49+
```js
50+
import {test} from '@benmvp/cli'
51+
52+
start({
53+
modes: ['lint'],
54+
pattern: 'api/',
55+
})
56+
```
57+
58+
## Signature
3859

3960
`start()` has the following [TypeScript](https://www.typescriptlang.org/) signature:
4061

4162
```js
42-
([options]: Options): Promise<Result>
63+
type Mode = 'type' | 'lint' | 'unit'
64+
namespace TestOptions {
65+
modes: Mode[];
66+
pattern: string;
67+
}
68+
69+
([options]: TestOptions): Promise<Result>
4370
```
4471

4572
## Options
@@ -58,6 +85,12 @@ Optional. Defaults to all modes when unspecified.
5885

5986
> NOTE: [Jest Watch Plugins](https://jestjs.io/docs/en/watch-plugins) are added to make watch mode even more useful. Specifically the [eslint `watch-fix` plugin](https://github.com/jest-community/jest-runner-eslint#toggle---fix-in-watch-mode) is added to enable auto-fixing of lint errors. However, for this to work, `'lint'` has to be the first mode when specified.
6087
88+
### `pattern`
89+
90+
A regexp pattern string that is matched against all tests paths before executing the test.
91+
92+
Optional. Defaults to `''` (signifying no filter)
93+
6194
## Return Value
6295

6396
`start()` returns a `Promise`.

docs/api/test.md

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ Looking for CLI docs? View companion [`benmvp test` documentation](../cli/test.m
88

99
## Examples
1010

11-
To run all modes (default behavior):
11+
To run all modes on all files (default behavior):
1212

1313
```js
1414
import {test} from '@benmvp/cli'
1515

1616
test()
1717
```
1818

19-
To run just unit tests:
19+
To run just unit tests on all files:
2020

2121
```js
2222
import {test} from '@benmvp/cli'
@@ -26,27 +26,56 @@ test({
2626
})
2727
```
2828

29-
To run typing & linting:
29+
To run linting & typing on all files:
3030

3131
```js
3232
import {test} from '@benmvp/cli'
3333

3434
test({
35-
modes: ['type', 'lint'],
35+
modes: ['lint', 'type'],
3636
})
3737
```
3838

39-
## Type
39+
To run all modes only on files within `utils/` directories:
40+
41+
```js
42+
import {test} from '@benmvp/cli'
43+
44+
test({
45+
pattern: 'utils/',
46+
})
47+
```
48+
49+
To just run linting on files within `api/` directories while continuously watching for changes:
50+
51+
```js
52+
import {test} from '@benmvp/cli'
53+
54+
test({
55+
modes: ['lint'],
56+
pattern: 'api/',
57+
watch: true,
58+
})
59+
```
60+
61+
## Signature
4062

4163
`test()` has the following [TypeScript](https://www.typescriptlang.org/) signature:
4264

4365
```js
44-
([options]: Options): Promise<Result>
66+
type Mode = 'type' | 'lint' | 'unit'
67+
namespace TestOptions {
68+
modes: Mode[];
69+
pattern: string;
70+
watch: boolean;
71+
}
72+
73+
([options]: TestOptions): Promise<Result>
4574
```
4675

4776
## Options
4877

49-
The optional `Options` object supports the following properties:
78+
The optional `TestOptions` object supports the following properties:
5079

5180
### `modes`
5281

@@ -58,6 +87,12 @@ An `Array` of the types or modes of tests to run. Available modes:
5887

5988
Optional. Defaults to all modes when unspecified.
6089

90+
### `pattern`
91+
92+
A regexp pattern string that is matched against all tests paths before executing the test.
93+
94+
Optional. Defaults to `''` (signifying no filter)
95+
6196
### `watch`
6297

6398
A flag indicating whether or not to continuously run the tests whenever source files change.

docs/cli/start.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,36 @@ Looking for Node API docs? View companion [`start()` documentation](../api/start
88

99
## Examples
1010

11-
To run all modes (default behavior):
11+
To continuously run all modes on all files (default behavior):
1212

1313
```sh
1414
benmvp start
1515
```
1616

17-
To run just type-checking:
17+
To continuously run just type-checking on all files:
1818

1919
```sh
2020
benmvp start --modes type
2121
```
2222

23-
To run linting & unit tests:
23+
To continuously run linting & unit tests on all files:
2424

2525
```sh
2626
benmvp start --modes lint unit
2727
```
2828

29+
To continuously run all modes only on files within `utils/` directories:
30+
31+
```sh
32+
benmvp start --pattern utils/
33+
```
34+
35+
To continuously run just linting on files within `api/` directories:
36+
37+
```sh
38+
benmvp start --modes lint --pattern api/
39+
```
40+
2941
## Arguments
3042

3143
### `--modes`
@@ -40,6 +52,12 @@ Optional. Defaults to all modes.
4052

4153
> NOTE: [Jest Watch Plugins](https://jestjs.io/docs/en/watch-plugins) are added to make watch mode even more useful. Specifically the [eslint `watch-fix` plugin](https://github.com/jest-community/jest-runner-eslint#toggle---fix-in-watch-mode) is added to enable auto-fixing of lint errors. However, for this to work, `lint` has to be the first mode when specified.
4254
55+
### `--pattern`
56+
57+
A regexp pattern string that is matched against all tests paths before executing the test. Aliased as `-p`.
58+
59+
Optional. Defaults to `''` (signifying no filter)
60+
4361
---
4462

4563
## More help

docs/cli/test.md

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,34 @@ Looking for Node API docs? View companion [`test()` documentation](../api/test.m
88

99
## Examples
1010

11-
To run all modes (default behavior):
11+
To run all modes on all files (default behavior):
1212

1313
```sh
1414
benmvp test
1515
```
1616

17-
To run just unit tests:
17+
To run just unit tests on all files:
1818

1919
```sh
2020
benmvp test --modes unit
2121
```
2222

23-
To run typing & linting:
23+
To run linting & typing on all files:
2424

2525
```sh
26-
benmvp start --modes lint type
26+
benmvp test --modes lint type
27+
```
28+
29+
To run all modes only on files within `utils/` directories:
30+
31+
```sh
32+
benmvp test --patern utils/
33+
```
34+
35+
To just run linting on files within `api/` directories while continuously watching for changes:
36+
37+
```sh
38+
benmvp test --modes lint --pattern api/ --watch
2739
```
2840

2941
## Arguments
@@ -38,6 +50,12 @@ A space-separated list of the types or modes of tests to run. Aliased as `-m`. A
3850

3951
Optional. Defaults to all modes.
4052

53+
### `--pattern`
54+
55+
A regexp pattern string that is matched against all tests paths before executing the test. Aliased as `-p`.
56+
57+
Optional. Defaults to `''` (signifying no filter)
58+
4159
### `--watch`
4260

4361
A flag indicating whether or not to continuously run the tests whenever source files change. Aliased as `-w`.

0 commit comments

Comments
 (0)