我尝试在Chrome中运行角度cli karma测试以获取本地主机链接。 但如果我运行npm run test它会打开chrome并立即关闭它。
karma.config.js:
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular/cli'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-phantomjs-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('karma-junit-reporter'),
require('@angular/cli/plugins/karma')
],
client: {
clearContext: false
},
files: [{
pattern: './src/test.ts',
watched: false
}],
preprocessors: {
'./src/test.ts': ['@angular/cli']
},
mime: {
'text/x-typescript': ['ts', 'tsx']
},
coverageIstanbulReporter: {
reports: ['html', 'lcovonly'],
fixWebpackSourcePaths: true
},
angularCli: {
config: './.angular-cli.json',
environment: 'dev'
},
reporters: config.angularCli && config.angularCli.codeCoverage
? ['progress', 'junit', 'coverage-istanbul']
: ['progress', 'junit', 'kjhtml'],
junitReporter: {
outputDir: 'test/target',
outputFile: 'surefire-reports/TEST-karma.xml',
suite: '',
useBrowserName: true
},
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: [
//'PhantomJS',
'Chrome'
],
singleRun: true
});
};
如何在chrome中运行npm run test。
我尝试使用我的所有测试来获取localhost,以便我可以在vs代码中调试它。
控制台输出:
10% building modules 2/2 modules 0 active10 02 2018 23:45:02.459:INFO [karma]: Karma v2.0.0 server started at http://0.0.0.0:9876/
10 02 2018 23:45:02.462:INFO [launcher]: Launching browser Chrome with unlimited concurrency
10 02 2018 23:45:02.468:INFO [launcher]: Starting browser Chrome 10 02 2018 23:45:12.031:INFO [Chrome 64.0.3282 (Windows 10.0.0)]: Connected on socket QFzL8LOUHJtjA405AAAA with id 83404421
Chrome 64.0.3282 (Windows 10.0.0): Executed 28 of 28 SUCCESS (0.976 secs / 0.951 secs)
答案 0 :(得分:0)
如果您的问题是这个=>“如果我运行npm run,请测试并打开chrome并立即将其关闭” 这是因为此=> singleRun = true 属实时,Karma捕获浏览器,运行测试并退出。 所以将其更改为
单次运行:否