我正在使用Chrome运行我的角7单元测试项目和Karma
它似乎不稳定,因为当运行几十个规范时,在没有完成所有测试的情况下随机地破坏了任何测试的。
我不知道这是否是记忆的问题,铬本身的因果报应。
My karma.conf :
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html
var process = require('process');
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
},
mime: {
'text/x-typescript': ['ts','tsx']
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, 'coverage'),
reports: [ 'html', 'lcovonly' ],
fixWebpackSourcePaths: true
},
reporters: config.angularCli && config.angularCli.codeCoverage
? ['progress', 'coverage-istanbul']
: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
browserDisconnectTimeout: 60000,
browserDisconnectTolerance: 3,
browserNoActivityTimeout: 60000,
flags: [
'--disable-web-security',
'--disable-gpu',
'--no-sandbox'
],
singleRun: true,
concurrency: Infinity
});
};我正在使用这些测试包:
"jasmine-core": "^3.3.0",
"jasmine-spec-reporter": "^4.2.1",
"karma": "^4.0.0",
"karma-chrome-launcher": "^2.2.0",
"karma-cli": "^2.0.0",
"karma-coverage-istanbul-reporter": "2.0.4",
"karma-jasmine": "^2.0.1",
"karma-jasmine-html-reporter": "^1.4.0",建议??
发布于 2019-05-28 09:37:37
为它添加一个客户午餐,它应该可以解决问题。
browsers: ['ChromeHeadlessNoSandbox'],
customLaunchers: {
ChromeHeadlessNoSandbox: {
base: 'ChromeHeadless',
flags: ['--no-sandbox']
}
},下面是一个使用ChromiumHeadless的工作配置示例
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-junit-reporter'),
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'),
reports: ['html', 'lcovonly', 'text-summary'],
fixWebpackSourcePaths: true
},
reporters: ['junit','progress', 'kjhtml'],
junitReporter: {
outputDir: require('path').join(__dirname, '../coverage'), // results will be saved as $outputDir/$browserName.xml
outputFile: 'junit.xml', // if included, results will be saved as $outputDir/$browserName/$outputFile
suite: '', // suite will become the package name attribute in xml testsuite element
useBrowserName: false, // add browser name to report and classes names
nameFormatter: undefined, // function (browser, result) to customize the name attribute in xml testcase element
classNameFormatter: undefined, // function (browser, result) to customize the classname attribute in xml testcase element
properties: {}, // key value pair of properties to add to the <properties> section of the report
xmlVersion: null // use '1' if reporting to be per SonarQube 6.2 XML format
},
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
singleRun: false,
browsers: ['Chrome_no_sandbox'],
customLaunchers: {
Chrome_no_sandbox: {
base: 'ChromiumHeadless',
flags: ['--no-sandbox']
}
}
});
};发布于 2019-09-05 11:19:39
就我而言,我通过以下方式解决了这一问题:
yarn add -D puppeteer karma-chrome-launcher
karma.conf.js ()中用这种软木塞的方式将它们连接起来:process.env.CHROME_BIN = require('puppeteer').executablePath();
module.exports = config => {
config.set({
// other config options...
// custom ChromeHeadless launcher
browsers: ['ChromeHeadless_without_security'],
customLaunchers: {
ChromeHeadless_without_security: {
base: 'ChromeHeadless',
flags: ['--disable-web-security', '--disable-site-isolation-trials']
}
}
});
};发布于 2022-11-09 23:15:30
在为一个小型web应用程序运行测试时,我遇到了同样的问题。我有Angular(14.2.9)和NodeJS(19.0.1)关于RHEL(8.7)。这是在一个Jenkins代理上完成的,它是一个EC2实例,配置为让主用户远程登录并完成这项工作。
我有一个Jenkins管道设置:
非常标准的东西,没什么不寻常的。然而,当最后阶段在Jenkins管道上完成时,它不会退出。日志显示测试是成功的,但它不会退出和结束。
09 11 2022 22:34:06.555:INFO [Chrome Headless 109.0.5396.2 (Linux x86_64)]: Connected on socket xm4ZTAjwGMOgGuePAAAB with id 1783772
Chrome Headless 109.0.5396.2 (Linux x86_64): Executed 0 of 4 SUCCESS (0 secs / 0 secs)
[1A[2KChrome Headless 109.0.5396.2 (Linux x86_64): Executed 1 of 4 SUCCESS (0 secs / 0.117 secs)
[1A[2KChrome Headless 109.0.5396.2 (Linux x86_64): Executed 2 of 4 SUCCESS (0 secs / 0.143 secs)
[1A[2KChrome Headless 109.0.5396.2 (Linux x86_64): Executed 3 of 4 SUCCESS (0 secs / 0.153 secs)
[1A[2KChrome Headless 109.0.5396.2 (Linux x86_64): Executed 4 of 4 SUCCESS (0 secs / 0.16 secs)
[1A[2KChrome Headless 109.0.5396.2 (Linux x86_64): Executed 4 of 4 SUCCESS (0.188 secs / 0.16 secs)
TOTAL: 4 SUCCESS在读取karma.conf.js文件时,我看到了字段singleRun,它被设置为false。
这似乎很奇怪,而且直觉上没有道理,所以我把它改成了true。当我重新运行管道时,测试完成并退出,没有问题。
我做了一些进一步的研究,并发现here,如果没有这个设置,那么您将被期望手动启动业力-客户端。
https://stackoverflow.com/questions/56339049
复制相似问题