【发布时间】:2020-09-29 12:51:52
【问题描述】:
我正在使用 parcel 在 windows 上构建我的项目,并安装了 karma 作为我的测试运行器。我希望当我更改我的源代码时,包裹会重建项目并且业力会执行测试。所以我添加了
"script": {
"dev-test": "parcel watch test/* --no-cache & karma start --auto-watch"
}
到我的 package.json。
奇怪的是当我运行“npm run dev-test”时,parcel构建了项目但karma没有执行任何测试,终端显示“√内置 5.95 秒。”,这就是我所得到的。
我必须在命令行中输入整个命令“parcel watch test/* --no-cache & npx karma start --auto-watch”(karma 未全局安装所以我必须添加npx),这似乎是一种解决方法,但仍然有一个错误(“&”表示parcel和karma同时运行,所以在parcel构建项目时karma会运行多次测试)
我不想输入整个命令,我希望我可以使用 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,
});
}
【问题讨论】:
标签: npm karma-runner git-bash parcel