Skip to content

Unexpected token import #47

@emman27

Description

@emman27

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions