Closed
Description
Version
3.0.0-beta.2
Reproduction link
Steps to reproduce
vue create test-dyn-import
- pick vue-router, vuex, sass, babel, pwa, eslint, unit-jest
- add new file users.json under test/unit
{
"data": ["bob", "max"]
}
- add the following test
it('should import my file', async () => {
const userFile = './users.json'
const users = await import(userFile)
console.log(users)
})
- run
npm run test
What is expected?
test should be green and print something like this { data: [ 'bob', 'max' ] }
What is actually happening?
~/sites/lab/test-dyn-import(master*) » npm run test
> test-dyn-import@0.1.0 test /home/maxence/sites/lab/test-dyn-import
> vue-cli-service test
FAIL tests/unit/HelloWorld.spec.js
● Test suite failed to run
/home/maxence/sites/lab/test-dyn-import/tests/unit/HelloWorld.spec.js:35
return import(userFile).then(function (someModule) {
^^^^^^
SyntaxError: Unexpected token import
at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:316:17)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 1.488s
Ran all test suites.
ERROR jest exited with code 1.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! test-dyn-import@0.1.0 test: `vue-cli-service test`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the test-dyn-import@0.1.0 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/maxence/.npm/_logs/2018-03-02T17_51_40_312Z-debug.log
I'm trying to switch to the new file architecture for one of my side project (https://github.com/maxpou/gitvub).
I solved this issue with the past architecture by the following babelrc file
{
"presets": [
["env", {
"modules": false,
"targets": {
"browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
}
}],
"stage-2"
],
"plugins": ["transform-runtime"],
"env": {
"test": {
"presets": ["env", "stage-2"],
"plugins": ["transform-es2015-modules-commonjs", "dynamic-import-node"]
}
}
}