@@ -73,6 +73,8 @@ const {
7373 TEST_SESSION_ID ,
7474 TEST_MODULE ,
7575 TEST_COMMAND ,
76+ GIT_COMMIT_SHA ,
77+ GIT_REPOSITORY_URL
7678} = require ( '../../packages/dd-trace/src/plugins/util/test' )
7779const { DD_HOST_CPU_COUNT } = require ( '../../packages/dd-trace/src/plugins/util/env' )
7880const { ERROR_MESSAGE , ERROR_TYPE , ORIGIN_KEY , COMPONENT } = require ( '../../packages/dd-trace/src/constants' )
@@ -5585,4 +5587,83 @@ describe(`jest@${JEST_VERSION} commonJS`, () => {
55855587 assert . doesNotMatch ( testOutput , / C a n n o t f i n d m o d u l e / )
55865588 assert . match ( testOutput , / 6 p a s s e d / )
55875589 } )
5590+
5591+ context ( 'coverage report upload' , ( ) => {
5592+ const gitCommitSha = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
5593+ const gitRepositoryUrl = 'https://github.com/datadog/test-repo.git'
5594+
5595+ it ( 'uploads coverage report when coverage_report_upload_enabled is true' , async ( ) => {
5596+ receiver . setSettings ( {
5597+ coverage_report_upload_enabled : true
5598+ } )
5599+
5600+ const coverageReportPromise = receiver
5601+ . gatherPayloadsMaxTimeout ( ( { url } ) => url === '/api/v2/cicovreprt' , ( payloads ) => {
5602+ assert . strictEqual ( payloads . length , 1 )
5603+
5604+ const coverageReport = payloads [ 0 ]
5605+
5606+ assert . ok ( coverageReport . headers [ 'content-type' ] . includes ( 'multipart/form-data' ) )
5607+
5608+ assert . strictEqual ( coverageReport . coverageFile . name , 'coverage' )
5609+ assert . ok ( coverageReport . coverageFile . content . includes ( 'SF:' ) ) // LCOV format
5610+
5611+ assert . strictEqual ( coverageReport . eventFile . name , 'event' )
5612+ assert . strictEqual ( coverageReport . eventFile . content . type , 'coverage_report' )
5613+ assert . strictEqual ( coverageReport . eventFile . content . format , 'lcov' )
5614+ assert . strictEqual ( coverageReport . eventFile . content [ GIT_COMMIT_SHA ] , gitCommitSha )
5615+ assert . strictEqual ( coverageReport . eventFile . content [ GIT_REPOSITORY_URL ] , gitRepositoryUrl )
5616+ } )
5617+
5618+ childProcess = exec (
5619+ runTestsCommand ,
5620+ {
5621+ cwd,
5622+ env : {
5623+ ...getCiVisAgentlessConfig ( receiver . port ) ,
5624+ ENABLE_CODE_COVERAGE : 'true' ,
5625+ COVERAGE_REPORTERS : 'lcov' ,
5626+ COLLECT_COVERAGE_FROM : 'ci-visibility/test/*.js' ,
5627+ DD_GIT_COMMIT_SHA : gitCommitSha ,
5628+ DD_GIT_REPOSITORY_URL : gitRepositoryUrl
5629+ }
5630+ }
5631+ )
5632+
5633+ await Promise . all ( [
5634+ coverageReportPromise ,
5635+ once ( childProcess , 'exit' )
5636+ ] )
5637+ } )
5638+
5639+ it ( 'does not upload coverage report when coverage_report_upload_enabled is false' , async ( ) => {
5640+ receiver . setSettings ( {
5641+ coverage_report_upload_enabled : false
5642+ } )
5643+
5644+ let coverageReportUploaded = false
5645+ receiver . assertPayloadReceived ( ( ) => {
5646+ coverageReportUploaded = true
5647+ } , ( { url } ) => url === '/api/v2/cicovreprt' )
5648+
5649+ childProcess = exec (
5650+ runTestsCommand ,
5651+ {
5652+ cwd,
5653+ env : {
5654+ ...getCiVisAgentlessConfig ( receiver . port ) ,
5655+ ENABLE_CODE_COVERAGE : 'true' ,
5656+ COVERAGE_REPORTERS : 'lcov' ,
5657+ COLLECT_COVERAGE_FROM : 'ci-visibility/test/*.js' ,
5658+ DD_GIT_COMMIT_SHA : gitCommitSha ,
5659+ DD_GIT_REPOSITORY_URL : gitRepositoryUrl
5660+ }
5661+ }
5662+ )
5663+
5664+ await once ( childProcess , 'exit' )
5665+
5666+ assert . strictEqual ( coverageReportUploaded , false , 'coverage report should not be uploaded' )
5667+ } )
5668+ } )
55885669} )
0 commit comments