簡體   English   中英

我無法通過 symfony/webpack-encore 使用 Jest 和 Vuejs 運行測試

[英]I can't run test using Jest and Vuejs with symfony/webpack-encore

我正在嘗試在 symfony/webpack-encore 上使用 jest 和 vuejs 框架來實現單元測試,但經過多次嘗試,我仍然收到此錯誤:

Jest 遇到了意外的令牌

這通常意味着您正在嘗試導入 Jest 無法解析的文件,例如它不是普通的 JavaScript。

默認情況下,如果 Jest 看到 Babel 配置,它將使用它來轉換您的文件,而忽略“node_modules”。

進口 {
^

語法錯誤:意外的令牌 {

20 |
21 | 從'三'導入*作為三;

22 | 從“三個/examples/jsm/loaders/GLTFLoader.js”導入{ GLTFLoader};
| ^

這里是 my.babelrc & package.json 文件:

.babelrc:

{
  "presets": [
    "env", 
    ["env", {
      "modules": false
    }],
    "stage-2",
    "vue"
  ],
  "plugins": ["transform-runtime", "transform-es2015-modules-commonjs"],
  "env": {
    "test": {
      "presets":[
        ["es2015", { "modules": false }],
        "vue",
        "stage-2"
      ],
      "plugins": [
        "transform-es2015-modules-commonjs",
        "dynamic-import-node"
      ]
    }
  }
}

package.json:

{
    "dependencies": {
        "bazinga-translator": "^2.6.6",
        "bootstrap": "^4.3.1",
        "driver.js": "^0.9.6",
        "highcharts": "^6.2.0",
        "jquery": "^3.3.1",
        "jquery-ui": "^1.12.1",
        "jquery.fancytree": "^2.30.2"
    },
    "devDependencies": {
        "@babel/core": "^7.7.0",
        "@babel/plugin-proposal-nullish-coalescing-operator": "^7.2.0",
        "@babel/plugin-syntax-dynamic-import": "^7.2.0",
        "@babel/preset-env": "^7.7.1",
        "@babel/preset-stage-2": "^7.0.0",
        "@symfony/webpack-encore": "^0.27.0",
        "@vue/cli-plugin-babel": "^3.0.5",
        "@vue/cli-plugin-e2e-cypress": "^3.0.5",
        "@vue/cli-plugin-eslint": "^3.0.5",
        "@vue/cli-plugin-pwa": "^3.0.5",
        "@vue/cli-plugin-unit-jest": "^3.0.5",
        "@vue/cli-service": "^3.0.5",
        "@vue/test-utils": "^1.0.0-beta.29",
        "babel-jest": "^24.9.0",
        "babel-loader": "^8.0.6",
        "babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
        "babel-preset-env": "^1.7.0",
        "babel-preset-es2015": "^6.24.1",
        "babel-preset-stage-0": "^6.24.1",
        "babel-preset-stage-2": "^6.24.1",
        "babel-preset-vue": "^2.0.2",
        "core-js": "^3.0.0",
        "expose-loader": "^0.7.5",
        "file-loader": "^4.2.0",
        "gltf-loader-2": "^0.0.3",
        "jest": "^24.9.0",
        "jest-serializer-vue": "^2.0.2",
        "jest-transform-stub": "^2.0.0",
        "jest-vue-preprocessor": "^1.7.0",
        "node-sass": "^4.12.0",
        "regenerator-runtime": "^0.13.2",
        "sass-loader": "^7.0.1",
        "stats.js": "^0.17.0",
        "three": "^0.110.0",
        "three-orbitcontrols": "^2.110.1",
        "transform-runtime": "^0.0.0",
        "url-loader": "^1.1.1",
        "vue": "^2.6.10",
        "vue-jest": "^3.0.5",
        "vue-loader": "^15.0.11",
        "vue-svg-loader": "^0.12.0",
        "vue-template-compiler": "^2.6.10",
        "webpack-notifier": "^1.6.0"
    },
    "scripts": {
        "dev-server": "encore dev-server",
        "dev": "encore dev",
        "watch": "encore dev --watch",
        "build": "encore production --progress",
        "test": "jest ./assets/src",
        "test:unit": "vue-cli-service test:unit"
    }
}

我確實嘗試過使用 vue-cli,但在同一個地方仍然遇到同樣的錯誤!

謝謝,

問題在於導入three.js庫,來源: https://github.com/facebook/jest/issues/3905#issuecomment-323525803

只需遵循此文檔,我就可以運行我的測試。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM