fix: allow user to define testMatch in package.json (#1069)

close #1067
This commit is contained in:
Derek Henscheid
2018-04-25 16:50:41 -05:00
committed by Evan You
parent 1fc9593930
commit cac18f231e
3 changed files with 50 additions and 11 deletions
@@ -11,3 +11,49 @@ test('should work', async () => {
})
await project.run(`vue-cli-service test`)
})
test('should respect jest testMatch config', async () => {
const project = await create('unit-jest-package.json', {
plugins: {
'@vue/cli-plugin-babel': {},
'@vue/cli-plugin-unit-jest': {}
}
})
const config = JSON.parse(await project.read('package.json'))
config.jest.testMatch = ['custom-test-directory/my.spec.js']
await project.write('package.json', JSON.stringify(config))
let result
try {
await project.run(`vue-cli-service test`)
} catch (e) {
result = e
}
expect(result.stdout).toMatch('testMatch: custom-test-directory/my.spec.js')
expect(result.stdout).toMatch('No tests found')
})
test('should respect jest.config.js testMatch config', async () => {
const project = await create('unit-jest-jest.config.js', {
plugins: {
'@vue/cli-plugin-babel': {},
'@vue/cli-plugin-unit-jest': {}
},
useConfigFiles: true
})
await project.write('jest.config.js', `
module.exports = ${JSON.stringify({
testMatch: ['custom-test-directory/my.spec.js']
})}
`)
let result
try {
await project.run(`vue-cli-service test`)
} catch (e) {
result = e
}
expect(result.stdout).toMatch('testMatch: custom-test-directory/my.spec.js')
expect(result.stdout).toMatch('No tests found')
})
@@ -28,6 +28,9 @@ module.exports = api => {
// serializer for snapshots
'snapshotSerializers': [
'jest-serializer-vue'
],
'testMatch': [
'<rootDir>/(tests/unit/**/*.spec.(ts|tsx|js)|**/__tests__/*.(ts|tsx|js))'
]
}
+1 -11
View File
@@ -17,18 +17,8 @@ module.exports = api => {
const execa = require('execa')
const jestBinPath = require.resolve('jest/bin/jest')
let testMatch = []
if (!args._.length) {
testMatch = [`--testMatch`, `<rootDir>/(tests/unit/**/*.spec.(ts|tsx|js)|**/__tests__/*.(ts|tsx|js))`]
}
const argv = [
...rawArgv,
...testMatch
]
return new Promise((resolve, reject) => {
const child = execa(jestBinPath, argv, {
const child = execa(jestBinPath, rawArgv, {
cwd: api.resolve('.'),
stdio: 'inherit'
})