根据https://stackoverflow.com/a/45350941/4148175 A部分,我应该能够通过“ karma start --grep my-test-file.js”运行特定的测试文件。我试过了,但是运行了两个测试文件。
根据https://stackoverflow.com/a/29151264/4148175,我应该首先启动业力,然后运行特定的文件,但是在启动业力之后,我也触发了两个文件,当我尝试运行spesific文件时,我得到该端口未应答
据我了解,我必须设置autoWatch:true和singleRun:true,并且在我的karma.conf.js中就是这样
控制台:
# karma start
03 07 2019 14:02:29.713:WARN [filelist]: Pattern "C:/_d/samples/../node_modules/@webcomponents/webcomponentsjs/webcomponents-bundle.js" does not match any file.
03 07 2019 14:02:29.730:INFO [karma-server]: Karma v4.1.0 server started at http://0.0.0.0:9876/
03 07 2019 14:02:29.731:INFO [launcher]: Launching browsers Chrome, Firefox with concurrency unlimited
03 07 2019 14:02:29.739:INFO [launcher]: Starting browser Chrome
03 07 2019 14:02:29.754:INFO [launcher]: Starting browser Firefox
03 07 2019 14:02:35.891:INFO [Chrome 75.0.3770 (Windows 10.0.0)]: Connected on socket R657DrSW7GAKGkPxAAAA with id 98561767
**** certain test from a file
**** another test from other file
Chrome 75.0.3770 (Windows 10.0.0): Executed 6 of 6 SUCCESS (0.096 secs / 0.01 secs)
Firefox 67.0.0 (Windows 10.0.0): Executed 6 of 6 SUCCESS (0.073 secs / 0.017 secs)
TOTAL: 12 SUCCESS
mycompany@DESKTOPF C:\_d\samples\how-to-test-web-component
# karma run -- --grep=text.component.test.js
03 07 2019 14:03:02.469:ERROR [runner]: There is no server listening on port 9876
Karma.conf.js
module.exports = function(config) {
config.set({
basePath: "",
frameworks: ["jasmine"],
files: [
"node_modules/@webcomponents/webcomponentsjs/webcomponents-bundle.js",
{ pattern: "**/*.test.js", type: "module", included: true },
{ pattern: "**/*.js", type: "module", included: false }
],
exclude: [],
preprocessors: {},
reporters: ["spec"],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ["Chrome", "Firefox"],
singleRun: true,
concurrency: Infinity
});
};
总结:为了通过业力进行测试,我只是做错了什么或缺少了什么?