forked from cypress-io/cypress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
record_spec.js
1858 lines (1596 loc) · 54.6 KB
/
record_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
const _ = require('lodash')
const path = require('path')
const Promise = require('bluebird')
const jsonSchemas = require('@cypress/json-schemas').api
const systemTests = require('../lib/system-tests').default
const { fs } = require('@packages/server/lib/util/fs')
const Fixtures = require('../lib/fixtures')
const {
createRoutes,
setupStubbedServer,
getRequestUrls, getRequests,
postRunResponse,
postRunResponseWithWarnings,
postRunInstanceResponse,
postInstanceTestsResponse,
} = require('../lib/serverStub')
const { expectRunsToHaveCorrectTimings } = require('../lib/resultsUtils')
const e2ePath = Fixtures.projectPath('e2e')
const outputPath = path.join(e2ePath, 'output.json')
let { runId, groupId, machineId, runUrl, tags } = postRunResponse
const { instanceId } = postRunInstanceResponse
let requests = null
describe('e2e record', () => {
beforeEach(() => {
requests = getRequests()
})
context('passing', () => {
setupStubbedServer(createRoutes())
it('passes', async function () {
const { stdout } = await systemTests.exec(this, {
key: 'f858a2bc-b469-4e48-be67-0876339ee7e1',
configFile: 'cypress-with-project-id.config.js',
spec: 'record*',
record: true,
snapshot: true,
outputPath,
expectedExitCode: 3,
config: {
env: {
'TEST_STDIO': '1',
},
},
})
console.log(stdout)
expect(stdout).to.include('Run URL:')
expect(stdout).to.include(runUrl)
const urls = getRequestUrls()
const instanceReqs = urls.slice(0, 22)
expect(instanceReqs).to.deep.eq([
// first create run request
'POST /runs',
// spec 1
`POST /runs/${runId}/instances`,
// no instances/:id/tests because spec failed during eval
`POST /instances/${instanceId}/results`,
'PUT /videos/video.mp4',
`PUT /instances/${instanceId}/stdout`,
// spec 2
`POST /runs/${runId}/instances`,
`POST /instances/${instanceId}/tests`,
`POST /instances/${instanceId}/results`,
'PUT /videos/video.mp4',
'PUT /screenshots/1.png',
`PUT /instances/${instanceId}/stdout`,
// spec 3
`POST /runs/${runId}/instances`,
`POST /instances/${instanceId}/tests`,
`POST /instances/${instanceId}/results`,
// no video because no tests failed
'PUT /screenshots/1.png',
`PUT /instances/${instanceId}/stdout`,
// spec 4
`POST /runs/${runId}/instances`,
`POST /instances/${instanceId}/tests`,
`POST /instances/${instanceId}/results`,
'PUT /videos/video.mp4',
'PUT /screenshots/1.png',
`PUT /instances/${instanceId}/stdout`,
])
const postRun = requests[0]
// ensure its relative to projectRoot
expect(postRun.body.specs).to.deep.eq([
'cypress/e2e/record_error.cy.js',
'cypress/e2e/record_fail.cy.js',
'cypress/e2e/record_pass.cy.js',
'cypress/e2e/record_uncaught.cy.js',
])
expect(postRun.body.projectId).to.eq('pid123')
expect(postRun.body.recordKey).to.eq('f858a2bc-b469-4e48-be67-0876339ee7e1')
expect(postRun.body.specPattern).to.eq('cypress/e2e/record*')
expect(postRun.body.testingType).to.eq('e2e')
const firstInstance = requests[1]
expect(firstInstance.body.groupId).to.eq(groupId)
expect(firstInstance.body.machineId).to.eq(machineId)
expect(firstInstance.body.spec).to.eq(null)
const firstInstancePostResults = requests[2]
expect(firstInstancePostResults.body.exception).to.include('Oops...we found an error preparing this test file')
expect(firstInstancePostResults.body.tests).to.be.null
expect(firstInstancePostResults.body.hooks).to.not.exist
expect(firstInstancePostResults.body.screenshots).to.have.length(0)
expect(firstInstancePostResults.body.stats.tests).to.eq(0)
expect(firstInstancePostResults.body.stats.failures).to.eq(1)
expect(firstInstancePostResults.body.stats.passes).to.eq(0)
const firstInstanceStdout = requests[4]
expect(firstInstanceStdout.body.stdout).to.include('record_error.cy.js')
const secondInstance = requests[5]
expect(secondInstance.body.groupId).to.eq(groupId)
expect(secondInstance.body.machineId).to.eq(machineId)
expect(secondInstance.body.spec).to.eq(null)
const secondInstancePostTests = requests[6].body
expect(secondInstancePostTests.tests).length(2)
expect(secondInstancePostTests.hooks).length(1)
expect(secondInstancePostTests.config).is.an('object')
const secondInstancePostResults = requests[7]
expect(secondInstancePostResults.body.exception).to.be.null
expect(secondInstancePostResults.body.tests).to.have.length(2)
expect(secondInstancePostResults.body.screenshots).to.have.length(1)
expect(secondInstancePostResults.body.stats.tests).to.eq(2)
expect(secondInstancePostResults.body.stats.failures).to.eq(1)
expect(secondInstancePostResults.body.stats.passes).to.eq(0)
expect(secondInstancePostResults.body.stats.skipped).to.eq(1)
expect(secondInstancePostResults.body.hooks).not.exist
expect(secondInstancePostResults.body.cypressConfig).not.exist
const secondInstanceStdout = requests[10]
expect(secondInstanceStdout.body.stdout).to.include('record_fail.cy.js')
expect(secondInstanceStdout.body.stdout).not.to.include('record_error.cy.js')
const thirdInstance = requests[11]
expect(thirdInstance.body.groupId).to.eq(groupId)
expect(thirdInstance.body.machineId).to.eq(machineId)
expect(thirdInstance.body.spec).to.eq(null)
const thirdInstancePostTests = requests[12].body
expect(thirdInstancePostTests.tests[0].config.env.foo).eq(true)
expect(thirdInstancePostTests.tests).length(2)
expect(thirdInstancePostTests.hooks).length(0)
expect(thirdInstancePostTests.config).is.an('object')
const thirdInstancePostResults = requests[13]
expect(thirdInstancePostResults.body.exception).to.be.null
expect(thirdInstancePostResults.body.tests).to.have.length(2)
expect(thirdInstancePostResults.body.screenshots).to.have.length(1)
expect(thirdInstancePostResults.body.stats.tests).to.eq(2)
expect(thirdInstancePostResults.body.stats.passes).to.eq(1)
expect(thirdInstancePostResults.body.stats.failures).to.eq(0)
expect(thirdInstancePostResults.body.stats.pending).to.eq(1)
const thirdInstanceStdout = requests[15]
console.log('13')
expect(thirdInstanceStdout.body.stdout).to.include('record_pass.cy.js')
expect(thirdInstanceStdout.body.stdout).not.to.include('record_error.cy.js')
expect(thirdInstanceStdout.body.stdout).not.to.include('record_fail.cy.js')
expect(thirdInstanceStdout.body.stdout).to.include('plugin stdout')
expect(thirdInstanceStdout.body.stdout).to.not.include('plugin stderr')
const fourthInstance = requests[16]
console.log('14')
expect(fourthInstance.body.groupId).to.eq(groupId)
expect(fourthInstance.body.machineId).to.eq(machineId)
expect(fourthInstance.body.spec).to.eq(null)
const fourthInstancePostResults = requests[18]
console.log('15')
expect(fourthInstancePostResults.body.exception).to.be.null
expect(fourthInstancePostResults.body.tests).to.have.length(1)
expect(fourthInstancePostResults.body.screenshots).to.have.length(1)
expect(fourthInstancePostResults.body.stats.tests).to.eq(1)
expect(fourthInstancePostResults.body.stats.failures).to.eq(1)
expect(fourthInstancePostResults.body.stats.passes).to.eq(0)
const forthInstanceStdout = requests[21]
console.log('18')
expect(forthInstanceStdout.body.stdout).to.include('record_uncaught.cy.js')
expect(forthInstanceStdout.body.stdout).not.to.include('record_error.cy.js')
expect(forthInstanceStdout.body.stdout).not.to.include('record_fail.cy.js')
expect(forthInstanceStdout.body.stdout).not.to.include('record_pass.cy.js')
let runs = requests.filter((v) => v.url.match(/POST \/instances\/.*\/results/) && v.body.tests).map((v) => v.body)
expectRunsToHaveCorrectTimings(runs)
runs = systemTests.normalizeRuns(runs)
systemTests.snapshot(runs)
const results = await fs.readJsonAsync(outputPath)
expect(results.runUrl).to.equal(runUrl)
})
})
context('parallelization', () => {
const allSpecs = [
'cypress/e2e/record_error.cy.js',
'cypress/e2e/record_fail.cy.js',
'cypress/e2e/record_pass.cy.js',
'cypress/e2e/record_uncaught.cy.js',
]
const postInstanceResponses = (specs) => {
return _
.chain(specs)
.map((spec, i) => {
return {
spec,
instanceId,
estimatedWallClockDuration: (i + 1) * 1000,
}
})
.concat({
spec: null,
instanceId: null,
estimatedWallClockDuration: null,
})
.value()
}
// a1 does 3 specs, b2 does 1 spec
const a1Specs = _.without(allSpecs, 'cypress/e2e/record_pass.cy.js')
const b2Specs = _.difference(allSpecs, a1Specs)
let firstRunResponse = false
let waitUntilSecondInstanceClaims = null
const claimed = []
const responses = {
a1: postInstanceResponses(a1Specs),
b2: postInstanceResponses(b2Specs),
}
// replace the 1st + 2nd routes object
const routes = createRoutes({
postRun: {
res (req, res) {
let ciBuildId; let group;
({ group, tags, ciBuildId } = req.body)
expect(group).to.eq('prod-e2e')
expect(tags).to.deep.eq(['nightly'])
expect(ciBuildId).to.eq('ciBuildId123')
// if this is the first response
// give machineId a1, else b2
if (!firstRunResponse) {
firstRunResponse = true
machineId = 'a1ad2bcf-6398-46ed-b201-2fd90b188d5f'
} else {
machineId = 'b2bd2bcf-6398-46ed-b201-2fd90b188d5f'
}
return res.json(
_.extend({}, postRunResponse, { machineId }),
)
},
},
postRunInstance: {
res (req, res) {
let spec;
({ machineId, spec } = req.body)
expect(spec).to.be.null
const mId = machineId.slice(0, 2)
const respond = function () {
const resp = responses[mId].shift()
// if theres a spec to claim
if (resp.spec) {
claimed.push(resp)
}
resp.claimedInstances = claimed.length
resp.totalInstances = allSpecs.length
jsonSchemas.assertSchema('postRunInstanceResponse', '2.1.0')(resp)
return res.json(resp)
}
// when the 1st machine attempts to claim its FIRST spec, we
// automatically delay it until the 2nd machine claims its FIRST
// spec so that the request URL's are deterministic
if ((mId === 'a1') && (claimed.length === 0)) {
waitUntilSecondInstanceClaims = function () {
waitUntilSecondInstanceClaims = null
return respond()
}
} else {
respond()
return (typeof waitUntilSecondInstanceClaims === 'function' ? waitUntilSecondInstanceClaims() : undefined)
}
},
},
})
setupStubbedServer(routes)
// TODO: fix flaky test https://github.com/cypress-io/cypress/issues/23152
it.skip('passes in parallel with group', function () {
this.retries(3)
return Promise.all([
systemTests.exec(this, {
key: 'f858a2bc-b469-4e48-be67-0876339ee7e1',
configFile: 'cypress-with-project-id.config.js',
spec: 'record*',
group: 'prod-e2e',
record: true,
parallel: true,
snapshot: true,
tag: 'nightly',
ciBuildId: 'ciBuildId123',
expectedExitCode: 3,
config: {
trashAssetsBeforeRuns: false,
},
})
.then(({ stdout }) => stdout),
// stagger the 2nd run
// starting up a bit
Promise
.delay(3000)
.then(() => {
return systemTests.exec(this, {
key: 'f858a2bc-b469-4e48-be67-0876339ee7e1',
configFile: 'cypress-with-project-id.config.js',
spec: 'record*',
group: 'prod-e2e',
record: true,
parallel: true,
snapshot: true,
tag: 'nightly',
ciBuildId: 'ciBuildId123',
config: {
trashAssetsBeforeRuns: false,
},
})
.then(({ stdout }) => stdout)
}),
])
})
})
context('metadata', () => {
setupStubbedServer(createRoutes())
// TODO: fix flaky test https://github.com/cypress-io/cypress/issues/23151
it.skip('sends Studio usage metadata', function () {
return systemTests.exec(this, {
key: 'f858a2bc-b469-4e48-be67-0876339ee7e1',
configFile: 'cypress-with-project-id.config.js',
spec: 'studio_written.cy.js',
record: true,
snapshot: true,
})
.then(() => {
const postResults = requests[3]
expect(postResults.url).to.eq(`POST /instances/${instanceId}/results`)
expect(postResults.body.metadata.studioCreated).to.eq(2)
expect(postResults.body.metadata.studioExtended).to.eq(4)
})
})
})
context('misconfiguration', () => {
setupStubbedServer([])
it('errors and exits when no specs found', function () {
return systemTests.exec(this, {
spec: 'notfound/**',
snapshot: true,
expectedExitCode: 1,
})
.then(() => {
expect(getRequestUrls()).to.be.empty
})
})
it('errors and exits when no browser found', function () {
return systemTests.exec(this, {
browser: 'browserDoesNotExist',
spec: 'record_pass*',
snapshot: true,
expectedExitCode: 1,
})
.then(() => {
expect(getRequestUrls()).to.be.empty
})
})
})
context('empty specs', () => {
setupStubbedServer(createRoutes())
// https://github.com/cypress-io/cypress/issues/15512
it('succeeds when empty spec file', async function () {
await systemTests.exec(this, {
key: 'f858a2bc-b469-4e48-be67-0876339ee7e1',
configFile: 'cypress-with-project-id.config.js',
record: true,
spec: 'empty_suite.cy.js,empty.cy.js',
snapshot: true,
expectedExitCode: 0,
})
expect(getRequestUrls()).deep.eq([
'POST /runs',
`POST /runs/${runId}/instances`,
`POST /instances/${instanceId}/tests`,
`POST /instances/${instanceId}/results`,
`PUT /instances/${instanceId}/stdout`,
`POST /runs/${runId}/instances`,
`POST /instances/${instanceId}/tests`,
`POST /instances/${instanceId}/results`,
`PUT /instances/${instanceId}/stdout`,
`POST /runs/${runId}/instances`,
])
})
})
context('projectId', () => {
systemTests.setup()
it('errors and exits without projectId', function () {
return systemTests.exec(this, {
key: 'f858a2bc-b469-4e48-be67-0876339ee7e1',
spec: 'record_pass*',
record: true,
snapshot: true,
expectedExitCode: 1,
})
})
})
context('quiet mode', () => {
setupStubbedServer(createRoutes())
it('respects quiet mode', function () {
return systemTests.exec(this, {
key: 'f858a2bc-b469-4e48-be67-0876339ee7e1',
configFile: 'cypress-with-project-id.config.js',
spec: 'record_pass*',
record: true,
snapshot: true,
expectedExitCode: 0,
quiet: true,
})
})
})
context('recordKey', () => {
setupStubbedServer(createRoutes())
it('errors and exits without recordKey', function () {
return systemTests.exec(this, {
configFile: 'cypress-with-project-id.config.js',
spec: 'record_pass*',
record: true,
snapshot: true,
expectedExitCode: 1,
})
.then(() => {
expect(getRequestUrls()).to.be.empty
})
})
it('warns but does not exit when is forked pr', function () {
process.env.CIRCLECI = 'true'
process.env.CIRCLE_PR_NUMBER = '123'
process.env.CIRCLE_PR_USERNAME = 'brian-mann'
process.env.CIRCLE_PR_REPONAME = 'cypress'
process.env.CYPRESS_INTERNAL_SYSTEM_TESTS = '0'
return systemTests.exec(this, {
configFile: 'cypress-with-project-id.config.js',
spec: 'record_pass*',
record: true,
snapshot: true,
})
.then(() => {
console.log('GETREQUESTURLS', getRequestUrls())
expect(getRequestUrls()).to.be.empty
})
})
it('warns but does not exit when is forked pr and parallel', function () {
process.env.CIRCLECI = 'true'
process.env.CIRCLE_WORKFLOW_ID = '123'
process.env.CIRCLE_PR_NUMBER = '123'
process.env.CIRCLE_PR_USERNAME = 'brian-mann'
process.env.CIRCLE_PR_REPONAME = 'cypress'
process.env.CYPRESS_INTERNAL_SYSTEM_TESTS = '0'
return systemTests.exec(this, {
configFile: 'cypress-with-project-id.config.js',
spec: 'record_pass*',
record: true,
parallel: true,
snapshot: true,
})
.then(() => {
expect(getRequestUrls()).to.be.empty
})
})
})
context('test configuration', () => {
setupStubbedServer(createRoutes())
it('config from runtime, testOptions', async function () {
await systemTests.exec(this, {
key: 'f858a2bc-b469-4e48-be67-0876339ee7e1',
configFile: 'cypress-with-project-id-without-video.config.js',
spec: 'config_record.cy.js',
record: true,
snapshot: false,
})
expect(requests[2].body.config.defaultCommandTimeout).eq(1111)
expect(requests[2].body.config.resolved.defaultCommandTimeout).deep.eq({
value: 1111,
from: 'runtime',
})
expect(requests[2].body.config.pageLoadTimeout).eq(3333)
expect(requests[2].body.config.resolved.pageLoadTimeout).deep.eq({
value: 3333,
from: 'runtime',
})
expect(requests[2].body.tests[0].config).deep.eq({
defaultCommandTimeout: 1234,
env: { foo: true },
retries: 2,
})
expect(requests[2].body.tests[1].title).deep.eq([
'record pass',
'is pending',
])
expect(requests[2].body.tests[1].body).to.eq('')
expect(requests[2].body.tests[2].title).deep.eq([
'record pass',
'is pending due to .skip',
])
expect(requests[2].body.tests[2].body).to.eq('() => {\n console.log(\'stuff\');\n }')
expect(requests[2].body.tests[3].title).deep.eq([
'record pass',
'is skipped due to browser',
])
expect(requests[2].body.tests[3].body).eq('() => {}')
expect(requests[2].body.tests[3].config).deep.eq({
defaultCommandTimeout: 1234,
browser: 'edge',
})
})
})
context('record in non-parallel', () => {
describe('api reordering specs', () => {
let mockServerState
mockServerState = setupStubbedServer(createRoutes({
postRun: {
res (req, res) {
console.log(req.body.specs)
mockServerState.specs = req.body.specs.slice().reverse()
console.log(mockServerState.specs)
mockServerState.allSpecs = req.body.specs
res.json(postRunResponse)
},
},
}))
it('changes spec run order', async function () {
await systemTests.exec(this, {
key: 'f858a2bc-b469-4e48-be67-0876339ee7e1',
configFile: 'cypress-with-project-id-without-video.config.js',
spec: 'a_record.cy.js,b_record.cy.js',
record: true,
snapshot: false,
})
// specs were reordered
expect(requests[2].body.tests[0].title[1]).eq('b test')
expect(requests[6].body.tests[0].title[1]).eq('a test')
})
})
})
describe('api skips specs', () => {
let mockServerState = setupStubbedServer(createRoutes({
postInstanceTests: {
res: (req, res) => {
console.log(mockServerState.specs)
if (mockServerState.specs.length > 0) {
return res.json({
...postInstanceTestsResponse,
actions: [{
type: 'SPEC',
action: 'SKIP',
}],
})
}
return res.json({
...postInstanceTestsResponse,
actions: [],
})
},
},
}))
it('records tests and exits without executing', async function () {
await systemTests.exec(this, {
key: 'f858a2bc-b469-4e48-be67-0876339ee7e1',
configFile: 'cypress-with-project-id-without-video.config.js',
spec: 'a_record_instantfail.cy.js,b_record.cy.js',
record: true,
snapshot: true,
expectedExitCode: 1,
})
expect(getRequestUrls()).deep.eq([
'POST /runs',
'POST /runs/00748421-e035-4a3d-8604-8468cc48bdb5/instances',
'POST /instances/e9e81b5e-cc58-4026-b2ff-8ae3161435a6/tests',
'POST /runs/00748421-e035-4a3d-8604-8468cc48bdb5/instances',
'POST /instances/e9e81b5e-cc58-4026-b2ff-8ae3161435a6/tests',
'POST /instances/e9e81b5e-cc58-4026-b2ff-8ae3161435a6/results',
'PUT /instances/e9e81b5e-cc58-4026-b2ff-8ae3161435a6/stdout',
'POST /runs/00748421-e035-4a3d-8604-8468cc48bdb5/instances',
])
console.log(requests[0].body.runnerCapabilities)
expect(requests[0].body).property('runnerCapabilities').deep.eq({
'dynamicSpecsInSerialMode': true,
'skipSpecAction': true,
})
})
it('records tests and exits without executing in parallel', async function () {
await systemTests.exec(this, {
key: 'f858a2bc-b469-4e48-be67-0876339ee7e1',
configFile: 'cypress-with-project-id-without-video.config.js',
spec: 'a_record_instantfail.cy.js,b_record.cy.js',
record: true,
snapshot: true,
group: 'abc',
parallel: true,
ciBuildId: 'ciBuildId123',
expectedExitCode: 1,
})
expect(getRequestUrls()).deep.eq([
'POST /runs',
'POST /runs/00748421-e035-4a3d-8604-8468cc48bdb5/instances',
'POST /instances/e9e81b5e-cc58-4026-b2ff-8ae3161435a6/tests',
'POST /runs/00748421-e035-4a3d-8604-8468cc48bdb5/instances',
'POST /instances/e9e81b5e-cc58-4026-b2ff-8ae3161435a6/tests',
'POST /instances/e9e81b5e-cc58-4026-b2ff-8ae3161435a6/results',
'PUT /instances/e9e81b5e-cc58-4026-b2ff-8ae3161435a6/stdout',
'POST /runs/00748421-e035-4a3d-8604-8468cc48bdb5/instances',
])
})
})
context('video recording', () => {
describe('when video=false', () => {
setupStubbedServer(createRoutes())
it('does not upload when not enabled', async function () {
const { stdout } = await systemTests.exec(this, {
key: 'f858a2bc-b469-4e48-be67-0876339ee7e1',
configFile: 'cypress-with-project-id-without-video.config.js',
spec: 'record_pass*',
record: true,
snapshot: true,
config: {
env: {
'TEST_STDIO': '1',
},
},
})
console.log(stdout)
expect(stdout).to.include('Run URL:')
expect(stdout).to.include(runUrl)
const postRun = requests[0]
// ensure its relative to projectRoot
expect(postRun.body.specs).to.deep.eq([
'cypress/e2e/record_pass.cy.js',
])
const runResults = requests[3]
expect(runResults.body.video).to.be.false
})
})
describe('when videoUploadOnPasses=false', () => {
setupStubbedServer(createRoutes())
it('does not upload when specs pass', async function () {
const { stdout } = await systemTests.exec(this, {
key: 'f858a2bc-b469-4e48-be67-0876339ee7e1',
configFile: 'cypress-with-project-id.config.js',
spec: 'record_fail*,record_pass*',
record: true,
snapshot: true,
expectedExitCode: 1,
config: {
env: {
'TEST_STDIO': '1',
},
},
})
console.log(stdout)
expect(stdout).to.include('Run URL:')
expect(stdout).to.include(runUrl)
const postRun = requests[0]
// ensure its relative to projectRoot
expect(postRun.body.specs).to.deep.eq([
'cypress/e2e/record_fail.cy.js',
'cypress/e2e/record_pass.cy.js',
])
const recordFailSpecResults = requests[3]
expect(recordFailSpecResults.body.video).to.be.true // failed spec has video
const recordPassSpecResults = requests[9]
expect(recordPassSpecResults.body.video).to.be.false // passing spec does not have video
})
})
})
context('api interaction errors', () => {
describe('recordKey and projectId', () => {
const routes = createRoutes({
postRun: {
res (req, res) {
return res.sendStatus(401)
},
},
})
setupStubbedServer(routes)
it('errors and exits on 401', function () {
return systemTests.exec(this, {
key: 'f858a2bc-b469-4e48-be67-0876339ee7e1',
configFile: 'cypress-with-project-id.config.js',
spec: 'record_pass*',
record: true,
snapshot: true,
expectedExitCode: 1,
})
})
})
describe('project 404', () => {
const routes = createRoutes({
postRun: {
res (req, res) {
return res.sendStatus(404)
},
},
})
setupStubbedServer(routes)
it('errors and exits', function () {
return systemTests.exec(this, {
key: 'f858a2bc-b469-4e48-be67-0876339ee7e1',
configFile: 'cypress-with-project-id.config.js',
spec: 'record_pass*',
record: true,
snapshot: true,
expectedExitCode: 1,
})
})
})
describe('create run 500', () => {
const routes = createRoutes({
postRun: {
res (req, res) {
return res.sendStatus(500)
},
},
})
setupStubbedServer(routes)
it('errors and exits', function () {
process.env.DISABLE_API_RETRIES = 'true'
return systemTests.exec(this, {
key: 'f858a2bc-b469-4e48-be67-0876339ee7e1',
configFile: 'cypress-with-project-id.config.js',
spec: 'record_pass*',
record: true,
snapshot: true,
expectedExitCode: 1,
})
.then(() => {
const urls = getRequestUrls()
expect(urls).to.deep.eq([
'POST /runs',
])
})
})
it('when grouping without parallelization errors and exits', function () {
process.env.DISABLE_API_RETRIES = 'true'
return systemTests.exec(this, {
key: 'f858a2bc-b469-4e48-be67-0876339ee7e1',
configFile: 'cypress-with-project-id.config.js',
spec: 'record_pass*',
group: 'foo',
record: true,
snapshot: true,
ciBuildId: 'ciBuildId123',
expectedExitCode: 1,
})
.then(() => {
const urls = getRequestUrls()
expect(urls).to.deep.eq([
'POST /runs',
])
})
})
it('does not proceed and exits with error when parallelizing', function () {
process.env.DISABLE_API_RETRIES = 'true'
return systemTests.exec(this, {
key: 'f858a2bc-b469-4e48-be67-0876339ee7e1',
configFile: 'cypress-with-project-id.config.js',
spec: 'record_pass*',
group: 'foo',
tag: 'nightly',
record: true,
parallel: true,
snapshot: true,
ciBuildId: 'ciBuildId123',
expectedExitCode: 1,
})
.then(() => {
const urls = getRequestUrls()
expect(urls).to.deep.eq([
'POST /runs',
])
})
})
})
describe('create instance 500', () => {
const routes = createRoutes({
postRunInstance: {
res (req, res) {
return res.sendStatus(500)
},
},
})
setupStubbedServer(_.values(routes))
it('does not proceed and exits with error when parallelizing and creating instance', function () {
process.env.DISABLE_API_RETRIES = 'true'
return systemTests.exec(this, {
key: 'f858a2bc-b469-4e48-be67-0876339ee7e1',
configFile: 'cypress-with-project-id.config.js',
spec: 'record_pass*',
group: 'foo',
tag: 'nightly',
record: true,
parallel: true,
snapshot: true,
ciBuildId: 'ciBuildId123',
expectedExitCode: 1,
})
.then(() => {
const urls = getRequestUrls()
expect(urls).to.deep.eq([
'POST /runs',
`POST /runs/${runId}/instances`,
])
})
})
it('without parallelization - does not proceed', async function () {
process.env.DISABLE_API_RETRIES = 'true'
await systemTests.exec(this, {
key: 'f858a2bc-b469-4e48-be67-0876339ee7e1',
configFile: 'cypress-with-project-id.config.js',
spec: 'a_record.cy.js,b_record.cy.js',
record: true,
snapshot: true,
expectedExitCode: 1,
})
.then(() => {
const urls = getRequestUrls()
expect(urls).to.deep.eq([
'POST /runs',
'POST /runs/00748421-e035-4a3d-8604-8468cc48bdb5/instances',
])
})
})
})
describe('update instance 500', () => {
const routes = createRoutes({
postRunInstance: {
res (req, res) {
return res.json({
instanceId,
spec: 'cypress/e2e/record_pass.cy.js',
estimatedWallClockDuration: 5000,
totalInstances: 1,
claimedInstances: 1,