@@ -41,7 +41,8 @@ const {
41
41
DI_DEBUG_ERROR_FILE_SUFFIX ,
42
42
DI_DEBUG_ERROR_SNAPSHOT_ID_SUFFIX ,
43
43
DI_DEBUG_ERROR_LINE_SUFFIX ,
44
- TEST_RETRY_REASON
44
+ TEST_RETRY_REASON ,
45
+ DD_TEST_IS_USER_PROVIDED_SERVICE
45
46
} = require ( '../../packages/dd-trace/src/plugins/util/test' )
46
47
const { DD_HOST_CPU_COUNT } = require ( '../../packages/dd-trace/src/plugins/util/env' )
47
48
const { ERROR_MESSAGE } = require ( '../../packages/dd-trace/src/constants' )
@@ -174,6 +175,7 @@ describe('mocha CommonJS', function () {
174
175
tests . forEach ( testEvent => {
175
176
assert . equal ( testEvent . meta [ TEST_SOURCE_FILE ] . startsWith ( 'ci-visibility/test/ci-visibility-test' ) , true )
176
177
assert . exists ( testEvent . metrics [ TEST_SOURCE_START ] )
178
+ assert . equal ( testEvent . meta [ DD_TEST_IS_USER_PROVIDED_SERVICE ] , 'false' )
177
179
// Can read DD_TAGS
178
180
assert . propertyVal ( testEvent . meta , 'test.customtag' , 'customvalue' )
179
181
assert . propertyVal ( testEvent . meta , 'test.customtag2' , 'customvalue2' )
@@ -194,7 +196,8 @@ describe('mocha CommonJS', function () {
194
196
env : {
195
197
...envVars ,
196
198
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
198
201
} ,
199
202
stdio : 'pipe'
200
203
} )
@@ -2520,4 +2523,38 @@ describe('mocha CommonJS', function () {
2520
2523
} )
2521
2524
} )
2522
2525
} )
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
+ } )
2523
2560
} )
0 commit comments