0

유닛 테스트를 실행하기 위해 nodeJs, karma 및 xvfb와 함께 도커 컨테이너를 실행하는 unjenkins 파이프 라인을 만들었습니다. 테스트 통과에 성공하지만 스크립트는 captureTimeout와도 멈추지 않을 : 60000 및 singleRun : 사실 카르마 구성 내가유닛 테스트 카르마 스크립트 실행 후 젠킨스 파이프 라인

[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 
     } 

카르마 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 아무도 나를 도울 수 없거나 명확하지 않을 수 있습니다. 내 문제는 제 젠킨스 파이프 라인을 실행하면 '실행 단위 테스트'단계가 완료되지 않았기 때문에 (cf 스크린 샷) 할 수 있습니다. 내 테스트가 통과하는지 또는 다음 단계를 시작하지 않을지 확인하지 마십시오. 나는 카르마 테스트가 끝난 후 커맨드 라인이나 다른 것을 어떻게 멈추게 할 수 있는지 알려주는 데 도움이 필요합니다.

내가 카르마 구성 (: 60000, singleRun : captureTimeout 참)로 만들려고 내 Jenkinsfile에 이전, 아무것도하지만, 내가 문제를 해결

enter image description here

답변

1

일어난, 난 '(명령 쉬 사용 ng test ') 백그라운드에서 어떤 일이 일어 났는지를 모르게 테스트를 실행합니다.

그래서 나는 그 업보가 CI 빌드를위한 개발 시스템에 대한 좋은하지만 좋은하지 않은 변화를보고 있었다 가정에 직접 카르마 명령

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

답변을 수락하면됩니다. – godzsa

+0

예, 완료되었습니다.이 옵션을 사용하지 않습니다. –

2

을 사용했다. 카르마 설정을 변경하지 않으려면 --watch false을 매개 변수로 ng test에 전달하면됩니다. (singleRun: true이 있더라도 autoWatch: true의 우선 순위가 더 높은지 확실하지 않습니다.)

단일 도커 실행 명령 대신 전체 도킹을 실행하려면 도커 컨테이너를 사용하는 것이 좋습니다. Jenkins는 도커 컨테이너에서 명령을 실행하기에 좋은 추상화를 제공합니다.

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' 
     } 
    ... 
관련 문제