[英]Angular CLI / Run two categories of test with ng test
I have two different types of tests: 我有两种不同类型的测试:
I am trying to : 我在尝试着 :
ng test
command to only run .spec.ts test file ng test
命令中排除.func.spec.ts文件,仅运行.spec.ts测试文件 So my functional tests are not executed in the regular ng test
context and can be run separately. 因此,我的功能测试不会在常规
ng test
上下文中执行,而是可以单独运行。
In other words the solution can be... 换句话说,解决方案可以是...
npm run test
runs .spec.ts files npm run test
运行.spec.ts文件 npm run test:func
runs .func.spec.ts files npm run test:func
运行.func.spec.ts文件 I tried to create a different karma config file that excludes the files I don't want but it does not work. 我试图创建一个不同的业力配置文件,该文件排除了我不想要的文件,但是它不起作用。
Do you have any idea of how to perform this? 您对如何执行此操作有任何想法吗?
What you can do is to add a specific Karama configuration karma.func.conf.js 您可以做的是添加特定的Karama配置karma.func.conf.js
module.exports = function (config) {
config.set({
basePath: '',
files: ['src/app/**/**.func.ts'] // Not 100% sure about the pattern
frameworks: ['jasmine', '@angular/cli'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular/cli/plugins/karma')
],
client:{
clearContext: false
},
coverageIstanbulReporter: {
reports: [ 'html', 'lcovonly' ],
fixWebpackSourcePaths: true
},
angularCli: {
environment: 'dev' //you could change to use prod
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
});
};
Add to your package.json 添加到您的package.json
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build --prod",
"test": "ng test",
"test:func": "ng test --config karma.func.conf.js"
"lint": "ng lint",
"e2e": "ng e2e"
}
Maybe there is another solution that will avoid maintaining two configuration files. 也许还有另一种解决方案可以避免维护两个配置文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.