Vue-cli: npm run test:unit fails on new project.

Created on 8 Jun 2018  ·  4Comments  ·  Source: vuejs/vue-cli

Version

3.0.0-beta.15

Reproduction link

https://gitlab.com/kjell/vuecli

Steps to reproduce

Run ui. Create a project. choose feature unit testing and jest.

The result of this process is pushed to the repo https://gitlab.com/kjell/vuecli

To reproduce

  git clone https://gitlab.com/kjell/vuecli.git
  cd vuecli/
  npm install --dev
  npm run test:unit

What is expected?

Expect test to pass

What is actually happening?

I get the following error:

Jest encountered an unexpected token
...
Details:
test_cli/tests/unit/HelloWorld.spec.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import { shallowMount } from '@vue/test-utils'
                                                                                             ^^^^^^

    SyntaxError: Unexpected token import

I have tested this with beta 15 and beta 16.

Tested on Ubuntu, node v8.11.1

bug

Most helpful comment

I'm received a similar error on and off since -beta.14. I just got it with -rc.1. (below).

The workaround I found here works for me: https://github.com/facebook/jest/issues/3202#issuecomment-312386525 - delete jest* from your temp dir.

    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import "core-js/modules/es6
.promise";                                                                                                              
                                                                                             ^^^^^^                     

    SyntaxError: Unexpected token import                                                                                

      at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:402:17)      

All 4 comments

Edit: nvm it seems you removed Babel from the project...
This could be a bug

Thank you.

I am pretty sure I not removed babel on purpose and that Babel was checked in the new project wizard. I tried again now, creating new project. Making sure Jest and babel was chosen, and the same error occurs.

I saved as a preset. Is there any way to export this preset?

Hmm, ok so my commit fixed the issue when Babel was not selected, but it seems you actually wanted Babel.

So it looks more like a problem of creating the project through UI is unintentionally dropping the Babel plugin. That looks like something similar to #1479. /cc @Akryum

I'm received a similar error on and off since -beta.14. I just got it with -rc.1. (below).

The workaround I found here works for me: https://github.com/facebook/jest/issues/3202#issuecomment-312386525 - delete jest* from your temp dir.

    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import "core-js/modules/es6
.promise";                                                                                                              
                                                                                             ^^^^^^                     

    SyntaxError: Unexpected token import                                                                                

      at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:402:17)      
Was this page helpful?
0 / 5 - 0 ratings

Related issues

evelynhathaway picture evelynhathaway  ·  35Comments

duduluu picture duduluu  ·  42Comments

yangzhuq picture yangzhuq  ·  33Comments

ghenry picture ghenry  ·  40Comments

yyx990803 picture yyx990803  ·  80Comments