Skip to content

Commit

Permalink
fix: moved the default testMatch setting to the generator to allow ov…
Browse files Browse the repository at this point in the history
…errides 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
  • Loading branch information
test committed Apr 13, 2018
1 parent bcd92b1 commit d4e1317
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
30 changes: 27 additions & 3 deletions packages/@vue/cli-plugin-unit-jest/__tests__/jestPlugin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test('should work', async () => {
})

test('should respect jest testMatch config', async () => {
const project = await create('unit-jest', {
const project = await create('unit-jest-package.json', {
plugins: {
'@vue/cli-plugin-babel': {},
'@vue/cli-plugin-unit-jest': {}
Expand All @@ -30,6 +30,30 @@ test('should respect jest testMatch config', async () => {
} catch (e) {
result = e
}
console.log(result)
expect(result.stdout).toMatch('custom-test-directory/my.spec.js')
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')
})
3 changes: 3 additions & 0 deletions packages/@vue/cli-plugin-unit-jest/generator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))'
]
}

Expand Down
12 changes: 1 addition & 11 deletions packages/@vue/cli-plugin-unit-jest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,8 @@ module.exports = api => {
const execa = require('execa')
const jestBinPath = require.resolve('jest/bin/jest')

let testMatch = []
if (!args._.length && !api.service.pkg.jest.testMatch) {
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'
})
Expand Down

0 comments on commit d4e1317

Please sign in to comment.