@@ -23,7 +23,9 @@ const {
2323 TEST_STATUS ,
2424 TEST_COMMAND ,
2525 TEST_MODULE ,
26+ TEST_FRAMEWORK ,
2627 TEST_FRAMEWORK_VERSION ,
28+ TEST_TYPE ,
2729 TEST_TOOLCHAIN ,
2830 TEST_CODE_COVERAGE_ENABLED ,
2931 TEST_ITR_SKIPPING_ENABLED ,
@@ -63,7 +65,7 @@ const {
6365 TEST_IS_MODIFIED
6466} = require ( '../../packages/dd-trace/src/plugins/util/test' )
6567const { DD_HOST_CPU_COUNT } = require ( '../../packages/dd-trace/src/plugins/util/env' )
66- const { ERROR_MESSAGE } = require ( '../../packages/dd-trace/src/constants' )
68+ const { ERROR_MESSAGE , ERROR_TYPE , COMPONENT } = require ( '../../packages/dd-trace/src/constants' )
6769const { DD_MAJOR , NODE_MAJOR } = require ( '../../version' )
6870
6971const RECEIVER_STOP_TIMEOUT = 20000
@@ -129,10 +131,10 @@ moduleTypes.forEach(({
129131 testCommand = testCommand ( version )
130132 }
131133
134+ // cypress-fail-fast is required as an incompatible plugin
132135 useSandbox ( [ `cypress@${ version } ` , 'cypress-fail-fast@7.1.0' ] , true )
133136
134137 before ( async ( ) => {
135- // cypress-fail-fast is required as an incompatible plugin
136138 cwd = sandboxCwd ( )
137139
138140 const { NODE_OPTIONS , ...restOfEnv } = process . env
@@ -176,6 +178,95 @@ moduleTypes.forEach(({
176178 }
177179 } )
178180
181+ it ( 'instruments tests with the APM protocol (old agents)' , async ( ) => {
182+ receiver . setInfoResponse ( { endpoints : [ ] } )
183+
184+ const receiverPromise = receiver
185+ . gatherPayloadsMaxTimeout ( ( { url } ) => url === '/v0.4/traces' , ( payloads ) => {
186+ const testSpans = payloads . flatMap ( ( { payload } ) => payload . flatMap ( trace => trace ) )
187+
188+ const passedTestSpan = testSpans . find ( span =>
189+ span . resource === 'cypress/e2e/basic-pass.js.basic pass suite can pass'
190+ )
191+ const failedTestSpan = testSpans . find ( span =>
192+ span . resource === 'cypress/e2e/basic-fail.js.basic fail suite can fail'
193+ )
194+
195+ assert . exists ( passedTestSpan , 'passed test span should exist' )
196+ assert . equal ( passedTestSpan . name , 'cypress.test' )
197+ assert . equal ( passedTestSpan . resource , 'cypress/e2e/basic-pass.js.basic pass suite can pass' )
198+ assert . equal ( passedTestSpan . type , 'test' )
199+ assert . equal ( passedTestSpan . meta [ TEST_STATUS ] , 'pass' )
200+ assert . equal ( passedTestSpan . meta [ TEST_NAME ] , 'basic pass suite can pass' )
201+ assert . equal ( passedTestSpan . meta [ TEST_SUITE ] , 'cypress/e2e/basic-pass.js' )
202+ assert . equal ( passedTestSpan . meta [ TEST_FRAMEWORK ] , 'cypress' )
203+ assert . equal ( passedTestSpan . meta [ TEST_TYPE ] , 'browser' )
204+ assert . exists ( passedTestSpan . meta [ TEST_SOURCE_FILE ] )
205+ assert . include ( passedTestSpan . meta [ TEST_SOURCE_FILE ] , 'cypress/e2e/basic-pass.js' )
206+ assert . exists ( passedTestSpan . meta [ TEST_FRAMEWORK_VERSION ] )
207+ assert . exists ( passedTestSpan . meta [ COMPONENT ] )
208+ assert . exists ( passedTestSpan . metrics [ TEST_SOURCE_START ] )
209+ assert . equal ( passedTestSpan . meta [ TEST_CODE_OWNERS ] , JSON . stringify ( [ '@datadog-dd-trace-js' ] ) )
210+ assert . equal ( passedTestSpan . meta . customTag , 'customValue' )
211+ assert . equal ( passedTestSpan . meta . addTagsBeforeEach , 'customBeforeEach' )
212+ assert . equal ( passedTestSpan . meta . addTagsAfterEach , 'customAfterEach' )
213+
214+ assert . exists ( failedTestSpan , 'failed test span should exist' )
215+ assert . equal ( failedTestSpan . name , 'cypress.test' )
216+ assert . equal ( failedTestSpan . resource , 'cypress/e2e/basic-fail.js.basic fail suite can fail' )
217+ assert . equal ( failedTestSpan . type , 'test' )
218+ assert . equal ( failedTestSpan . meta [ TEST_STATUS ] , 'fail' )
219+ assert . equal ( failedTestSpan . meta [ TEST_NAME ] , 'basic fail suite can fail' )
220+ assert . equal ( failedTestSpan . meta [ TEST_SUITE ] , 'cypress/e2e/basic-fail.js' )
221+ assert . equal ( failedTestSpan . meta [ TEST_FRAMEWORK ] , 'cypress' )
222+ assert . equal ( failedTestSpan . meta [ TEST_TYPE ] , 'browser' )
223+ assert . exists ( failedTestSpan . meta [ TEST_SOURCE_FILE ] )
224+ assert . include ( failedTestSpan . meta [ TEST_SOURCE_FILE ] , 'cypress/e2e/basic-fail.js' )
225+ assert . exists ( failedTestSpan . meta [ TEST_FRAMEWORK_VERSION ] )
226+ assert . exists ( failedTestSpan . meta [ COMPONENT ] )
227+ assert . exists ( failedTestSpan . meta [ ERROR_MESSAGE ] )
228+ assert . include ( failedTestSpan . meta [ ERROR_MESSAGE ] , 'expected' )
229+ assert . exists ( failedTestSpan . meta [ ERROR_TYPE ] )
230+ assert . exists ( failedTestSpan . metrics [ TEST_SOURCE_START ] )
231+ assert . equal ( passedTestSpan . meta [ TEST_CODE_OWNERS ] , JSON . stringify ( [ '@datadog-dd-trace-js' ] ) )
232+ assert . equal ( failedTestSpan . meta . customTag , 'customValue' )
233+ assert . equal ( failedTestSpan . meta . addTagsBeforeEach , 'customBeforeEach' )
234+ assert . equal ( failedTestSpan . meta . addTagsAfterEach , 'customAfterEach' )
235+ // Tags added after failure should not be present because test failed
236+ assert . notProperty ( failedTestSpan . meta , 'addTagsAfterFailure' )
237+ } , 60000 )
238+
239+ const {
240+ NODE_OPTIONS ,
241+ ...restEnvVars
242+ } = getCiVisEvpProxyConfig ( receiver . port )
243+
244+ const specToRun = 'cypress/e2e/basic-*.js'
245+
246+ // For Cypress 6.7.0, we need to override the --spec flag that's hardcoded in testCommand
247+ const command = version === '6.7.0'
248+ ? `./node_modules/.bin/cypress run --config-file cypress-config.json --spec "${ specToRun } "`
249+ : testCommand
250+
251+ childProcess = exec (
252+ command ,
253+ {
254+ cwd,
255+ env : {
256+ ...restEnvVars ,
257+ CYPRESS_BASE_URL : `http://localhost:${ webAppPort } ` ,
258+ SPEC_PATTERN : specToRun
259+ } ,
260+ stdio : 'pipe'
261+ }
262+ )
263+
264+ await Promise . all ( [
265+ once ( childProcess , 'exit' ) ,
266+ receiverPromise
267+ ] )
268+ } )
269+
179270 if ( version === '6.7.0' ) {
180271 // to be removed when we drop support for cypress@6.7.0
181272 it ( 'logs a warning if using a deprecated version of cypress' , async ( ) => {
0 commit comments