npm脚本无法正确启动业力测试

时间:2020-06-10 07:22:59

标签: npm karma-runner git-bash parcel

我正在使用包裹在Windows上构建项目,并安装了业力作为测试运行程序。我希望当我更改源代码时,包裹将重建项目,业力将执行测试。所以我添加了

  "script": {
     "dev-test": "parcel watch test/* --no-cache & karma start --auto-watch"
  }

到我的package.json。

奇怪的是,当我运行“ npm run dev-test ”时,包裹构建了项目,但因果报应没有执行任何测试,终端显示“√内置5.95秒。”,这就是我所拥有的。

我必须在命令行中键入整个命令“ parcel watch test / * --no-cache&npx karma start --auto-watch ”(karma未全局安装所以我必须添加npx),这似乎是一种解决方法,但是仍然存在一个错误(“&”表示包裹和业力同时运行,因此业力在构建项目时会多次运行测试)

我不想键入整个命令,希望可以使用npm脚本。

如果有帮助,这是我的package.json

{
  "name": "custom-vue-component",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "parcel build test/* --no-cache --no-minify && karma start --single-run",
    "dev-test": "parcel watch test/* --no-cache &  karma start --auto-watch"
  },
  "repository": {
    "type": "git",
  },
  "author": "me",
  "license": "ISC",
  "dependencies": {
    "vue": "^2.6.11",
    "vue-hot-reload-api": "^2.3.4"
  },
  "devDependencies": {
    "@vue/component-compiler-utils": "^3.1.2",
    "chai": "^4.2.0",
    "chai-spies": "^1.0.0",
    "karma": "^5.0.9",
    "karma-chai": "^0.1.0",
    "karma-chai-spies": "^0.1.4",
    "karma-chrome-launcher": "^3.1.0",
    "karma-mocha": "^2.0.1",
    "karma-sinon-chai": "^2.0.2",
    "mocha": "^7.2.0",
    "parcel-bundler": "^1.12.4",
    "sass": "^1.26.7",
    "sinon": "^9.0.2",
    "sinon-chai": "^3.5.0",
    "vue-template-compiler": "^2.6.11"
  },
  "alias": {
    "vue": "./node_modules/vue/dist/vue.common.js"
  }
}


和karma.conf.js


module.exports = function(config) {
  config.set({
    basePath: "",
    frameworks: ["mocha", "sinon-chai"],
    client: {
      chai: {
        includeStack: true,
      },
    },
    files: ["dist/**/*.test.js", "dist/**/*.test.css"],
    exclude: [],
    preprocessors: {},
    reporters: ["progress"],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ["ChromeHeadless"],
    singleRun: false,
    concurrency: Infinity,
  });
}

1 个答案:

答案 0 :(得分:0)

如果您是Windows用户,则可能会遇到此问题。

您可以通过分别运行parcel watch test/* --no-cache & karma start来解决它:

  1. 打开git bush窗口并运行npx parcel watch test/* --no-cache
  2. 打开另一个git bush窗口并运行npx karma start