Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow user to define testMatch in package.json (#1067) #1069

Merged
merged 2 commits into from
Apr 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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