Skip to content

Commit bcd92b1

Browse files
committed
fix: allow user to define testMatch in package.json (#1067)
1 parent e65110f commit bcd92b1

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,25 @@ 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', {
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+
console.log(result)
34+
expect(result.stdout).toMatch('custom-test-directory/my.spec.js')
35+
})

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports = api => {
1818
const jestBinPath = require.resolve('jest/bin/jest')
1919

2020
let testMatch = []
21-
if (!args._.length) {
21+
if (!args._.length && !api.service.pkg.jest.testMatch) {
2222
testMatch = [`--testMatch`, `<rootDir>/(tests/unit/**/*.spec.(ts|tsx|js)|**/__tests__/*.(ts|tsx|js))`]
2323
}
2424

0 commit comments

Comments
 (0)