嗨,我有大约603个用茉莉花写的测试用例。我正在尝试使用ng test命令运行这些测试用例。但是每次浏览器在390个测试用例断开连接并再次重新启动浏览器并从编号1重新运行测试用例时,消息如下:HeadlessChrome 0.0.0 (Windows 7 0.0.0): Executed 390 of 603 (14 FAILED) (0 secs / 37 mins 55.402 secs)HeadlessChrome 0.0.0 (Windows 7 0.0.0) ERROR DisconnectedHeadlessChrome 0.0.0 (Windows 7 0.0.0): Executed 390 of 603 (14 FAILED) DISCONNECTED (38 mins 45.052 secs / 37 mins 55.402 secs)HeadlessChrome 0.0.0 (Windows 7 0.0.0) ERRORHeadlessChrome 0.0.0 (Windows 7 0.0.0): Executed 390 of 603 (14 FAILED) DISCONNECTED (38 mins 45.052 secs / 37 mins 55.402 secs)26 08 2019 14:57:29.558:INFO [karma]: Restarting HeadlessChrome 0.0.0 (Windows 7 0.0.0) (1 of 5 attempts)26 08 2019 14:57:33.062:INFO [HeadlessChrome 0.0.0 (Windows 7 0.0.0)]: Connected on socket CF0U7yNUkencldeeAAAB with id 69964403
Karma.conf文件
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-phantomjs-launcher'),
require('karma-chrome-launcher'),
require('karma-junit-reporter'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
clearContext: false
},
coverageIstanbulReporter: {
reports: ['html', 'lcovonly'],
fixWebpackSourcePaths: true
},
angularCli: {
environment: 'dev'
},
mime: {
'text/x-typescript': ['ts']
},
reporters: ['progress', 'kjhtml', 'junit'],
junitReporter: {
outputFile: './target/surefire-reports/TEST-com.ericsson.bss.rm.cpm.cpc.xml',
suite: 'com.ericsson.bss.rm.cpm.cpc',
useBrowserName: false
},
port: 9876,
failOnEmptyTestSuite: false,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: false,
mime: { 'text/x-typescript': ['ts', 'tsx'] },
browsers: ['ChromeHeadless'],
singleRun: true,
captureTimeout: 800000,
browserDisconnectTimeout: 2000,
browserDisconnectTolerance: 5,
browserNoActivityTimeout: 800000,
webpack: { node: { fs: 'empty' } }
});
};
Package.json文件:-
"devDependencies": {
"@angular/cli": "^8.2.0",
"@ericsson/cus-ui": "3.0.0",
"@types/jasmine": "2.8.8",
"@types/jasminewd2": "~2.0.2",
"@types/node": "~12.0.8",
"codelyzer": "^5.0.1",
"jasmine-core": "~2.8.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~2.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"karma-junit-reporter": "^1.2.0",
"karma-phantomjs-launcher": "^1.0.4",
"karma-remap-istanbul": "0.6.0",
"karma-spec-reporter": "0.0.30",
"protractor": "5.4.2",
"ts-node": "~8.2.0",
"tslint": "~5.17.0",
"typescript": "~3.4.3"
}
最佳答案
我遇到了与您完全相同的问题,并通过为它定义了一个自定义启动器来设法解决了这个问题:
browsers: ["Chrome-headless"],
customLaunchers: {
"Chrome-headless": {
base: 'Chrome',
flags: ['--headless', '--remote-debugging-port=9222', '--no-sandbox']
}
}
或者,您也可以通过在自定义启动器中添加以下附加标志来进行尝试:
--js-flags="--max_old_space_size=4096"
关于javascript - 浏览器在执行 karma 测试用例时断开连接,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57655499/