作为一个例子,我有这些文件:
***folder blog component***
blog.component.ts
blog.component.spec.ts
blog.component.domSpec.ts
blog.component.html
blog.component.scss
***folder xyz component***
xyz.component.ts
xyz.component.spec.ts
xyz.component.domSpec.ts
xyz.component.html
xyz.component.scss
我希望能够使用不同的命令运行* .spec.ts和* .domSpec.ts测试等测试。我无法让 ng test --config 工作。
使用标准karma.conf.js的ng test 可以正常运行所有类似* .spec.ts的测试
我一直试图让这个工作: ng test --config karma.conf.dom.js 运行* .domSpec.ts等所有测试
在karma.conf.dom.js中我有这个:
module.exports = function (config) {
let _cliAppProcessors ={};
_cliAppProcessors[config.angularCli.app+'/test.dom.ts'] = ['@angular/cli'];
config.set({
files: [
{ pattern: './src/test.dom.ts', watched: false }
],
preprocessors: _cliAppProcessors,
然后在test.dom.ts我有这个:
const context = require.context('./', true, /\.domSpec\.ts$/);
当我运行 ng test --config karma.conf.dom.js 时,所有测试都会运行,而不仅仅是名为* .domSpec.ts的测试
答案 0 :(得分:0)
我想在一个构建步骤中运行单元测试,并在另一构建步骤中运行使用TestBed.compileComponents()的测试。我最后得到了两个文件:test.ts和test.testbed.ts。
这是文件中的唯一区别:
test.ts
const context = require.context('./', true, /\.spec\.ts$/);
test.testbed.ts
const context = require.context('./', true, /\.spec\.testbed\.ts$/);
我将运行'ng test'来运行单元测试,然后在命令行(Windows)上运行'copy test.testbed.ts test.ts',然后我可以再次运行'ng test'来运行测试台测试。很简单,我知道。我永远都无法让“ ng test --config”正常工作。