@@ -41,7 +41,8 @@ const {
4141 DI_DEBUG_ERROR_FILE_SUFFIX ,
4242 DI_DEBUG_ERROR_SNAPSHOT_ID_SUFFIX ,
4343 DI_DEBUG_ERROR_LINE_SUFFIX ,
44- TEST_RETRY_REASON
44+ TEST_RETRY_REASON ,
45+ DD_TEST_IS_USER_PROVIDED_SERVICE
4546} = require ( '../../packages/dd-trace/src/plugins/util/test' )
4647const { DD_HOST_CPU_COUNT } = require ( '../../packages/dd-trace/src/plugins/util/env' )
4748const { ERROR_MESSAGE } = require ( '../../packages/dd-trace/src/constants' )
@@ -174,6 +175,7 @@ describe('mocha CommonJS', function () {
174175 tests . forEach ( testEvent => {
175176 assert . equal ( testEvent . meta [ TEST_SOURCE_FILE ] . startsWith ( 'ci-visibility/test/ci-visibility-test' ) , true )
176177 assert . exists ( testEvent . metrics [ TEST_SOURCE_START ] )
178+ assert . equal ( testEvent . meta [ DD_TEST_IS_USER_PROVIDED_SERVICE ] , 'false' )
177179 // Can read DD_TAGS
178180 assert . propertyVal ( testEvent . meta , 'test.customtag' , 'customvalue' )
179181 assert . propertyVal ( testEvent . meta , 'test.customtag2' , 'customvalue2' )
@@ -194,7 +196,8 @@ describe('mocha CommonJS', function () {
194196 env : {
195197 ...envVars ,
196198 DD_TAGS : 'test.customtag:customvalue,test.customtag2:customvalue2' ,
197- DD_TEST_SESSION_NAME : 'my-test-session'
199+ DD_TEST_SESSION_NAME : 'my-test-session' ,
200+ DD_SERVICE : undefined
198201 } ,
199202 stdio : 'pipe'
200203 } )
@@ -2520,4 +2523,38 @@ describe('mocha CommonJS', function () {
25202523 } )
25212524 } )
25222525 } )
2526+
2527+ it ( 'sets _dd.test.is_user_provided_service to true if DD_SERVICE is used' , ( done ) => {
2528+ const eventsPromise = receiver
2529+ . gatherPayloadsMaxTimeout ( ( { url } ) => url . endsWith ( '/api/v2/citestcycle' ) , ( payloads ) => {
2530+ const events = payloads . flatMap ( ( { payload } ) => payload . events )
2531+
2532+ const tests = events . filter ( event => event . type === 'test' ) . map ( event => event . content )
2533+ tests . forEach ( test => {
2534+ assert . equal ( test . meta [ DD_TEST_IS_USER_PROVIDED_SERVICE ] , 'true' )
2535+ } )
2536+ } )
2537+
2538+ childProcess = exec (
2539+ runTestsWithCoverageCommand ,
2540+ {
2541+ cwd,
2542+ env : {
2543+ ...getCiVisAgentlessConfig ( receiver . port ) ,
2544+ TESTS_TO_RUN : JSON . stringify ( [
2545+ './test/ci-visibility-test.js' ,
2546+ './test/ci-visibility-test-2.js'
2547+ ] ) ,
2548+ DD_SERVICE : 'my-service'
2549+ } ,
2550+ stdio : 'inherit'
2551+ }
2552+ )
2553+
2554+ childProcess . on ( 'exit' , ( ) => {
2555+ eventsPromise . then ( ( ) => {
2556+ done ( )
2557+ } ) . catch ( done )
2558+ } )
2559+ } )
25232560} )
0 commit comments