fix: transform es modules syntax for Jest when not using Babel

close #1524
This commit is contained in:
Evan You
2018-06-08 18:41:05 -04:00
parent dd39866cad
commit 65d5d36d39
3 changed files with 19 additions and 2 deletions
@@ -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`)
})
@@ -36,8 +36,8 @@ 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',
@@ -45,6 +45,12 @@ module.exports = api => {
'babel-core': '7.0.0-bridge.0'
}
})
} else {
api.extendPackage({
babel: {
plugins: ['transform-es2015-modules-commonjs']
}
})
}
} else {
jestConfig.moduleFileExtensions.unshift('ts', 'tsx')
@@ -23,6 +23,8 @@
},
"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",
@@ -30,7 +32,6 @@
},
"devDependencies": {
"@vue/test-utils": "^1.0.0-beta.16",
"babel-jest": "^23.0.1",
"ts-jest": "^22.4.6"
}
}