ng test --config 正常工作需要哪些更改

what changes are necessary for ng test --config to work correctly

例如,我有这些文件:

***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 工作。

ng test 使用标准 karma.conf.js 可以很好地 运行 所有类似 *.spec.ts[=13= 的测试]

我一直在努力让它发挥作用: 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

我想 运行 在一个构建步骤中进行单元测试,并在另一个构建步骤中使用 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' 到 运行 单元测试,然后 运行 'copy test.testbed.ts test.ts' 在命令行上 (Windows),然后我可以 运行 'ng test' 再次 运行 测试台测试。很简单,我知道。我永远无法让 'ng test --config' 工作。