我有一个包含要进行单元测试的打字稿文件的文件夹。该文件夹位于应用程序src文件夹之外。 运行测试时,在Jasmine的代码覆盖率报告中看不到src文件夹之外的文件夹和文件。
文件夹结构如下:
ang/apps/app-name/src/
ang/test-folder
在测试文件夹中,我具有带有.spec文件的组件。 测试本身正在运行,但是结果未显示在“代码覆盖率”报告中。
我只能看到ang/apps/app-name/src/
ang/apps/app-name/src
中的我的test.ts文件:
import 'zone.js/dist/zone-testing';
import { getTestBed } from '@angular/core/testing';
import { BrowserDynamicTestingModule,platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
declare const require: any;
// First,initialize the Angular testing environment.
getTestBed().initTestEnvironment(BrowserDynamicTestingModule,platformBrowserDynamicTesting());
// Then we find all the tests.
const context = require.context('test-folder',true,/\.spec\.ts$/);
// And load the modules.
context.keys().map(context);
const context1 = require.context('./',/\.spec\.ts$/);
context1.keys().map(context1);
ang/apps/app-name/src/
内的karma.conf文件的一部分
coverageIstanbulReporter: {
reports: ['html','lcovonly','text-summary','json'],dir: `test/reports/coverage`,fixWebpackSourcePaths: true,thresholds: {
emitWarning: true,// set to `true` to not fail the test command when thresholds are not met
// thresholds for all files
global: {
statements: 80,lines: 80,branches: 80,functions: 80
},// thresholds per file
each: {
statements: 50,lines: 50,branches: 50,functions: 50
}
},'report-config': { html: { subdir: 'html' } },},coverageReporter: {
dir: `test/reports/coverage`,subdir: (browser) => {
return browser.toLowerCase().split(/[ /-]/)[0];
},reporters: [
{ type: 'html' },{ type: 'text-summary' },{ type: 'lcovonly' }
],includeAllSources: true,instrumenterOptions: {
istanbul: { esModules: true }
},//Coverage threshold colors:
//- The first number is the threshold between Red and Yellow.
//- The second number is the threshold between Yellow and Green.
watermarks: {
statements: [90,95],lines: [90,functions: [90,branches:[90,95]
},
如何将测试文件夹中的文件包括/添加到Jasmine Code Coverage报告中?