gpt4 book ai didi

command-line - 使用模式匹配在 Karma Jasmine 中选择性执行测试

转载 作者:行者123 更新时间:2023-12-03 06:14:25 25 4
gpt4 key购买 nike

我在调用 karma-jasmine 上的命令行选项时遇到问题,该选项仅允许执行那些与给定模式匹配的测试。我的规范如下:

/path/to/single-test/ma​​in.spec.js

describe('my first test suite', function() {
it('always passes', function() {
expect(true).toBe(true);
});

it('still always passes', function() {
expect(true).toBe(true);
});
});

我假设描述(例如“仍然总是通过”)是与 grep 命令行选项指定的模式相匹配的项目。当我尝试运行第二个示例(基于其描述是唯一包含单词“still”的示例)时,两个示例都会执行,而不仅仅是一个示例:

$ karma start -- --grep=still
INFO [karma]: Karma v0.12.35 server started at http://localhost:9876/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.8 (Linux 0.0.0)]: Connected on socket 7Dn7Ez1Reap7ch0Uzsb0 with id 44623726
PhantomJS 1.9.8 (Linux 0.0.0): Executed 2 of 2 SUCCESS (0.002 secs / 0.001 secs)

如何根据模式执行这个示例? official documentation没有给出模式匹配选项的用法示例。

我在 discussion of a pull request 中读到,grep 选项可以与“fit”和“fdescribe”结合使用。这在测试时有效。但是,在将 grep 与“fit”一起使用的情况下,grep 选项的模式参数的目的是什么? (如果能够有选择地执行测试而无需增加源代码,那就太好了!)

这是我项目中的其余文件供引用:

/path/to/single-test/karma.conf.js

module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine'],
files: ['*.spec.js'],
exclude: [],
preprocessors: {},
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: false,
browsers: ['PhantomJS'],
singleRun: true
});
};

/path/to/single-test/package.json

{
"name": "single-test",
"version": "1.0.0",
"description": "",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "MIT",
"devDependencies": {
"jasmine-core": "^2.3.4",
"karma": "^0.12.35",
"karma-jasmine": "^0.3.5",
"karma-phantomjs-launcher": "^0.2.0",
"phantomjs": "^1.9.17"
}
}

最佳答案

您必须启动 Karma 服务器,然后在 Karma 运行程序中指定 --grep 选项。 IE。大致如下:

karma start path/to/karma.conf.js

然后在另一个终端中:

karma run path/to/karma.conf.js -- --grep=still

在配置选项中设置 singleRun: false 非常重要。

关于command-line - 使用模式匹配在 Karma Jasmine 中选择性执行测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30629176/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com