因此,我的 Angular 10 项目中有一个默认的和一个自定义的 spec.ts 文件,但 Karma 没有检测到它们可以运行。知道为什么会发生这种情况吗?
我的 Karma 配置文件(实际上未更改):
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, './coverage/korrespo-portal'),
reports: ['html', 'lcovonly', 'text-summary'],
fixWebpackSourcePaths: true
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
restartOnFileChange: true
});
};
我的控制台输出:
Chrome 88.0.4324.104 (Windows 10): Executed 0 of 0 SUCCESS (0.013 secs / 0 secs)
TOTAL: 0 SUCCESS
在 Karma UI 中显示:
Incomplete: No specs found, , randomized with seed 27463
我的
ng version
输出:
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 10.1.7
Node: 12.13.1
OS: win32 x64
Angular: 10.2.0
... animations, common, compiler, compiler-cli, core, forms
... language-service, localize, platform-browser
... platform-browser-dynamic, router
Ivy Workspace: Yes
Package Version
------------------------------------------------------------
@angular-devkit/architect 0.1002.0
@angular-devkit/build-angular 0.1002.0
@angular-devkit/core 10.2.0
@angular-devkit/schematics 10.1.7
@angular/cdk 10.2.5
@angular/cli 10.1.7
@angular/material 10.2.5
@angular/material-moment-adapter 10.2.5
@schematics/angular 10.1.7
@schematics/update 0.1001.7
rxjs 6.6.3
typescript 3.9.7
我正在运行 Angular 10(如上所示)和 TypeScript 3.9.7(如上所示)...
应该有一个名为
test.ts
的文件,其中包含如下行:
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().map(context);
这些是负责查找测试的线路。也许您的测试不位于
./
。
我注意到将 Angular 版本从 v11 升级到 v12 后,在我的项目中找不到任何测试。
在我的
tests.ts
文件中我有这个:
const context = require.context('./', true, /\.spec\.ts$/);
更改为以下内容后现在可以使用:
const context = require.context('src/', true, /\.spec\.ts$/);