Skip to content

Commit d4e1317

Browse files
author
test
committed
fix: moved the default testMatch setting to the generator to allow overrides in either package.json or jest.config.js to function properly
- ninja edit: somehow tests passed even though I used the wrong jest config option in the generator
1 parent bcd92b1 commit d4e1317

File tree

3 files changed

+31
-14
lines changed

3 files changed

+31
-14
lines changed

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

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ test('should work', async () => {
1313
})
1414

1515
test('should respect jest testMatch config', async () => {
16-
const project = await create('unit-jest', {
16+
const project = await create('unit-jest-package.json', {
1717
plugins: {
1818
'@vue/cli-plugin-babel': {},
1919
'@vue/cli-plugin-unit-jest': {}
@@ -30,6 +30,30 @@ test('should respect jest testMatch config', async () => {
3030
} catch (e) {
3131
result = e
3232
}
33-
console.log(result)
34-
expect(result.stdout).toMatch('custom-test-directory/my.spec.js')
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')
3559
})

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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 1 addition & 11 deletions
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 && !api.service.pkg.jest.testMatch) {
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)