Skip to content

Commit

Permalink
fix: transform es modules syntax for Jest when not using Babel
Browse files Browse the repository at this point in the history
close #1524
  • Loading branch information
yyx990803 committed Jun 8, 2018
1 parent dd39866 commit 65d5d36
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
10 changes: 10 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 @@ -57,3 +57,13 @@ test('should respect jest.config.js testMatch config', async () => {
expect(result.stdout).toMatch('testMatch: custom-test-directory/my.spec.js')
expect(result.stdout).toMatch('No tests found')
})

test('should work without Babel', async () => {
const project = await create('jest-without-babel', {
plugins: {
'@vue/cli-plugin-unit-jest': {}
},
useConfigFiles: true
})
await project.run(`vue-cli-service test:unit`)
})
8 changes: 7 additions & 1 deletion packages/@vue/cli-plugin-unit-jest/generator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,21 @@ module.exports = api => {
}

if (!api.hasPlugin('typescript')) {
jestConfig.transform['^.+\\.jsx?$'] = 'babel-jest'
if (api.hasPlugin('babel')) {
jestConfig.transform['^.+\\.jsx?$'] = 'babel-jest'
api.extendPackage({
devDependencies: {
'babel-jest': '^23.0.1',
// this is for now necessary to force babel-jest and vue-jest to use babel 7
'babel-core': '7.0.0-bridge.0'
}
})
} else {
api.extendPackage({
babel: {
plugins: ['transform-es2015-modules-commonjs']
}
})
}
} else {
jestConfig.moduleFileExtensions.unshift('ts', 'tsx')
Expand Down
3 changes: 2 additions & 1 deletion packages/@vue/cli-plugin-unit-jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@
},
"dependencies": {
"@vue/cli-shared-utils": "^3.0.0-beta.16",
"babel-jest": "^23.0.1",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
"jest": "^23.1.0",
"jest-serializer-vue": "^1.0.0",
"jest-transform-stub": "^1.0.0",
"vue-jest": "^2.6.0"
},
"devDependencies": {
"@vue/test-utils": "^1.0.0-beta.16",
"babel-jest": "^23.0.1",
"ts-jest": "^22.4.6"
}
}

0 comments on commit 65d5d36

Please sign in to comment.