-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
run.coffee
1009 lines (815 loc) · 26.4 KB
/
run.coffee
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
_ = require("lodash")
pkg = require("@packages/root")
uuid = require("uuid")
path = require("path")
chalk = require("chalk")
human = require("human-interval")
debug = require("debug")("cypress:server:run")
Promise = require("bluebird")
logSymbols = require("log-symbols")
recordMode = require("./record")
errors = require("../errors")
Project = require("../project")
Reporter = require("../reporter")
browsers = require("../browsers")
openProject = require("../open_project")
videoCapture = require("../video_capture")
Windows = require("../gui/windows")
fs = require("../util/fs")
env = require("../util/env")
trash = require("../util/trash")
random = require("../util/random")
system = require("../util/system")
duration = require("../util/duration")
terminal = require("../util/terminal")
specsUtil = require("../util/specs")
humanTime = require("../util/human_time")
electronApp = require("../util/electron_app")
color = (val, c) ->
chalk[c](val)
gray = (val) ->
color(val, "gray")
colorIf = (val, c) ->
if val is 0
val = "-"
c = "gray"
color(val, c)
getSymbol = (num) ->
if num then logSymbols.error else logSymbols.success
formatBrowser = (browser) ->
## todo finish browser
_.compact([
browser.displayName,
browser.majorVersion,
browser.isHeadless and gray("(headless)")
]).join(" ")
formatFooterSummary = (results) ->
{ totalFailed, runs } = results
## pass or fail color
c = if totalFailed then "red" else "green"
phrase = do ->
## if we have any specs failing...
if not totalFailed
return "All specs passed!"
## number of specs
total = runs.length
failingRuns = _.filter(runs, "stats.failures").length
percent = Math.round(failingRuns / total * 100)
"#{failingRuns} of #{total} failed (#{percent}%)"
return [
color(phrase, c),
gray(duration.format(results.totalDuration)),
colorIf(results.totalTests, "reset"),
colorIf(results.totalPassed, "green"),
colorIf(totalFailed, "red"),
colorIf(results.totalPending, "cyan"),
colorIf(results.totalSkipped, "blue"),
]
formatSpecSummary = (name, failures) ->
[
getSymbol(failures),
color(name, "reset")
]
.join(" ")
formatRecordParams = (runUrl, parallel, group) ->
if runUrl
group or= false
"Group: #{group}, Parallel: #{Boolean(parallel)}"
formatSpecPattern = (specPattern) ->
if specPattern
specPattern.join(", ")
formatSpecs = (specs) ->
names = _.map(specs, "name")
## 25 found: (foo.spec.js, bar.spec.js, baz.spec.js)
[
"#{names.length} found "
gray("("),
gray(names.join(', ')),
gray(")")
]
.join("")
displayRunStarting = (options = {}) ->
{ specs, specPattern, browser, runUrl, parallel, group } = options
console.log("")
terminal.divider("=")
console.log("")
terminal.header("Run Starting", {
color: ["reset"]
})
console.log("")
table = terminal.table({
colWidths: [12, 88]
type: "outsideBorder"
})
data = _
.chain([
[gray("Cypress:"), pkg.version]
[gray("Browser:"), formatBrowser(browser)]
[gray("Specs:"), formatSpecs(specs)]
[gray("Searched:"), formatSpecPattern(specPattern)]
[gray("Params:"), formatRecordParams(runUrl, parallel, group)]
[gray("Run URL:"), runUrl]
])
.filter(_.property(1))
.value()
table.push(data...)
console.log(table.toString())
console.log("")
displaySpecHeader = (name, curr, total, estimated) ->
console.log("")
PADDING = 2
table = terminal.table({
colWidths: [80, 20]
colAligns: ["left", "right"]
type: "pageDivider"
style: {
"padding-left": PADDING
}
})
table.push(["", ""])
table.push([
"Running: " + gray(name + "..."),
gray("(#{curr} of #{total})")
])
console.log(table.toString())
if estimated
estimatedLabel = " ".repeat(PADDING) + "Estimated:"
console.log(estimatedLabel, gray(humanTime.long(estimated)))
collectTestResults = (obj = {}, estimated) ->
{
name: _.get(obj, 'spec.name')
tests: _.get(obj, 'stats.tests')
passes: _.get(obj, 'stats.passes')
pending: _.get(obj, 'stats.pending')
failures: _.get(obj, 'stats.failures')
skipped: _.get(obj, 'stats.skipped' )
duration: humanTime.long(_.get(obj, 'stats.wallClockDuration'))
estimated: estimated and humanTime.long(estimated)
screenshots: obj.screenshots and obj.screenshots.length
video: Boolean(obj.video)
}
renderSummaryTable = (runUrl) -> (results) ->
{ runs } = results
console.log("")
terminal.divider("=")
console.log("")
terminal.header("Run Finished", {
color: ["reset"]
})
if runs and runs.length
head = [" Spec", "", "Tests", "Passing", "Failing", "Pending", "Skipped"]
colAligns = ["left", "right", "right", "right", "right", "right", "right"]
colWidths = [39, 11, 10, 10, 10, 10, 10]
table1 = terminal.table({
colAligns
colWidths
type: "noBorder"
head: _.map(head, gray)
})
table2 = terminal.table({
colAligns
colWidths
type: "border"
})
table3 = terminal.table({
colAligns
colWidths
type: "noBorder"
head: formatFooterSummary(results)
style: {
"padding-right": 2
}
})
_.each runs, (run) ->
{ spec, stats } = run
ms = duration.format(stats.wallClockDuration)
table2.push([
formatSpecSummary(spec.name, stats.failures)
color(ms, "gray")
colorIf(stats.tests, "reset")
colorIf(stats.passes, "green"),
colorIf(stats.failures, "red"),
colorIf(stats.pending, "cyan"),
colorIf(stats.skipped, "blue")
])
console.log("")
console.log("")
console.log(terminal.renderTables(table1, table2, table3))
console.log("")
if runUrl
console.log("")
table4 = terminal.table({
colWidths: [100]
type: "pageDivider"
style: {
"padding-left": 2
}
})
table4.push(["", ""])
table4.push(["Recorded Run: " + gray(runUrl)])
console.log(terminal.renderTables(table4))
console.log("")
iterateThroughSpecs = (options = {}) ->
{ specs, runEachSpec, parallel, beforeSpecRun, afterSpecRun, config } = options
serial = ->
Promise.mapSeries(specs, runEachSpec)
serialWithRecord = ->
Promise
.mapSeries specs, (spec, index, length) ->
beforeSpecRun(spec)
.then ({ estimated }) ->
runEachSpec(spec, index, length, estimated)
.tap (results) ->
afterSpecRun(spec, results, config)
parallelWithRecord = (runs) ->
beforeSpecRun()
.then ({ spec, claimedInstances, totalInstances, estimated }) ->
## no more specs to run?
if not spec
## then we're done!
return runs
## find the actual spec object amongst
## our specs array since the API sends us
## the relative name
spec = _.find(specs, { relative: spec })
runEachSpec(spec, claimedInstances - 1, totalInstances, estimated)
.tap (results) ->
runs.push(results)
afterSpecRun(spec, results, config)
.then ->
## recurse
parallelWithRecord(runs)
switch
when parallel
## if we are running in parallel
## then ask the server for the next spec
parallelWithRecord([])
when beforeSpecRun
## else iterate serialially and record
## the results of each spec
serialWithRecord()
else
## else iterate in serial
serial()
getProjectId = (project, id) ->
id ?= env.get("CYPRESS_PROJECT_ID")
## if we have an ID just use it
if id
return Promise.resolve(id)
project
.getProjectId()
.catch ->
## no id no problem
return null
reduceRuns = (runs, prop) ->
_.reduce runs, (memo, run) ->
memo += _.get(run, prop)
, 0
getRun = (run, prop) ->
_.get(run, prop)
writeOutput = (outputPath, results) ->
Promise.try ->
return if not outputPath
debug("saving output results as %s", outputPath)
fs.outputJsonAsync(outputPath, results)
openProjectCreate = (projectRoot, socketId, options) ->
## now open the project to boot the server
## putting our web client app in headless mode
## - NO display server logs (via morgan)
## - YES display reporter results (via mocha reporter)
openProject.create(projectRoot, options, {
socketId
morgan: false
report: true
isTextTerminal: options.isTextTerminal
onError: (err) ->
console.log("")
if err.details
console.log(err.message)
console.log("")
console.log(chalk.yellow(err.details))
else
console.log(err.stack)
openProject.emit("exitEarlyWithErr", err.message)
})
.catch {portInUse: true}, (err) ->
## TODO: this needs to move to emit exitEarly
## so we record the failure in CI
errors.throw("PORT_IN_USE_LONG", err.port)
createAndOpenProject = (socketId, options) ->
{ projectRoot, projectId } = options
Project
.ensureExists(projectRoot)
.then ->
## open this project without
## adding it to the global cache
openProjectCreate(projectRoot, socketId, options)
.call("getProject")
.then (project) ->
Promise.props({
project
config: project.getConfig()
projectId: getProjectId(project, projectId)
})
removeOldProfiles = ->
browsers.removeOldProfiles()
.catch (err) ->
## dont make removing old browsers profiles break the build
errors.warning("CANNOT_REMOVE_OLD_BROWSER_PROFILES", err.stack)
trashAssets = (config = {}) ->
if config.trashAssetsBeforeRuns isnt true
return Promise.resolve()
Promise.join(
trash.folder(config.videosFolder)
trash.folder(config.screenshotsFolder)
)
.catch (err) ->
## dont make trashing assets fail the build
errors.warning("CANNOT_TRASH_ASSETS", err.stack)
module.exports = {
collectTestResults
getProjectId
writeOutput
openProjectCreate
createRecording: (name) ->
outputDir = path.dirname(name)
fs
.ensureDirAsync(outputDir)
.then ->
videoCapture.start(name, {
onError: (err) ->
## catch video recording failures and log them out
## but don't let this affect the run at all
errors.warning("VIDEO_RECORDING_FAILED", err.stack)
})
getElectronProps: (isHeaded, project, write) ->
obj = {
width: 1280
height: 720
show: isHeaded
onCrashed: ->
err = errors.get("RENDERER_CRASHED")
errors.log(err)
project.emit("exitEarlyWithErr", err.message)
onNewWindow: (e, url, frameName, disposition, options) ->
## force new windows to automatically open with show: false
## this prevents window.open inside of javascript client code
## to cause a new BrowserWindow instance to open
## https://github.com/cypress-io/cypress/issues/123
options.show = false
}
if write
obj.recordFrameRate = 20
obj.onPaint = (event, dirty, image) ->
write(image.toJPEG(100))
obj
displayResults: (obj = {}, estimated) ->
results = collectTestResults(obj, estimated)
c = if results.failures then "red" else "green"
console.log("")
terminal.header("Results", {
color: [c]
})
table = terminal.table({
type: "outsideBorder"
})
data = _.chain([
["Tests:", results.tests]
["Passing:", results.passes]
["Failing:", results.failures]
["Pending:", results.pending]
["Skipped:", results.skipped]
["Screenshots:", results.screenshots]
["Video:", results.video]
["Duration:", results.duration]
["Estimated:", results.estimated] if estimated
["Spec Ran:", results.name]
])
.compact()
.map (arr) ->
[key, val] = arr
[color(key, "gray"), color(val, c)]
.value()
table.push(data...)
console.log("")
console.log(table.toString())
console.log("")
displayScreenshots: (screenshots = []) ->
console.log("")
terminal.header("Screenshots", {color: ["yellow"]})
console.log("")
format = (s) ->
dimensions = gray("(#{s.width}x#{s.height})")
" - #{s.path} #{dimensions}"
screenshots.forEach (screenshot) ->
console.log(format(screenshot))
console.log("")
postProcessRecording: (end, name, cname, videoCompression, shouldUploadVideo) ->
debug("ending the video recording %o", { name, videoCompression, shouldUploadVideo })
## once this ended promises resolves
## then begin processing the file
end()
.then ->
## dont process anything if videoCompress is off
## or we've been told not to upload the video
return if videoCompression is false or shouldUploadVideo is false
console.log("")
terminal.header("Video", {
color: ["cyan"]
})
console.log("")
console.log(
gray(" - Started processing: "),
chalk.cyan("Compressing to #{videoCompression} CRF")
)
started = new Date
progress = Date.now()
throttle = env.get("VIDEO_COMPRESSION_THROTTLE") or human("10 seconds")
onProgress = (float) ->
switch
when float is 1
finished = new Date - started
dur = "(#{humanTime.long(finished)})"
console.log(
gray(" - Finished processing: "),
chalk.cyan(name),
gray(dur)
)
console.log("")
when (new Date - progress) > throttle
## bump up the progress so we dont
## continuously get notifications
progress += throttle
percentage = Math.ceil(float * 100) + "%"
console.log(" - Compression progress: ", chalk.cyan(percentage))
# bar.tickTotal(float)
videoCapture.process(name, cname, videoCompression, onProgress)
.catch {recordingVideoFailed: true}, (err) ->
## dont do anything if this error occured because
## recording the video had already failed
return
.catch (err) ->
## log that post processing was attempted
## but failed and dont let this change the run exit code
errors.warning("VIDEO_POST_PROCESSING_FAILED", err.stack)
launchBrowser: (options = {}) ->
{ browser, spec, write, project, screenshots, projectRoot } = options
browserOpts = switch browser.name
when "electron"
@getElectronProps(browser.isHeaded, project, write)
else
{}
browserOpts.automationMiddleware = {
onAfterResponse: (message, data, resp) =>
if message is "take:screenshot" and resp
screenshots.push @screenshotMetadata(data, resp)
resp
}
browserOpts.projectRoot = projectRoot
openProject.launch(browser, spec, browserOpts)
listenForProjectEnd: (project, exit) ->
new Promise (resolve) ->
if exit is false
resolve = (arg) ->
console.log("not exiting due to options.exit being false")
onEarlyExit = (errMsg) ->
## probably should say we ended
## early too: (Ended Early: true)
## in the stats
obj = {
error: errors.stripAnsi(errMsg)
stats: {
failures: 1
tests: 0
passes: 0
pending: 0
suites: 0
skipped: 0
wallClockDuration: 0
wallClockStartedAt: (new Date()).toJSON()
wallClockEndedAt: (new Date()).toJSON()
}
}
resolve(obj)
onEnd = (obj) ->
resolve(obj)
## when our project fires its end event
## resolve the promise
project.once("end", onEnd)
project.once("exitEarlyWithErr", onEarlyExit)
waitForBrowserToConnect: (options = {}) ->
{ project, socketId, timeout } = options
attempts = 0
do waitForBrowserToConnect = =>
Promise.join(
@waitForSocketConnection(project, socketId)
@launchBrowser(options)
)
.timeout(timeout ? 30000)
.catch Promise.TimeoutError, (err) =>
attempts += 1
console.log("")
## always first close the open browsers
## before retrying or dieing
openProject.closeBrowser()
.then ->
switch attempts
## try again up to 3 attempts
when 1, 2
word = if attempts is 1 then "Retrying..." else "Retrying again..."
errors.warning("TESTS_DID_NOT_START_RETRYING", word)
waitForBrowserToConnect()
else
err = errors.get("TESTS_DID_NOT_START_FAILED")
errors.log(err)
project.emit("exitEarlyWithErr", err.message)
waitForSocketConnection: (project, id) ->
debug("waiting for socket connection... %o", { id })
new Promise (resolve, reject) ->
fn = (socketId) ->
debug("got socket connection %o", { id: socketId })
if socketId is id
## remove the event listener if we've connected
project.removeListener("socket:connected", fn)
## resolve the promise
resolve()
## when a socket connects verify this
## is the one that matches our id!
project.on("socket:connected", fn)
waitForTestsToFinishRunning: (options = {}) ->
{ project, screenshots, started, end, name, cname, videoCompression, videoUploadOnPasses, exit, spec, estimated } = options
@listenForProjectEnd(project, exit)
.then (obj) =>
_.defaults(obj, {
error: null
hooks: null
tests: null
video: null
screenshots: null
reporterStats: null
})
if end
obj.video = name
if screenshots
obj.screenshots = screenshots
obj.spec = spec
finish = ->
return obj
@displayResults(obj, estimated)
if screenshots and screenshots.length
@displayScreenshots(screenshots)
{ tests, stats } = obj
failingTests = _.filter(tests, { state: "failed" })
hasFailingTests = _.get(stats, 'failures') > 0
## if we have a video recording
if started and tests and tests.length
## always set the video timestamp on tests
obj.tests = Reporter.setVideoTimestamp(started, tests)
## we should upload the video if we upload on passes (by default)
## or if we have any failures and have started the video
suv = Boolean(videoUploadOnPasses is true or (started and hasFailingTests))
obj.shouldUploadVideo = suv
debug("attempting to close the browser")
## always close the browser now as opposed to letting
## it exit naturally with the parent process due to
## electron bug in windows
openProject.closeBrowser()
.then =>
if end
@postProcessRecording(end, name, cname, videoCompression, suv)
.then(finish)
## TODO: add a catch here
else
finish()
screenshotMetadata: (data, resp) ->
{
screenshotId: random.id()
name: data.name ? null
testId: data.testId
takenAt: resp.takenAt
path: resp.path
height: resp.dimensions.height
width: resp.dimensions.width
}
runSpecs: (options = {}) ->
{ config, browser, sys, headed, outputPath, specs, specPattern, beforeSpecRun, afterSpecRun, runUrl, parallel, group } = options
isHeadless = browser.name is "electron" and not headed
browser.isHeadless = isHeadless
browser.isHeaded = not isHeadless
results = {
startedTestsAt: null
endedTestsAt: null
totalDuration: null
totalSuites: null,
totalTests: null,
totalFailed: null,
totalPassed: null,
totalPending: null,
totalSkipped: null,
runs: null,
browserPath: browser.path,
browserName: browser.name,
browserVersion: browser.version,
osName: sys.osName,
osVersion: sys.osVersion,
cypressVersion: pkg.version,
runUrl: runUrl,
config,
}
displayRunStarting({
specs
group
runUrl
browser
parallel
specPattern
})
runEachSpec = (spec, index, length, estimated) =>
displaySpecHeader(spec.name, index + 1, length, estimated)
@runSpec(spec, options, estimated)
.get("results")
.tap (results) ->
debug("spec results %o", results)
iterateThroughSpecs({
specs
config
parallel
runEachSpec
afterSpecRun
beforeSpecRun
})
.then (runs = []) ->
results.startedTestsAt = start = getRun(_.first(runs), "stats.wallClockStartedAt")
results.endedTestsAt = end = getRun(_.last(runs), "stats.wallClockEndedAt")
results.totalDuration = reduceRuns(runs, "stats.wallClockDuration")
results.totalSuites = reduceRuns(runs, "stats.suites")
results.totalTests = reduceRuns(runs, "stats.tests")
results.totalPassed = reduceRuns(runs, "stats.passes")
results.totalPending = reduceRuns(runs, "stats.pending")
results.totalFailed = reduceRuns(runs, "stats.failures")
results.totalSkipped = reduceRuns(runs, "stats.skipped")
results.runs = runs
debug("final results of all runs: %o", results)
writeOutput(outputPath, results)
.return(results)
runSpec: (spec = {}, options = {}, estimated) ->
{ project, browser, video, videosFolder } = options
{ isHeadless, isHeaded } = browser
browserName = browser.name
debug("about to run spec %o", {
spec
isHeadless
browserName
})
screenshots = []
## we know we're done running headlessly
## when the renderer has connected and
## finishes running all of the tests.
## we're using an event emitter interface
## to gracefully handle this in promise land
## if we've been told to record and we're not spawning a headed browser
browserCanBeRecorded = (name) ->
name is "electron" and isHeadless
if video
if browserCanBeRecorded(browserName)
if not videosFolder
throw new Error("Missing videoFolder for recording")
name = path.join(videosFolder, spec.name + ".mp4")
cname = path.join(videosFolder, spec.name + "-compressed.mp4")
recording = @createRecording(name)
else
console.log("")
if browserName is "electron" and isHeaded
errors.warning("CANNOT_RECORD_VIDEO_HEADED")
else
errors.warning("CANNOT_RECORD_VIDEO_FOR_THIS_BROWSER", browserName)
Promise.resolve(recording)
.then (props = {}) =>
## extract the started + ended promises from recording
{start, end, write} = props
## make sure we start the recording first
## before doing anything
Promise.resolve(start)
.then (started) =>
Promise.props({
results: @waitForTestsToFinishRunning({
end
name
spec
cname
started
project
estimated
screenshots
exit: options.exit
videoCompression: options.videoCompression
videoUploadOnPasses: options.videoUploadOnPasses
}),
connection: @waitForBrowserToConnect({
spec
write
project
browser
screenshots
socketId: options.socketId
webSecurity: options.webSecurity
projectRoot: options.projectRoot
})
})
findSpecs: (config, specPattern) ->
specsUtil.find(config, specPattern)
.tap (specs = []) =>
if debug.enabled
names = _.map(specs, "name")
debug(
"found '%d' specs using spec pattern '%s': %o",
names.length,
specPattern,
names
)
ready: (options = {}) ->
debug("run mode ready with options %o", options)
_.defaults(options, {
isTextTerminal: true
browser: "electron"
})
socketId = random.id()
{ projectRoot, record, key, ciBuildId, parallel, group } = options
browserName = options.browser
## alias and coerce to null
specPattern = options.spec ? null
## warn if we're using deprecated --ci flag
recordMode.warnIfCiFlag(options.ci)
## ensure the project exists
## and open up the project
createAndOpenProject(socketId, options)
.then ({ project, projectId, config }) =>
## if we have a project id and a key but record hasnt been given
recordMode.warnIfProjectIdButNoRecordOption(projectId, options)
recordMode.throwIfRecordParamsWithoutRecording(record, ciBuildId, parallel, group)
if record
recordMode.throwIfNoProjectId(projectId)
recordMode.throwIfIncorrectCiBuildIdUsage(ciBuildId, parallel, group)
recordMode.throwIfIndeterminateCiBuildId(ciBuildId, parallel, group)
Promise.all([
system.info(),
browsers.ensureAndGetByName(browserName),
@findSpecs(config, specPattern),
trashAssets(config),
removeOldProfiles()
])
.spread (sys = {}, browser = {}, specs = []) =>
## return only what is return to the specPattern
if specPattern
specPattern = specsUtil.getPatternRelativeToProjectRoot(specPattern, projectRoot)
if not specs.length
errors.throw('NO_SPECS_FOUND', config.integrationFolder, specPattern)
runAllSpecs = ({ beforeSpecRun, afterSpecRun, runUrl }, parallelOverride = parallel) =>
@runSpecs({
beforeSpecRun
afterSpecRun
projectRoot
specPattern
socketId
parallel: parallelOverride
browser
project
runUrl
group
config
specs
sys
videosFolder: config.videosFolder
video: config.video
videoCompression: config.videoCompression
videoUploadOnPasses: config.videoUploadOnPasses
exit: options.exit
headed: options.headed
outputPath: options.outputPath
})
.tap(renderSummaryTable(runUrl))
if record
{ projectName } = config
recordMode.createRunAndRecordSpecs({
key
sys
specs
group
browser
parallel
ciBuildId
projectId
projectRoot
projectName
specPattern
runAllSpecs
})
else
## not recording, can't be parallel