Skip to content

Commit cac18f2

Browse files
dhenscheyyx990803
authored andcommittedApr 25, 2018
fix: allow user to define testMatch in package.json (#1069)
close #1067
1 parent 1fc9593 commit cac18f2

File tree

3 files changed

+50
-11
lines changed

3 files changed

+50
-11
lines changed
 

‎packages/@vue/cli-plugin-unit-jest/__tests__/jestPlugin.spec.js

+46
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,49 @@ test('should work', async () => {
1111
})
1212
await project.run(`vue-cli-service test`)
1313
})
14+
15+
test('should respect jest testMatch config', async () => {
16+
const project = await create('unit-jest-package.json', {
17+
plugins: {
18+
'@vue/cli-plugin-babel': {},
19+
'@vue/cli-plugin-unit-jest': {}
20+
}
21+
})
22+
const config = JSON.parse(await project.read('package.json'))
23+
config.jest.testMatch = ['custom-test-directory/my.spec.js']
24+
25+
await project.write('package.json', JSON.stringify(config))
26+
27+
let result
28+
try {
29+
await project.run(`vue-cli-service test`)
30+
} catch (e) {
31+
result = e
32+
}
33+
expect(result.stdout).toMatch('testMatch: custom-test-directory/my.spec.js')
34+
expect(result.stdout).toMatch('No tests found')
35+
})
36+
37+
test('should respect jest.config.js testMatch config', async () => {
38+
const project = await create('unit-jest-jest.config.js', {
39+
plugins: {
40+
'@vue/cli-plugin-babel': {},
41+
'@vue/cli-plugin-unit-jest': {}
42+
},
43+
useConfigFiles: true
44+
})
45+
await project.write('jest.config.js', `
46+
module.exports = ${JSON.stringify({
47+
testMatch: ['custom-test-directory/my.spec.js']
48+
})}
49+
`)
50+
51+
let result
52+
try {
53+
await project.run(`vue-cli-service test`)
54+
} catch (e) {
55+
result = e
56+
}
57+
expect(result.stdout).toMatch('testMatch: custom-test-directory/my.spec.js')
58+
expect(result.stdout).toMatch('No tests found')
59+
})

‎packages/@vue/cli-plugin-unit-jest/generator/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ module.exports = api => {
2828
// serializer for snapshots
2929
'snapshotSerializers': [
3030
'jest-serializer-vue'
31+
],
32+
'testMatch': [
33+
'<rootDir>/(tests/unit/**/*.spec.(ts|tsx|js)|**/__tests__/*.(ts|tsx|js))'
3134
]
3235
}
3336

‎packages/@vue/cli-plugin-unit-jest/index.js

+1-11
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,8 @@ module.exports = api => {
1717
const execa = require('execa')
1818
const jestBinPath = require.resolve('jest/bin/jest')
1919

20-
let testMatch = []
21-
if (!args._.length) {
22-
testMatch = [`--testMatch`, `<rootDir>/(tests/unit/**/*.spec.(ts|tsx|js)|**/__tests__/*.(ts|tsx|js))`]
23-
}
24-
25-
const argv = [
26-
...rawArgv,
27-
...testMatch
28-
]
29-
3020
return new Promise((resolve, reject) => {
31-
const child = execa(jestBinPath, argv, {
21+
const child = execa(jestBinPath, rawArgv, {
3222
cwd: api.resolve('.'),
3323
stdio: 'inherit'
3424
})

0 commit comments

Comments
 (0)
Please sign in to comment.