在尝试使用命令ng测试运行测试并获得错误“未找到规范”和Chrome 73.0.3683(Linux 0.0.0)之后,将角度从5更新为7:执行0 0 ERROR(0.029秒/ 0秒)。
任何人都可以帮我解决这个问题吗?我尝试了所有可能的方案来解决这个问题。实际上,当我运行测试时,它应该找到我的spec.ts文件来运行我的脚本,但它没有发生
我的cli版本:
Angular CLI:7.3.9
Node: 8.16.0
OS: linux x64
Angular: 7.2.15
Package Version
@angular-devkit/architect 0.12.4
@angular-devkit/build-angular 0.12.4
@angular-devkit/build-optimizer 0.12.4
@angular-devkit/build-webpack 0.12.4
@angular-devkit/core 7.2.4
@angular-devkit/schematics 7.3.9
@angular/cdk 7.3.1
@angular/cli 7.3.9
@angular/flex-layout 7.0.0-beta.23
@angular/material 7.3.1
@ngtools/webpack 7.2.4
@schematics/angular 7.3.9
@schematics/update 0.13.9
rxjs 6.5.2
typescript 3.2.4
webpack 4.28.4
my karma.conf.js:
_ _ ____ _ ___
const tags = process.argv.filter(arg => {
return (arg.endsWith('.component') || arg.endsWith('.service'))
})
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-spec-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma'),
],
mime: {
'text/x-typescript': ['ts', 'tsx']
},
client: {
args: [tags],
clearContext: false // leave Jasmine Spec Runner output visible in browser!
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, 'coverage'),
reports: ['html', 'lcovonly'],
fixWebpackSourcePaths: true
},
// reporters: ['progress', 'kjhtml', 'spec'],
reporters: ['kjhtml', 'spec'],
port: 9876,
colors: true,
logLevel: config.LOG_DEBUG,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
captureTimeout: 240000,
browserDisconnectTimeout: 10000,
browserDisconnectTolerance: 3,
browserNoActivityTimeout: 60000,
});
};
**PS: removed files and the preprocessor configs from the karma.conf.js completely. This is all defined in the angular.json and should be handled automatically by the @anguler-devkit karma plugin**
test.ts:
_ _ ____ _ ___
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
import 'zone.js/dist/zone-testing';
import { getTestBed } from '@angular/core/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';
declare var __karma__: any
declare var require: any
const tags = __karma__.config.args[0]
// Prevent Karma from running prematurely.
__karma__.loaded = function () { }
getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting()
)
let filterRegex
if (tags.length) {
const strTags = tags.join('|')
filterRegex = new RegExp(`(${strTags})\\.spec\\.ts$`) // SPECIFIC TEST SUITES AS PASSED TO ... npm test filter-list.component filter-list.service
} else {
filterRegex = /\.spec\.ts$/ // ALL TEST SUITES
}
// filterRegex = /(filter-list.component|filter-list.service)\.spec\.ts$/ // OR YOU CAN UNCOMMENT AND EDIT THIS LINE
const context = require.context('./', true, /\.spec\.ts$/)
const specFiles = context.keys().filter(path => filterRegex.test(path))
if (specFiles.length) {
specFiles.map(context)
__karma__.start()
} else {
console.warn(`Could not find any test suites for ${tags.join(', ')}`)
}
i expect the pass my all test which was working when i was using angular 5 but now i am getting "no spec found"
通过迁移,您应该检查旧应用程序的文件,并将它们与ng new
的新创建的角度7应用程序进行比较。
这是由于错误的配置导致的100%,这可能是由不正确的文件名或不正确的配置架构引起的。没有所有tsconfig.json
和angular.json
文件,真的无法帮助更多。