Skip to content

Commit

Permalink
test: simplify test matching
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jan 15, 2018
1 parent 65cc27d commit 04ceebf
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ jobs:
key: v1-dependencies-{{ checksum "yarn.lock" }}

# run tests!
- run: yarn test-all
- run: yarn test
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,27 @@ yarn serve

### Testing Tips

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.
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:

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

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

``` sh
yarn test-plugin pwa
yarn test typescript
```

Or, just specify your own regex:
To further narrow down tests, you can also specify your own regex:

``` sh
yarn test <fileRegex>
yarn test -g <filenameRegex>
```

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.
You can also pass `--watch` to any of the test scripts to run tests in watch mode.

Note that `jest -o` (running tests related to modified files) isn't always accurate because some tests spawn child processes.

### Plugin Development

Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ test_script:
- git --version
- node --version
- yarn --version
- yarn test-all
- yarn test

cache:
- node_modules -> yarn.lock
Expand Down
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@
"packages/test/*"
],
"scripts": {
"test": "node scripts/testChanged.js",
"test-all": "jest --env node --runInBand",
"test-plugin": "node scripts/testPlugin.js",
"test": "node scripts/test.js",
"posttest": "yarn clean",
"posttest-all": "yarn clean",
"posttest-plugin": "yarn clean",
"lint": "eslint --fix packages/**/*.js packages/**/bin/* test/**/*.js",
"clean": "rimraf packages/test/*",
"sync": "node scripts/syncDeps.js",
Expand All @@ -29,6 +25,7 @@
"/template/",
"/packages/test/",
"/temp/",
"/scripts/",
".*.helper.js"
]
},
Expand Down
23 changes: 23 additions & 0 deletions scripts/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const execa = require('execa')
const minimist = require('minimist')

const args = minimist(process.argv.slice(2))

const packages = args._
let regex = args.g || args.grep
if (!regex && packages.length) {
regex = `.*@vue/(${packages.join('|')}|cli-plugin-(${packages.join('|')}))/.*\\.spec\\.js$`
}

;(async () => {
await execa('jest', [
'--env', 'node',
'--runInBand',
...(regex ? [regex] : [])
], {
stdio: 'inherit'
})
})().catch(err => {
console.error(err)
process.exit(1)
})
32 changes: 0 additions & 32 deletions scripts/testChanged.js

This file was deleted.

17 changes: 0 additions & 17 deletions scripts/testPlugin.js

This file was deleted.

0 comments on commit 04ceebf

Please sign in to comment.