test: add test-changed script

This commit is contained in:
Evan You
2018-01-14 16:26:21 -05:00
parent ed4d845021
commit aa87be024c
2 changed files with 25 additions and 2 deletions

View File

@@ -5,7 +5,8 @@
"packages/test/*"
],
"scripts": {
"test": "jest --env node",
"test": "jest --env node --runInBand",
"test-changed": "node scripts/testChanged.js",
"posttest": "yarn clean",
"lint": "eslint --fix packages/**/*.js packages/**/bin/* test/**/*.js",
"clean": "rimraf packages/test/*",
@@ -23,7 +24,8 @@
"testPathIgnorePatterns": [
"/template/",
"/packages/test/",
"/temp/"
"/temp/",
".*.helper.js"
]
},
"lint-staged": {

21
scripts/testChanged.js Normal file
View File

@@ -0,0 +1,21 @@
const execa = require('execa')
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))
await execa('jest', [
'--env', 'node',
'--runInBand',
...additionalArgs,
'--findRelatedTests', ...files
], {
stdio: 'inherit'
})
})().catch(err => {
console.error(err)
process.exit(1)
})