-
Notifications
You must be signed in to change notification settings - Fork 328
/
Copy pathcucumber.spec.js
1913 lines (1680 loc) · 78.1 KB
/
cucumber.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
'use strict'
const { exec } = require('child_process')
const getPort = require('get-port')
const semver = require('semver')
const { assert } = require('chai')
const {
createSandbox,
getCiVisAgentlessConfig,
getCiVisEvpProxyConfig
} = require('../helpers')
const { FakeCiVisIntake } = require('../ci-visibility-intake')
const {
TEST_STATUS,
TEST_SKIPPED_BY_ITR,
TEST_COMMAND,
TEST_MODULE,
TEST_TOOLCHAIN,
TEST_CODE_COVERAGE_ENABLED,
TEST_ITR_SKIPPING_ENABLED,
TEST_ITR_TESTS_SKIPPED,
TEST_ITR_SKIPPING_TYPE,
TEST_ITR_SKIPPING_COUNT,
TEST_CODE_COVERAGE_LINES_PCT,
TEST_ITR_FORCED_RUN,
TEST_ITR_UNSKIPPABLE,
TEST_SOURCE_FILE,
TEST_SOURCE_START,
TEST_EARLY_FLAKE_ENABLED,
TEST_EARLY_FLAKE_ABORT_REASON,
TEST_IS_NEW,
TEST_IS_RETRY,
TEST_NAME,
CUCUMBER_IS_PARALLEL,
TEST_SUITE,
TEST_CODE_OWNERS,
TEST_SESSION_NAME,
TEST_LEVEL_EVENT_TYPES,
DI_ERROR_DEBUG_INFO_CAPTURED,
DI_DEBUG_ERROR_PREFIX,
DI_DEBUG_ERROR_FILE_SUFFIX,
DI_DEBUG_ERROR_SNAPSHOT_ID_SUFFIX,
DI_DEBUG_ERROR_LINE_SUFFIX
} = require('../../packages/dd-trace/src/plugins/util/test')
const { DD_HOST_CPU_COUNT } = require('../../packages/dd-trace/src/plugins/util/env')
const isOldNode = semver.satisfies(process.version, '<=16')
const versions = ['7.0.0', isOldNode ? '9' : 'latest']
const runTestsCommand = './node_modules/.bin/cucumber-js ci-visibility/features/*.feature'
const runTestsWithCoverageCommand = './node_modules/nyc/bin/nyc.js -r=text-summary ' +
'node ./node_modules/.bin/cucumber-js ci-visibility/features/*.feature'
const parallelModeCommand = './node_modules/.bin/cucumber-js ci-visibility/features/*.feature --parallel 2'
const featuresPath = 'ci-visibility/features/'
const fileExtension = 'js'
versions.forEach(version => {
// TODO: add esm tests
describe(`cucumber@${version} commonJS`, () => {
let sandbox, cwd, receiver, childProcess, testOutput
before(async function () {
// add an explicit timeout to make tests less flaky
this.timeout(50000)
sandbox = await createSandbox([`@cucumber/cucumber@${version}`, 'assert', 'nyc'], true)
cwd = sandbox.folder
})
after(async function () {
// add an explicit timeout to make tests less flaky
this.timeout(50000)
await sandbox.remove()
})
beforeEach(async function () {
const port = await getPort()
receiver = await new FakeCiVisIntake(port).start()
})
afterEach(async () => {
testOutput = ''
childProcess.kill()
await receiver.stop()
})
const reportMethods = ['agentless', 'evp proxy']
reportMethods.forEach((reportMethod) => {
context(`reporting via ${reportMethod}`, () => {
let envVars, isAgentless, logsEndpoint
beforeEach(() => {
isAgentless = reportMethod === 'agentless'
envVars = isAgentless ? getCiVisAgentlessConfig(receiver.port) : getCiVisEvpProxyConfig(receiver.port)
logsEndpoint = isAgentless ? '/api/v2/logs' : '/debugger/v1/input'
})
const runModes = ['serial']
if (version !== '7.0.0') { // only on latest or 9 if node is old
runModes.push('parallel')
}
runModes.forEach((runMode) => {
it(`(${runMode}) can run and report tests`, (done) => {
const runCommand = runMode === 'parallel' ? parallelModeCommand : runTestsCommand
const receiverPromise = receiver
.gatherPayloadsMaxTimeout(({ url }) => url.endsWith('/api/v2/citestcycle'), payloads => {
const metadataDicts = payloads.flatMap(({ payload }) => payload.metadata)
metadataDicts.forEach(metadata => {
for (const testLevel of TEST_LEVEL_EVENT_TYPES) {
assert.equal(metadata[testLevel][TEST_SESSION_NAME], 'my-test-session')
}
})
const events = payloads.flatMap(({ payload }) => payload.events)
const testSessionEvent = events.find(event => event.type === 'test_session_end')
const testModuleEvent = events.find(event => event.type === 'test_module_end')
const testSuiteEvents = events.filter(event => event.type === 'test_suite_end')
const testEvents = events.filter(event => event.type === 'test')
const stepEvents = events.filter(event => event.type === 'span')
const { content: testSessionEventContent } = testSessionEvent
const { content: testModuleEventContent } = testModuleEvent
if (runMode === 'parallel') {
assert.equal(testSessionEventContent.meta[CUCUMBER_IS_PARALLEL], 'true')
}
assert.exists(testSessionEventContent.test_session_id)
assert.exists(testSessionEventContent.meta[TEST_COMMAND])
assert.exists(testSessionEventContent.meta[TEST_TOOLCHAIN])
assert.equal(testSessionEventContent.resource.startsWith('test_session.'), true)
assert.equal(testSessionEventContent.meta[TEST_STATUS], 'fail')
assert.exists(testModuleEventContent.test_session_id)
assert.exists(testModuleEventContent.test_module_id)
assert.exists(testModuleEventContent.meta[TEST_COMMAND])
assert.exists(testModuleEventContent.meta[TEST_MODULE])
assert.equal(testModuleEventContent.resource.startsWith('test_module.'), true)
assert.equal(testModuleEventContent.meta[TEST_STATUS], 'fail')
assert.equal(
testModuleEventContent.test_session_id.toString(10),
testSessionEventContent.test_session_id.toString(10)
)
assert.includeMembers(testSuiteEvents.map(suite => suite.content.resource), [
`test_suite.${featuresPath}farewell.feature`,
`test_suite.${featuresPath}greetings.feature`
])
assert.includeMembers(testSuiteEvents.map(suite => suite.content.meta[TEST_STATUS]), [
'pass',
'fail'
])
testSuiteEvents.forEach(({
content: {
meta,
metrics,
test_suite_id: testSuiteId,
test_module_id: testModuleId,
test_session_id: testSessionId
}
}) => {
assert.exists(meta[TEST_COMMAND])
assert.exists(meta[TEST_MODULE])
assert.exists(testSuiteId)
assert.equal(testModuleId.toString(10), testModuleEventContent.test_module_id.toString(10))
assert.equal(testSessionId.toString(10), testSessionEventContent.test_session_id.toString(10))
assert.isTrue(meta[TEST_SOURCE_FILE].startsWith(featuresPath))
assert.equal(metrics[TEST_SOURCE_START], 1)
assert.exists(metrics[DD_HOST_CPU_COUNT])
})
assert.includeMembers(testEvents.map(test => test.content.resource), [
`${featuresPath}farewell.feature.Say farewell`,
`${featuresPath}greetings.feature.Say greetings`,
`${featuresPath}greetings.feature.Say yeah`,
`${featuresPath}greetings.feature.Say yo`,
`${featuresPath}greetings.feature.Say skip`
])
assert.includeMembers(testEvents.map(test => test.content.meta[TEST_STATUS]), [
'pass',
'pass',
'pass',
'fail',
'skip'
])
testEvents.forEach(({
content: {
meta,
metrics,
test_suite_id: testSuiteId,
test_module_id: testModuleId,
test_session_id: testSessionId
}
}) => {
assert.exists(meta[TEST_COMMAND])
assert.exists(meta[TEST_MODULE])
assert.exists(testSuiteId)
assert.equal(testModuleId.toString(10), testModuleEventContent.test_module_id.toString(10))
assert.equal(testSessionId.toString(10), testSessionEventContent.test_session_id.toString(10))
assert.equal(meta[TEST_SOURCE_FILE].startsWith('ci-visibility/features'), true)
// Can read DD_TAGS
assert.propertyVal(meta, 'test.customtag', 'customvalue')
assert.propertyVal(meta, 'test.customtag2', 'customvalue2')
if (runMode === 'parallel') {
assert.propertyVal(meta, CUCUMBER_IS_PARALLEL, 'true')
}
assert.exists(metrics[DD_HOST_CPU_COUNT])
})
stepEvents.forEach(stepEvent => {
assert.equal(stepEvent.content.name, 'cucumber.step')
assert.property(stepEvent.content.meta, 'cucumber.step')
})
}, 5000)
childProcess = exec(
runCommand,
{
cwd,
env: {
...envVars,
DD_TAGS: 'test.customtag:customvalue,test.customtag2:customvalue2',
DD_TEST_SESSION_NAME: 'my-test-session'
},
stdio: 'pipe'
}
)
childProcess.on('exit', () => {
receiverPromise.then(() => done()).catch(done)
})
})
})
context('intelligent test runner', () => {
it('can report git metadata', (done) => {
const searchCommitsRequestPromise = receiver.payloadReceived(
({ url }) => url.endsWith('/api/v2/git/repository/search_commits')
)
const packfileRequestPromise = receiver
.payloadReceived(({ url }) => url.endsWith('/api/v2/git/repository/packfile'))
const eventsRequestPromise = receiver.payloadReceived(({ url }) => url.endsWith('/api/v2/citestcycle'))
Promise.all([
searchCommitsRequestPromise,
packfileRequestPromise,
eventsRequestPromise
]).then(([searchCommitRequest, packfileRequest, eventsRequest]) => {
if (isAgentless) {
assert.propertyVal(searchCommitRequest.headers, 'dd-api-key', '1')
assert.propertyVal(packfileRequest.headers, 'dd-api-key', '1')
} else {
assert.notProperty(searchCommitRequest.headers, 'dd-api-key')
assert.notProperty(packfileRequest.headers, 'dd-api-key')
}
const eventTypes = eventsRequest.payload.events.map(event => event.type)
assert.includeMembers(eventTypes, ['test', 'test_suite_end', 'test_module_end', 'test_session_end'])
const numSuites = eventTypes.reduce(
(acc, type) => type === 'test_suite_end' ? acc + 1 : acc, 0
)
assert.equal(numSuites, 2)
done()
}).catch(done)
childProcess = exec(
runTestsCommand,
{
cwd,
env: envVars,
stdio: 'pipe'
}
)
})
it('can report code coverage', (done) => {
const libraryConfigRequestPromise = receiver.payloadReceived(
({ url }) => url.endsWith('/api/v2/libraries/tests/services/setting')
)
const codeCovRequestPromise = receiver.payloadReceived(({ url }) => url.endsWith('/api/v2/citestcov'))
const eventsRequestPromise = receiver.payloadReceived(({ url }) => url.endsWith('/api/v2/citestcycle'))
Promise.all([
libraryConfigRequestPromise,
codeCovRequestPromise,
eventsRequestPromise
]).then(([libraryConfigRequest, codeCovRequest, eventsRequest]) => {
const [coveragePayload] = codeCovRequest.payload
if (isAgentless) {
assert.propertyVal(libraryConfigRequest.headers, 'dd-api-key', '1')
assert.propertyVal(codeCovRequest.headers, 'dd-api-key', '1')
} else {
assert.notProperty(libraryConfigRequest.headers, 'dd-api-key')
assert.notProperty(codeCovRequest.headers, 'dd-api-key', '1')
}
assert.propertyVal(coveragePayload, 'name', 'coverage1')
assert.propertyVal(coveragePayload, 'filename', 'coverage1.msgpack')
assert.propertyVal(coveragePayload, 'type', 'application/msgpack')
assert.include(coveragePayload.content, {
version: 2
})
const allCoverageFiles = codeCovRequest.payload
.flatMap(coverage => coverage.content.coverages)
.flatMap(file => file.files)
.map(file => file.filename)
assert.includeMembers(allCoverageFiles, [
`${featuresPath}support/steps.${fileExtension}`,
`${featuresPath}farewell.feature`,
`${featuresPath}greetings.feature`
])
// steps is twice because there are two suites using it
assert.equal(
allCoverageFiles.filter(file => file === `${featuresPath}support/steps.${fileExtension}`).length,
2
)
assert.exists(coveragePayload.content.coverages[0].test_session_id)
assert.exists(coveragePayload.content.coverages[0].test_suite_id)
const testSession = eventsRequest
.payload
.events
.find(event => event.type === 'test_session_end')
.content
assert.exists(testSession.metrics[TEST_CODE_COVERAGE_LINES_PCT])
const eventTypes = eventsRequest.payload.events.map(event => event.type)
assert.includeMembers(eventTypes, ['test', 'test_suite_end', 'test_module_end', 'test_session_end'])
const numSuites = eventTypes.reduce(
(acc, type) => type === 'test_suite_end' ? acc + 1 : acc, 0
)
assert.equal(numSuites, 2)
}).catch(done)
childProcess = exec(
runTestsWithCoverageCommand,
{
cwd,
env: envVars,
stdio: 'pipe'
}
)
childProcess.stdout.on('data', (chunk) => {
testOutput += chunk.toString()
})
childProcess.stderr.on('data', (chunk) => {
testOutput += chunk.toString()
})
childProcess.on('exit', () => {
// check that reported coverage is still the same
assert.include(testOutput, 'Lines : 100%')
done()
})
})
it('does not report code coverage if disabled by the API', (done) => {
receiver.setSettings({
itr_enabled: false,
code_coverage: false,
tests_skipping: false
})
receiver.assertPayloadReceived(() => {
const error = new Error('it should not report code coverage')
done(error)
}, ({ url }) => url.endsWith('/api/v2/citestcov')).catch(() => {})
receiver.assertPayloadReceived(({ payload }) => {
const eventTypes = payload.events.map(event => event.type)
assert.includeMembers(eventTypes, ['test', 'test_session_end', 'test_module_end', 'test_suite_end'])
const testSession = payload.events.find(event => event.type === 'test_session_end').content
assert.propertyVal(testSession.meta, TEST_ITR_TESTS_SKIPPED, 'false')
assert.propertyVal(testSession.meta, TEST_CODE_COVERAGE_ENABLED, 'false')
assert.propertyVal(testSession.meta, TEST_ITR_SKIPPING_ENABLED, 'false')
assert.exists(testSession.metrics[TEST_CODE_COVERAGE_LINES_PCT])
const testModule = payload.events.find(event => event.type === 'test_module_end').content
assert.propertyVal(testModule.meta, TEST_ITR_TESTS_SKIPPED, 'false')
assert.propertyVal(testModule.meta, TEST_CODE_COVERAGE_ENABLED, 'false')
assert.propertyVal(testModule.meta, TEST_ITR_SKIPPING_ENABLED, 'false')
}, ({ url }) => url.endsWith('/api/v2/citestcycle')).then(() => done()).catch(done)
childProcess = exec(
runTestsWithCoverageCommand,
{
cwd,
env: envVars,
stdio: 'inherit'
}
)
})
it('can skip suites received by the intelligent test runner API and still reports code coverage',
(done) => {
receiver.setSuitesToSkip([{
type: 'suite',
attributes: {
suite: `${featuresPath}farewell.feature`
}
}])
const skippableRequestPromise = receiver
.payloadReceived(({ url }) => url.endsWith('/api/v2/ci/tests/skippable'))
const coverageRequestPromise = receiver.payloadReceived(({ url }) => url.endsWith('/api/v2/citestcov'))
const eventsRequestPromise = receiver.payloadReceived(({ url }) => url.endsWith('/api/v2/citestcycle'))
Promise.all([
skippableRequestPromise,
coverageRequestPromise,
eventsRequestPromise
]).then(([skippableRequest, coverageRequest, eventsRequest]) => {
const [coveragePayload] = coverageRequest.payload
if (isAgentless) {
assert.propertyVal(skippableRequest.headers, 'dd-api-key', '1')
assert.propertyVal(coverageRequest.headers, 'dd-api-key', '1')
assert.propertyVal(eventsRequest.headers, 'dd-api-key', '1')
} else {
assert.notProperty(skippableRequest.headers, 'dd-api-key', '1')
assert.notProperty(coverageRequest.headers, 'dd-api-key', '1')
assert.notProperty(eventsRequest.headers, 'dd-api-key', '1')
}
assert.propertyVal(coveragePayload, 'name', 'coverage1')
assert.propertyVal(coveragePayload, 'filename', 'coverage1.msgpack')
assert.propertyVal(coveragePayload, 'type', 'application/msgpack')
const eventTypes = eventsRequest.payload.events.map(event => event.type)
const skippedSuite = eventsRequest.payload.events.find(event =>
event.content.resource === `test_suite.${featuresPath}farewell.feature`
).content
assert.propertyVal(skippedSuite.meta, TEST_STATUS, 'skip')
assert.propertyVal(skippedSuite.meta, TEST_SKIPPED_BY_ITR, 'true')
assert.includeMembers(eventTypes, ['test', 'test_suite_end', 'test_module_end', 'test_session_end'])
const numSuites = eventTypes.reduce(
(acc, type) => type === 'test_suite_end' ? acc + 1 : acc, 0
)
assert.equal(numSuites, 2)
const testSession = eventsRequest
.payload.events.find(event => event.type === 'test_session_end').content
assert.propertyVal(testSession.meta, TEST_ITR_TESTS_SKIPPED, 'true')
assert.propertyVal(testSession.meta, TEST_CODE_COVERAGE_ENABLED, 'true')
assert.propertyVal(testSession.meta, TEST_ITR_SKIPPING_ENABLED, 'true')
assert.propertyVal(testSession.meta, TEST_ITR_SKIPPING_TYPE, 'suite')
assert.propertyVal(testSession.metrics, TEST_ITR_SKIPPING_COUNT, 1)
const testModule = eventsRequest
.payload.events.find(event => event.type === 'test_module_end').content
assert.propertyVal(testModule.meta, TEST_ITR_TESTS_SKIPPED, 'true')
assert.propertyVal(testModule.meta, TEST_CODE_COVERAGE_ENABLED, 'true')
assert.propertyVal(testModule.meta, TEST_ITR_SKIPPING_ENABLED, 'true')
assert.propertyVal(testModule.meta, TEST_ITR_SKIPPING_TYPE, 'suite')
assert.propertyVal(testModule.metrics, TEST_ITR_SKIPPING_COUNT, 1)
done()
}).catch(done)
childProcess = exec(
runTestsWithCoverageCommand,
{
cwd,
env: envVars,
stdio: 'inherit'
}
)
})
it('does not skip tests if git metadata upload fails', (done) => {
receiver.setSuitesToSkip([{
type: 'suite',
attributes: {
suite: `${featuresPath}farewell.feature`
}
}])
receiver.setGitUploadStatus(404)
receiver.assertPayloadReceived(() => {
const error = new Error('should not request skippable')
done(error)
}, ({ url }) => url.endsWith('/api/v2/ci/tests/skippable'))
receiver.assertPayloadReceived(({ payload }) => {
const eventTypes = payload.events.map(event => event.type)
// because they are not skipped
assert.includeMembers(eventTypes, ['test', 'test_suite_end', 'test_module_end', 'test_session_end'])
const numSuites = eventTypes.reduce(
(acc, type) => type === 'test_suite_end' ? acc + 1 : acc, 0
)
assert.equal(numSuites, 2)
const testSession = payload.events.find(event => event.type === 'test_session_end').content
assert.propertyVal(testSession.meta, TEST_ITR_TESTS_SKIPPED, 'false')
assert.propertyVal(testSession.meta, TEST_CODE_COVERAGE_ENABLED, 'true')
assert.propertyVal(testSession.meta, TEST_ITR_SKIPPING_ENABLED, 'true')
const testModule = payload.events.find(event => event.type === 'test_module_end').content
assert.propertyVal(testModule.meta, TEST_ITR_TESTS_SKIPPED, 'false')
assert.propertyVal(testModule.meta, TEST_CODE_COVERAGE_ENABLED, 'true')
assert.propertyVal(testModule.meta, TEST_ITR_SKIPPING_ENABLED, 'true')
}, ({ url }) => url.endsWith('/api/v2/citestcycle')).then(() => done()).catch(done)
childProcess = exec(
runTestsWithCoverageCommand,
{
cwd,
env: envVars,
stdio: 'inherit'
}
)
})
it('does not skip tests if test skipping is disabled by the API', (done) => {
receiver.setSettings({
itr_enabled: true,
code_coverage: true,
tests_skipping: false
})
receiver.setSuitesToSkip([{
type: 'suite',
attributes: {
suite: `${featuresPath}farewell.feature`
}
}])
receiver.assertPayloadReceived(() => {
const error = new Error('should not request skippable')
done(error)
}, ({ url }) => url.endsWith('/api/v2/ci/tests/skippable'))
receiver.assertPayloadReceived(({ payload }) => {
const eventTypes = payload.events.map(event => event.type)
// because they are not skipped
assert.includeMembers(eventTypes, ['test', 'test_suite_end', 'test_module_end', 'test_session_end'])
const numSuites = eventTypes.reduce(
(acc, type) => type === 'test_suite_end' ? acc + 1 : acc, 0
)
assert.equal(numSuites, 2)
}, ({ url }) => url.endsWith('/api/v2/citestcycle')).then(() => done()).catch(done)
childProcess = exec(
runTestsWithCoverageCommand,
{
cwd,
env: getCiVisAgentlessConfig(receiver.port),
stdio: 'inherit'
}
)
})
it('does not skip suites if suite is marked as unskippable', (done) => {
receiver.setSettings({
itr_enabled: true,
code_coverage: true,
tests_skipping: true
})
receiver.setSuitesToSkip([
{
type: 'suite',
attributes: {
suite: `${featuresPath}farewell.feature`
}
},
{
type: 'suite',
attributes: {
suite: `${featuresPath}greetings.feature`
}
}
])
const eventsPromise = receiver
.gatherPayloadsMaxTimeout(({ url }) => url.endsWith('/api/v2/citestcycle'), (payloads) => {
const events = payloads.flatMap(({ payload }) => payload.events)
const suites = events.filter(event => event.type === 'test_suite_end')
assert.equal(suites.length, 2)
const testSession = events.find(event => event.type === 'test_session_end').content
const testModule = events.find(event => event.type === 'test_session_end').content
assert.propertyVal(testSession.meta, TEST_ITR_UNSKIPPABLE, 'true')
assert.propertyVal(testSession.meta, TEST_ITR_FORCED_RUN, 'true')
assert.propertyVal(testModule.meta, TEST_ITR_UNSKIPPABLE, 'true')
assert.propertyVal(testModule.meta, TEST_ITR_FORCED_RUN, 'true')
const skippedSuite = suites.find(
event => event.content.resource === 'test_suite.ci-visibility/features/farewell.feature'
).content
const forcedToRunSuite = suites.find(
event => event.content.resource === 'test_suite.ci-visibility/features/greetings.feature'
).content
assert.propertyVal(skippedSuite.meta, TEST_STATUS, 'skip')
assert.notProperty(skippedSuite.meta, TEST_ITR_UNSKIPPABLE)
assert.notProperty(skippedSuite.meta, TEST_ITR_FORCED_RUN)
assert.propertyVal(forcedToRunSuite.meta, TEST_STATUS, 'fail')
assert.propertyVal(forcedToRunSuite.meta, TEST_ITR_UNSKIPPABLE, 'true')
assert.propertyVal(forcedToRunSuite.meta, TEST_ITR_FORCED_RUN, 'true')
}, 25000)
childProcess = exec(
runTestsWithCoverageCommand,
{
cwd,
env: envVars,
stdio: 'inherit'
}
)
childProcess.on('exit', () => {
eventsPromise.then(() => {
done()
}).catch(done)
})
})
it('only sets forced to run if suite was going to be skipped by ITR', (done) => {
receiver.setSettings({
itr_enabled: true,
code_coverage: true,
tests_skipping: true
})
receiver.setSuitesToSkip([
{
type: 'suite',
attributes: {
suite: `${featuresPath}farewell.feature`
}
}
])
const eventsPromise = receiver
.gatherPayloadsMaxTimeout(({ url }) => url.endsWith('/api/v2/citestcycle'), (payloads) => {
const events = payloads.flatMap(({ payload }) => payload.events)
const suites = events.filter(event => event.type === 'test_suite_end')
assert.equal(suites.length, 2)
const testSession = events.find(event => event.type === 'test_session_end').content
const testModule = events.find(event => event.type === 'test_session_end').content
assert.propertyVal(testSession.meta, TEST_ITR_UNSKIPPABLE, 'true')
assert.notProperty(testSession.meta, TEST_ITR_FORCED_RUN)
assert.propertyVal(testModule.meta, TEST_ITR_UNSKIPPABLE, 'true')
assert.notProperty(testModule.meta, TEST_ITR_FORCED_RUN)
const skippedSuite = suites.find(
event => event.content.resource === 'test_suite.ci-visibility/features/farewell.feature'
)
const failedSuite = suites.find(
event => event.content.resource === 'test_suite.ci-visibility/features/greetings.feature'
)
assert.propertyVal(skippedSuite.content.meta, TEST_STATUS, 'skip')
assert.notProperty(skippedSuite.content.meta, TEST_ITR_UNSKIPPABLE)
assert.notProperty(skippedSuite.content.meta, TEST_ITR_FORCED_RUN)
assert.propertyVal(failedSuite.content.meta, TEST_STATUS, 'fail')
assert.propertyVal(failedSuite.content.meta, TEST_ITR_UNSKIPPABLE, 'true')
assert.notProperty(failedSuite.content.meta, TEST_ITR_FORCED_RUN)
}, 25000)
childProcess = exec(
runTestsWithCoverageCommand,
{
cwd,
env: envVars,
stdio: 'inherit'
}
)
childProcess.on('exit', () => {
eventsPromise.then(() => {
done()
}).catch(done)
})
})
it('sets _dd.ci.itr.tests_skipped to false if the received suite is not skipped', (done) => {
receiver.setSuitesToSkip([{
type: 'suite',
attributes: {
suite: `${featuresPath}not-existing.feature`
}
}])
const eventsPromise = receiver
.gatherPayloadsMaxTimeout(({ url }) => url.endsWith('/api/v2/citestcycle'), (payloads) => {
const events = payloads.flatMap(({ payload }) => payload.events)
const testSession = events.find(event => event.type === 'test_session_end').content
assert.propertyVal(testSession.meta, TEST_ITR_TESTS_SKIPPED, 'false')
assert.propertyVal(testSession.meta, TEST_CODE_COVERAGE_ENABLED, 'true')
assert.propertyVal(testSession.meta, TEST_ITR_SKIPPING_ENABLED, 'true')
assert.propertyVal(testSession.metrics, TEST_ITR_SKIPPING_COUNT, 0)
const testModule = events.find(event => event.type === 'test_module_end').content
assert.propertyVal(testModule.meta, TEST_ITR_TESTS_SKIPPED, 'false')
assert.propertyVal(testModule.meta, TEST_CODE_COVERAGE_ENABLED, 'true')
assert.propertyVal(testModule.meta, TEST_ITR_SKIPPING_ENABLED, 'true')
assert.propertyVal(testModule.metrics, TEST_ITR_SKIPPING_COUNT, 0)
}, 25000)
childProcess = exec(
runTestsWithCoverageCommand,
{
cwd,
env: envVars,
stdio: 'inherit'
}
)
childProcess.on('exit', () => {
eventsPromise.then(() => {
done()
}).catch(done)
})
})
if (!isAgentless) {
context('if the agent is not event platform proxy compatible', () => {
it('does not do any intelligent test runner request', (done) => {
receiver.setInfoResponse({ endpoints: [] })
receiver.assertPayloadReceived(() => {
const error = new Error('should not request search_commits')
done(error)
}, ({ url }) => url === '/evp_proxy/v2/api/v2/git/repository/search_commits')
receiver.assertPayloadReceived(() => {
const error = new Error('should not request search_commits')
done(error)
}, ({ url }) => url === '/api/v2/git/repository/search_commits')
receiver.assertPayloadReceived(() => {
const error = new Error('should not request setting')
done(error)
}, ({ url }) => url === '/api/v2/libraries/tests/services/setting')
receiver.assertPayloadReceived(() => {
const error = new Error('should not request setting')
done(error)
}, ({ url }) => url === '/evp_proxy/v2/api/v2/libraries/tests/services/setting')
receiver.assertPayloadReceived(({ payload }) => {
const testSpans = payload.flatMap(trace => trace)
const resourceNames = testSpans.map(span => span.resource)
assert.includeMembers(resourceNames,
[
`${featuresPath}farewell.feature.Say farewell`,
`${featuresPath}greetings.feature.Say greetings`,
`${featuresPath}greetings.feature.Say yeah`,
`${featuresPath}greetings.feature.Say yo`,
`${featuresPath}greetings.feature.Say skip`
]
)
}, ({ url }) => url === '/v0.4/traces').then(() => done()).catch(done)
childProcess = exec(
runTestsWithCoverageCommand,
{
cwd,
env: getCiVisEvpProxyConfig(receiver.port),
stdio: 'inherit'
}
)
})
})
}
it('reports itr_correlation_id in test suites', (done) => {
const itrCorrelationId = '4321'
receiver.setItrCorrelationId(itrCorrelationId)
const eventsPromise = receiver
.gatherPayloadsMaxTimeout(({ url }) => url.endsWith('/api/v2/citestcycle'), (payloads) => {
const events = payloads.flatMap(({ payload }) => payload.events)
const testSuites = events.filter(event => event.type === 'test_suite_end').map(event => event.content)
testSuites.forEach(testSuite => {
assert.equal(testSuite.itr_correlation_id, itrCorrelationId)
})
}, 25000)
childProcess = exec(
runTestsWithCoverageCommand,
{
cwd,
env: envVars,
stdio: 'inherit'
}
)
childProcess.on('exit', () => {
eventsPromise.then(() => {
done()
}).catch(done)
})
})
it('reports code coverage relative to the repository root, not working directory', (done) => {
receiver.setSettings({
itr_enabled: true,
code_coverage: true,
tests_skipping: false
})
const codeCoveragesPromise = receiver
.gatherPayloadsMaxTimeout(({ url }) => url.endsWith('/api/v2/citestcov'), (payloads) => {
const coveredFiles = payloads
.flatMap(({ payload }) => payload)
.flatMap(({ content: { coverages } }) => coverages)
.flatMap(({ files }) => files)
.map(({ filename }) => filename)
assert.includeMembers(coveredFiles, [
'ci-visibility/subproject/features/support/steps.js',
'ci-visibility/subproject/features/greetings.feature'
])
})
childProcess = exec(
'../../node_modules/nyc/bin/nyc.js node ../../node_modules/.bin/cucumber-js features/*.feature',
{
cwd: `${cwd}/ci-visibility/subproject`,
env: {
...getCiVisAgentlessConfig(receiver.port)
},
stdio: 'inherit'
}
)
childProcess.on('exit', () => {
codeCoveragesPromise.then(() => {
done()
}).catch(done)
})
})
})
context('early flake detection', () => {
it('retries new tests', (done) => {
const NUM_RETRIES_EFD = 3
receiver.setSettings({
itr_enabled: false,
code_coverage: false,
tests_skipping: false,
early_flake_detection: {
enabled: true,
slow_test_retries: {
'5s': NUM_RETRIES_EFD
}
}
})
// cucumber.ci-visibility/features/farewell.feature.Say whatever will be considered new
receiver.setKnownTests(
{
cucumber: {
'ci-visibility/features/farewell.feature': ['Say farewell'],
'ci-visibility/features/greetings.feature': ['Say greetings', 'Say yeah', 'Say yo', 'Say skip']
}
}
)
const eventsPromise = receiver
.gatherPayloadsMaxTimeout(({ url }) => url.endsWith('/api/v2/citestcycle'), payloads => {
const events = payloads.flatMap(({ payload }) => payload.events)
const testSession = events.find(event => event.type === 'test_session_end').content
assert.propertyVal(testSession.meta, TEST_EARLY_FLAKE_ENABLED, 'true')
const tests = events.filter(event => event.type === 'test').map(event => event.content)
const newTests = tests.filter(test =>
test.resource === 'ci-visibility/features/farewell.feature.Say whatever'
)
newTests.forEach(test => {
assert.propertyVal(test.meta, TEST_IS_NEW, 'true')
})
const retriedTests = newTests.filter(test => test.meta[TEST_IS_RETRY] === 'true')
// all but one has been retried
assert.equal(
newTests.length - 1,
retriedTests.length
)
assert.equal(retriedTests.length, NUM_RETRIES_EFD)
// Test name does not change
newTests.forEach(test => {
assert.equal(test.meta[TEST_NAME], 'Say whatever')
})
})
childProcess = exec(
runTestsCommand,
{
cwd,
env: envVars,
stdio: 'pipe'
}
)
childProcess.on('exit', () => {
eventsPromise.then(() => {
done()
}).catch(done)
})
})
it('is disabled if DD_CIVISIBILITY_EARLY_FLAKE_DETECTION_ENABLED is false', (done) => {
const NUM_RETRIES_EFD = 3
receiver.setSettings({
itr_enabled: false,
code_coverage: false,
tests_skipping: false,
early_flake_detection: {
enabled: true,
slow_test_retries: {
'5s': NUM_RETRIES_EFD
}
}
})
const eventsPromise = receiver
.gatherPayloadsMaxTimeout(({ url }) => url.endsWith('/api/v2/citestcycle'), (payloads) => {
const events = payloads.flatMap(({ payload }) => payload.events)
const testSession = events.find(event => event.type === 'test_session_end').content
assert.notProperty(testSession.meta, TEST_EARLY_FLAKE_ENABLED)
const tests = events.filter(event => event.type === 'test').map(event => event.content)
const newTests = tests.filter(test =>
test.meta[TEST_IS_NEW] === 'true'
)
// new tests are not detected
assert.equal(newTests.length, 0)
})
// cucumber.ci-visibility/features/farewell.feature.Say whatever will be considered new
receiver.setKnownTests({
cucumber: {
'ci-visibility/features/farewell.feature': ['Say farewell'],
'ci-visibility/features/greetings.feature': ['Say greetings', 'Say yeah', 'Say yo', 'Say skip']
}
})
childProcess = exec(
runTestsCommand,
{
cwd,
env: { ...envVars, DD_CIVISIBILITY_EARLY_FLAKE_DETECTION_ENABLED: 'false' },
stdio: 'pipe'
}
)
childProcess.on('exit', () => {
eventsPromise.then(() => {
done()
}).catch(done)
})
})
it('retries flaky tests and sets exit code to 0 as long as one attempt passes', (done) => {
const NUM_RETRIES_EFD = 3
receiver.setSettings({
itr_enabled: false,
code_coverage: false,
tests_skipping: false,
early_flake_detection: {
enabled: true,
slow_test_retries: {
'5s': NUM_RETRIES_EFD
}
}
})
// Tests in "cucumber.ci-visibility/features-flaky/flaky.feature" will be considered new
receiver.setKnownTests({})
const eventsPromise = receiver
.gatherPayloadsMaxTimeout(({ url }) => url.endsWith('/api/v2/citestcycle'), payloads => {
const events = payloads.flatMap(({ payload }) => payload.events)
const testSession = events.find(event => event.type === 'test_session_end').content
assert.propertyVal(testSession.meta, TEST_EARLY_FLAKE_ENABLED, 'true')
const tests = events.filter(event => event.type === 'test').map(event => event.content)
const testSuites = events.filter(event => event.type === 'test_suite_end').map(event => event.content)
tests.forEach(test => {
assert.propertyVal(test.meta, TEST_IS_NEW, 'true')
})
// All test suites pass, even though there are failed tests
testSuites.forEach(testSuite => {
assert.propertyVal(testSuite.meta, TEST_STATUS, 'pass')
})
const failedAttempts = tests.filter(test => test.meta[TEST_STATUS] === 'fail')
const passedAttempts = tests.filter(test => test.meta[TEST_STATUS] === 'pass')
// (1 original run + 3 retries) / 2
assert.equal(failedAttempts.length, 2)
assert.equal(passedAttempts.length, 2)
})
childProcess = exec(
'./node_modules/.bin/cucumber-js ci-visibility/features-flaky/*.feature',
{