@ vue / cli-plugin-unit-mocha(Google no solution)生成的测试报告中被测试文件的路径错误

时间:2019-05-13 11:32:01

标签: javascript unit-testing vue.js mocha mocha-webpack

我已经运行了测试套件,并通过mochawesome生成了报告。测试文件的路径错误。我已经尝试过其他报告,但仍然得到了相同的结果。在每个结果中,它始终是 /dist/main.js 路径。

我是否必须在其他任何地方进行配置?或者,找到更多解决方案的任何关键字都不错。预先谢谢你。

HTML测试报告。

TestReport image

test.js

var expect = require('chai').expect;
var getToken = require('../../src/utils/auth').getToken;
var setToken = require('../../src/utils/auth').setToken;

describe('Auth Utils Test', () => {
  it('Should return the token', function() { // no done
    setToken("hihi");
    expect(getToken(), "Take token").equal("hihi");
  });

vue.config.js

module.exports = {
  transpileDependencies: ['vuex-module-decorators'],
  runtimeCompiler: true,
  pluginOptions: {
    electronBuilder: {
      // List native deps here if they don't work
      externals: ['escpos'],
      // If you are using Yarn Workspaces, you may have multiple node_modules folders
      // List them all here so that VCP Electron Builder can find them
      nodeModulesPath: ['../../node_modules', './node_modules']
    }
  },
  chainWebpack: config => {
    // config.plugin('copy').use(require('copy-webpack-plugin'), [[
    //   { from: '/src/*', to: 'public/', toType: 'dir' }
    // ]])
  }
}

package.json

"devDependencies": {
    ...
    "@types/chai": "^4.1.0",
    "@types/mocha": "^5.2.4",
    "@types/pouchdb": "^6.3.3",
    "@vue/cli-plugin-babel": "^3.5.0",
    "@vue/cli-plugin-e2e-nightwatch": "^3.6.0",
    "@vue/cli-plugin-eslint": "^3.5.0",
    "@vue/cli-plugin-typescript": "^3.5.0",
    "@vue/cli-plugin-unit-mocha": "^3.5.0",
    "@vue/cli-service": "^3.5.0",
    "@vue/eslint-config-standard": "^4.0.0",
    "@vue/eslint-config-typescript": "^4.0.0",
    "@vue/test-utils": "1.0.0-beta.29",
    "babel-eslint": "^10.0.1",
    "babel-plugin-istanbul": "^5.1.3",
    "bootstrap": "^4.3.1",
    "chai": "^4.1.2",
    "chromedriver": "^73.0.0",
    "copy-webpack-plugin": "^5.0.2",
    "electron": "^4.0.0",
    "electron-chromedriver": "^5.0.0-beta.1",
    "electron-rebuild": "^1.8.4",
    "eslint": "^5.8.0",
    "eslint-plugin-vue": "^5.0.0",
    "jquery": "^3.4.0",
    "mochawesome": "^3.1.2",
    "nyc": "^14.0.0",
    "popper.js": "^1.15.0",
    "sass-loader": "^7.1.0",
    "ts-node": "^8.1.0",
    "ts-protoc-gen": "^0.9.0",
    "typescript": "^3.2.1",
    "vue-cli-plugin-electron-builder": "^1.2.0",
    "vue-template-compiler": "^2.5.21",
    "vuex-module-decorators": "^0.9.8"
    ...
  }

运行命令

"test:unit": "vue-cli-service test:unit --reporter mochawesome --reporter-options reportDir=reports/unitTests,reportFilename=unitTest"

tsconfig.json

{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "strict": true,
    "jsx": "preserve",
    "importHelpers": true,
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "removeComments": false,
    "baseUrl": ".",
    "types": [
      "webpack-env",
      "mocha",
      "chai",
      "node"
    ],
    "paths": {
      "@/*": [
        "src/*",
        "node_modules/escpos/*"
      ]
    },
    "lib": [
      "esnext",
      "dom",
      "dom.iterable",
      "scripthost"
    ]
  },
  "include": [
    "src/**/*.ts",
    "src/**/*.tsx",
    "src/**/*.vue",
    "tests/**/*.ts",
    "tests/**/*.tsx"
  ],
  "exclude": [
    "node_modules"
  ]
}

babel.config.js

module.exports = {
  presets: [
    '@vue/app'
  ]
}

0 个答案:

没有答案