Skip to content

Commit 04ceebf

Browse files
committed
test: simplify test matching
1 parent 65cc27d commit 04ceebf

File tree

7 files changed

+38
-63
lines changed

7 files changed

+38
-63
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ jobs:
2626
key: v1-dependencies-{{ checksum "yarn.lock" }}
2727

2828
# run tests!
29-
- run: yarn test-all
29+
- run: yarn test

README.md

+11-7
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,27 @@ yarn serve
2727

2828
### Testing Tips
2929

30-
The full test suite is rather slow, because it has a number of e2e tests that performs full webpack builds of actual projects. Therefore the default `test` script automatically runs only tests that are related to the files that have been modified/added since the last commit.
30+
The full test suite is rather slow, because it has a number of e2e tests that performs full webpack builds of actual projects. To narrow down the tests needed to run during development, you can use the `test-package` script to run tests for specific packages:
3131

32-
To run the full test suite, run `yarn test-all` instead. CI always runs all tests.
32+
``` sh
33+
yarn test cli cli-services
34+
```
3335

34-
Alternatively, you can run tests for a specific plugin (note this only matches files ending in `.spec.js` in the given plugin):
36+
If the package is a plugin, you can commit the `cli-plugin-` prefix:
3537

3638
``` sh
37-
yarn test-plugin pwa
39+
yarn test typescript
3840
```
3941

40-
Or, just specify your own regex:
42+
To further narrow down tests, you can also specify your own regex:
4143

4244
``` sh
43-
yarn test <fileRegex>
45+
yarn test -g <filenameRegex>
4446
```
4547

46-
You can also pass `--watch` to any of the test scripts, but note the matched tests are determined from the modified files when the script is started.
48+
You can also pass `--watch` to any of the test scripts to run tests in watch mode.
49+
50+
Note that `jest -o` (running tests related to modified files) isn't always accurate because some tests spawn child processes.
4751

4852
### Plugin Development
4953

appveyor.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ test_script:
99
- git --version
1010
- node --version
1111
- yarn --version
12-
- yarn test-all
12+
- yarn test
1313

1414
cache:
1515
- node_modules -> yarn.lock

package.json

+2-5
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,8 @@
55
"packages/test/*"
66
],
77
"scripts": {
8-
"test": "node scripts/testChanged.js",
9-
"test-all": "jest --env node --runInBand",
10-
"test-plugin": "node scripts/testPlugin.js",
8+
"test": "node scripts/test.js",
119
"posttest": "yarn clean",
12-
"posttest-all": "yarn clean",
13-
"posttest-plugin": "yarn clean",
1410
"lint": "eslint --fix packages/**/*.js packages/**/bin/* test/**/*.js",
1511
"clean": "rimraf packages/test/*",
1612
"sync": "node scripts/syncDeps.js",
@@ -29,6 +25,7 @@
2925
"/template/",
3026
"/packages/test/",
3127
"/temp/",
28+
"/scripts/",
3229
".*.helper.js"
3330
]
3431
},

scripts/test.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const execa = require('execa')
2+
const minimist = require('minimist')
3+
4+
const args = minimist(process.argv.slice(2))
5+
6+
const packages = args._
7+
let regex = args.g || args.grep
8+
if (!regex && packages.length) {
9+
regex = `.*@vue/(${packages.join('|')}|cli-plugin-(${packages.join('|')}))/.*\\.spec\\.js$`
10+
}
11+
12+
;(async () => {
13+
await execa('jest', [
14+
'--env', 'node',
15+
'--runInBand',
16+
...(regex ? [regex] : [])
17+
], {
18+
stdio: 'inherit'
19+
})
20+
})().catch(err => {
21+
console.error(err)
22+
process.exit(1)
23+
})

scripts/testChanged.js

-32
This file was deleted.

scripts/testPlugin.js

-17
This file was deleted.

0 commit comments

Comments
 (0)