2017-04-05 107 views
0

我創建了unjenkins管道運行一個docker容器與nodeJs,karma和xvfb來運行單元測試。 測試成功通過,但該腳本從未與captureTimeout甚至停止:60000和singleRun:真正的因果報應配置jenkins管道運行後單元測試karma腳本不停止

如果我錯了

[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 沒有人可以幫助我,也可能是我不清楚,我的問題是當我運行我的詹金斯管道'運行單元測試'一步從未完成(比較截圖),我可以不檢查我的測試是否通過或不開展下一步。我需要幫助來了解在業力測試完成後,我可以如何使用命令行或其他方式來阻止它。

我嘗試用因果報應的配置(captureTimeout:60000,singleRun:真),使其但沒有發生

enter image description here

回答

1

我解決了問題,之前我Jenkinsfile,我用命令sh(」 ng測試')來運行測試,而不知道後臺發生了什麼。

所以我直接用善緣命令

sh ('./node_modules/karma/bin/karma start karma.conf.js') 
+0

您dhould接受你的答案,它的工作原理! – godzsa

+0

是的,我沒有這個選項:( –

2

我認爲業力是看更改這是開發機器不錯,但不適合CI構建。如果您想避免更改業務配置,則可以將--watch false作爲參數傳遞給ng test。 (雖然你有singleRun: true我不確定autoWatch: true是否具有更高的優先級。)

我建議你使用docker容器來執行完整的構建,而不是單個docker-run命令。 詹金斯提供了一個很好的抽象運行泊塢窗容器內的命令:

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' 
     } 
    ...