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

Unexpected token import #47

Open
emman27 opened this issue Dec 4, 2017 · 4 comments
Open

Unexpected token import #47

emman27 opened this issue Dec 4, 2017 · 4 comments

Comments

@emman27
Copy link

emman27 commented Dec 4, 2017

I'm submitting a ... (check one with "x")

[ ] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[x] support request

Current behavior

I've used jest-vue-preprocessor since the start of my project to work with files. Recently, I've added process.env (using Webpack's define plugin) to my project, and it gives me the following error.

 FAIL  test/unit/specs/components/onboarding/RecordForm.spec.js
  ● Test suite failed to run

    <path>/Form.vue:3
    import _defineProperty from 'babel-runtime/helpers/defineProperty';
    ^^^^^^
    
    SyntaxError: Unexpected token import
      
      at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:305:17)
      at Object.<anonymous> (test/unit/specs/components/Form.spec.js:6:19)
          at Generator.next (<anonymous>)

Expected behavior

Minimal reproduction of the problem with instructions
Relevant sections of

// package.json

"jest": {
    "moduleFileExtensions": [
      "js",
      "json",
      "vue"
    ],
    "moduleNameMapper": {
      "^@/(.*)$": "<rootDir>/src/$1"
    },
    "transform": {
      "^.+\\.(js)$": "<rootDir>/node_modules/babel-jest",
      "^.+\\.(vue)$": "<rootDir>/node_modules/jest-vue-preprocessor"
    },
    "mapCoverage": true,
    "snapshotSerializers": [
      "<rootDir>/node_modules/jest-serializer-vue"
    ],
    "testRegex": "test/unit/.+\\.spec.js$",
    "collectCoverageFrom": [
      "<rootDir>/src/**/*"
    ]
  }
// .babelrc

{
  "presets": [
    [
      "env",
      {
        "modules": false,
        "targets": {
          "browsers": [
            "> 1%",
            "last 2 versions",
            "not ie <= 8"
          ]
        }
      }
    ],
    "stage-2"
  ],
  "plugins": [
    "transform-runtime"
  ],
  "env": {
    "test": {
      "plugins": [
        "istanbul",
        "transform-es2015-modules-commonjs"
      ]
    }
  }
}

What is the motivation / use case for changing the behavior?
Er I just want it to work

Please tell us about your environment:
Ubuntu 16.04, bash.

  • jest-vue-preprocessor: 1.3.1
  • Node version : 8.9.1

  • Platform: Linux

As a side note, I've tried replacing jest-vue-preprocessor with vue-jest, and the transpilation process goes fine, which is why I'm assuming the error lies here and not in something else. However vue-jest has problems with test coverage reporting which I can't deal with either.

@signal-intrusion
Copy link

@emman27 were you ever able to get this to work. I'm completely blocked.

@emman27
Copy link
Author

emman27 commented Dec 6, 2017

@signal-intrusion Unfortunately not. I've moved to vue-jest. If you're on a relatively new project. I'd suggest setting up with vue-cli also - they've recently added Jest as one of their default configs.

@vire
Copy link
Owner

vire commented Dec 6, 2017

Guy unfortunately I don't have now much capacity to investigate this bug, I'd assume it's related to .babelrc config

try to use the default .babelrc config in this repo

@Fallenstedt
Copy link

@vire Your suggestion worked perfectly for me. Thank you. I have a nuxt project and I am configuring jest to work with my Nuxt components.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants