Skip to content

Commit 776b730

Browse files
Blue Fchrisbreiding
Blue F
andauthored
feat: Add 'slowTestThreshold' and fix this.slow() inside specs (#18496)
Co-authored-by: Chris Breiding <chrisbreiding@users.noreply.github.com>
1 parent c027f28 commit 776b730

16 files changed

+1325
-798
lines changed

cli/schema/cypress.schema.json

+5
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@
4444
"default": null,
4545
"description": "The reporter options used. Supported options depend on the reporter. See https://on.cypress.io/reporters#Reporter-Options"
4646
},
47+
"slowTestThreshold": {
48+
"type": "number",
49+
"default": 10000,
50+
"description": "Slow test threshold in milliseconds. Only affects the visual output of some reporters. For example, the spec reporter will display the test time in yellow if over the threshold. See https://on.cypress.io/configuration#Timeouts"
51+
},
4752
"testFiles": {
4853
"type": [
4954
"string",

cli/types/cypress-npm-api.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ declare namespace CypressCommandLine {
9191
* Specify mocha reporter options
9292
*/
9393
reporterOptions: any
94+
/**
95+
* Slow test threshold in milliseconds. Only affects the visual output of some reporters. For example, the spec reporter will display the test time in yellow if over the threshold.
96+
*/
97+
slowTestThreshold: number
9498
/**
9599
* Specify the specs to run
96100
*/

cli/types/cypress.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -2577,6 +2577,11 @@ declare namespace Cypress {
25772577
* @default "spec"
25782578
*/
25792579
reporterOptions: { [key: string]: any }
2580+
/**
2581+
* Slow test threshold in milliseconds. Only affects the visual output of some reporters. For example, the spec reporter will display the test time in yellow if over the threshold.
2582+
* @default 10000
2583+
*/
2584+
slowTestThreshold: number
25802585
/**
25812586
* Whether Cypress will watch and restart tests on test file changes
25822587
* @default true

packages/driver/src/cypress/mocha.ts

+2
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,8 @@ const create = (specWindow, Cypress, config) => {
500500

501501
const _mocha = createMocha(specWindow)
502502

503+
_mocha.slow(config('slowTestThreshold'))
504+
503505
const _runner = getRunner(_mocha)
504506

505507
_mocha.suite.file = Cypress.spec.relative

packages/driver/src/cypress/runner.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const TEST_BEFORE_RUN_EVENT = 'runner:test:before:run'
2121
const TEST_AFTER_RUN_EVENT = 'runner:test:after:run'
2222

2323
const RUNNABLE_LOGS = 'routes agents commands hooks'.split(' ')
24-
const RUNNABLE_PROPS = '_testConfig id order title _titlePath root hookName hookId err state failedFromHookId body speed type duration wallClockStartedAt wallClockDuration timings file originalTitle invocationDetails final currentRetry retries'.split(' ')
24+
const RUNNABLE_PROPS = '_testConfig id order title _titlePath root hookName hookId err state failedFromHookId body speed type duration wallClockStartedAt wallClockDuration timings file originalTitle invocationDetails final currentRetry retries _slow'.split(' ')
2525

2626
const debug = debugFn('cypress:driver:runner')
2727
const debugErrors = debugFn('cypress:driver:errors')
@@ -581,6 +581,10 @@ const normalize = (runnable, tests, initialTests, onRunnable, onLogsById, getRun
581581
wrappedRunnable._testConfig = cfg
582582
}
583583

584+
if (cfg.slowTestThreshold) {
585+
runnable.slow(cfg.slowTestThreshold)
586+
}
587+
584588
wrappedRunnable._titlePath = runnable.titlePath()
585589
}
586590

0 commit comments

Comments
 (0)