Skip to content

Commit

Permalink
adjust default test strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jan 14, 2018
1 parent b95ab2c commit 0e2c22e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 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
- run: yarn test-all
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ 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. To limit the tests to only the plugin / files you are working on, you can use the `test-changed` script, which 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. Therefore the default `test` script automatically runs only tests that are related to the files that have been modified/added since the last commit.

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

Alternatively, you can run tests for a specific plugin (note this only matches files ending in `.spec.js` in the given plugin):

Expand All @@ -45,6 +43,8 @@ Or, just specify your own regex:
yarn test <fileRegex>
```

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.

### Plugin Development

See [dedicated section in docs](https://github.com/vuejs/vue-cli/tree/next/docs/Plugin.md).
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
- yarn test-all

cache:
- node_modules -> yarn.lock
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
"packages/test/*"
],
"scripts": {
"test": "jest --env node --runInBand",
"test-changed": "node scripts/testChanged.js",
"test": "node scripts/testChanged.js",
"test-all": "jest --env node --runInBand",
"test-plugin": "node scripts/testPlugin.js",
"posttest": "yarn clean",
"posttest-changed": "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 Down
15 changes: 13 additions & 2 deletions scripts/testChanged.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
const execa = require('execa')
const chalk = require('chalk')

const additionalArgs = process.argv.slice(2)

;(async () => {
// get modified files
const { stdout } = await execa('git', ['ls-files', '--exclude-standard', '--modified', '--others'])
const files = stdout.split('\n').filter(line => /\.js$/.test(line))
const files = stdout.split('\n')
.filter(line => /\.js$/.test(line))
.filter(line => /^(packages|__mocks__)/.test(line))

if (!files.length) {
console.log(
`No changed src files found.\n` +
`To run the full test suite, run ${chalk.cyan(`yarn test-all`)} instead.`
)
return
}

await execa('jest', [
'--env', 'node',
Expand All @@ -16,6 +27,6 @@ const additionalArgs = process.argv.slice(2)
stdio: 'inherit'
})
})().catch(err => {
console.error(err)
err
process.exit(1)
})

0 comments on commit 0e2c22e

Please sign in to comment.