Skip to content

Commit

Permalink
fix: allow user to define testMatch in package.json (#1069)
Browse files Browse the repository at this point in the history
close #1067
  • Loading branch information
dhensche authored and yyx990803 committed Apr 25, 2018
1 parent 1fc9593 commit cac18f2
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 11 deletions.
46 changes: 46 additions & 0 deletions packages/@vue/cli-plugin-unit-jest/__tests__/jestPlugin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
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) {
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 cac18f2

Please sign in to comment.