gpt4 book ai didi

docker - 运行单元测试 karma 脚本后的 Jenkins 管道不停止

转载 作者:行者123 更新时间:2023-12-02 18:11:54 34 4
gpt4 key购买 nike

我创建了一个un jenkins管道,该管道运行带有nodeJs,karma和xvfb的docker容器以运行单元测试。
测试已成功通过,但脚本(即使在karma配置中使用captureTimeout:60000和singleRun:true也不停止)

我错了

[33m05 04 2017 16:01:54.227:WARN [karma]: [39mNo captured browser, open http://localhost:9876/
[32m05 04 2017 16:01:54.260:INFO [karma]: [39mKarma v1.3.0 server started at http://localhost:9876/
[32m05 04 2017 16:01:54.262:INFO [launcher]: [39mLaunching browser Chrome with unlimited concurrency
[32m05 04 2017 16:01:54.282:INFO [launcher]: [39mStarting browser Chrome
[32m05 04 2017 16:01:59.120:INFO [Chrome 57.0.2987 (Linux 0.0.0)]: [39mConnected on socket /#0Rk4DaJRdDHKCHNvAAAA with id 66659056
Chrome 57.0.2987 (Linux 0.0.0): Executed 0 of 2 SUCCESS (0 secs / 0 secs)
[1A[2KChrome 57.0.2987 (Linux 0.0.0): Executed 1 of 2 SUCCESS (0 secs / 0.99 secs)
[1A[2KLOG: 'MAIN'
Chrome 57.0.2987 (Linux 0.0.0): Executed 1 of 2 SUCCESS (0 secs / 0.99 secs)
[1A[2KChrome 57.0.2987 (Linux 0.0.0): Executed 2 of 2 SUCCESS (0 secs / 1.269 secs)
[1A[2KChrome 57.0.2987 (Linux 0.0.0): Executed 2 of 2 SUCCESS (1.319 secs / 1.269 secs)

管道:
        def karma = docker.image('trion/ng-cli-karma')
karma.pull()

try {

karma.run(' -u $(id -u) -v ${WORKSPACE}:/app trion/ng-cli-karma ')
karma.inside {
sh 'npm install'

try {
sh('ng test')
}catch(err) {
sh 'echo TEST FAILED'
step([$class: 'JUnitResultArchiver', testResults: 'report/*.xml', healthScaleFactor: 1.0])
throw err
}
sh 'echo DO SOMETHING ELSE AFTER TEST'
}
sh 'ls -al '
} catch(err) {
sh 'echo RUN DOCKER FAILED'
throw err
}

Karma conf:
module.exports = function (config) {
config.set({
mime: { 'text/x-typescript': ['ts','tsx'] },
basePath: '',
frameworks: ['jasmine', 'angular-cli'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-remap-istanbul'),
require('angular-cli/plugins/karma'),
require('karma-junit-reporter')
],
files: [
{ pattern: './src/test.ts', watched: false }
],
preprocessors: {
'./src/test.ts': ['angular-cli']
},
remapIstanbulReporter: {
reports: {
html: 'coverage',
lcovonly: './coverage/coverage.lcov'
}
},
angularCli: {
config: './angular-cli.json',
environment: 'dev'
},
reporters: config.angularCli && config.angularCli.codeCoverage
? ['progress', 'karma-remap-istanbul']
: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
customLaunchers: {
Chrome_without_sandbox: {
base: 'Chrome',
flags: ['--no-sandbox'] // with sandbox it fails under Docker
}
},
junitReporter: {
outputDir: './report', // results will be saved as $outputDir/$browserName.xml
outputFile: 'report.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
},
reporters: config.angularCli && config.angularCli.codeCoverage
? ['progress', 'karma-remap-istanbul', 'junit']
: ['progress', 'junit'],
captureTimeout: 60000,
singleRun: true
});
};

编辑日期:07/04/2017
没有人可以帮助我,或者可能我不清楚,我的问题是,当我运行我的 Jenkins 管道时,“运行单元测试”步骤从未完成(参见屏幕截图),并且我无法检查我的测试是否通过或无法启动下一步。我需要帮助,以了解在业力测试完成后如何使用命令行或其他方式停止它。

我尝试使用业力配置使其成功(captureTimeout:60000,singleRun:true),但是什么也没发生

enter image description here

最佳答案

我认为业力在监视变化,这对开发机器有利,但对CI构建不利。如果要避免更改业力配置,可以将--watch false作为参数传递给ng test。 (尽管您有singleRun: true,但我不确定autoWatch: true是否具有更高的优先级。)

我建议您使用docker容器而不是单个docker-run命令来执行完整的构建。
Jenkins提供了一个很好的抽象来在Docker容器内运行命令:

docker.image('trion/ng-cli-karma').inside {
stage ('load npm dependencies') {
echo 'Load npm dependencies'
sh 'npm install'
}
stage ('build') {
echo "building"
sh 'npm run build'
}
stage ('unit test') {
sh 'ng test --progress false --watch false'
echo 'generate test report **/dist/test-reports/*.xml'
junit allowEmptyResults: false, testResults: '**/test-results.xml'
echo 'end test & coverage'
}
...

关于docker - 运行单元测试 karma 脚本后的 Jenkins 管道不停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43236609/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com