Skip to content

Commit

Permalink
create and implement slowTestThreshold cypress option
Browse files Browse the repository at this point in the history
  • Loading branch information
wesmangum committed Nov 3, 2017
1 parent 6ec4975 commit 53737ec
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
4 changes: 3 additions & 1 deletion packages/server/lib/config.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ cypressEnvRe = /^(cypress_)/i
dashesOrUnderscoresRe = /^(_-)+/

folders = "fileServerFolder videosFolder supportFolder fixturesFolder integrationFolder screenshotsFolder unitFolder supportFile".split(" ")
configKeys = "port reporter reporterOptions baseUrl execTimeout defaultCommandTimeout pageLoadTimeout requestTimeout responseTimeout numTestsKeptInMemory screenshotOnHeadlessFailure waitForAnimations animationDistanceThreshold watchForFileChanges trashAssetsBeforeHeadlessRuns chromeWebSecurity videoRecording videoCompression videoUploadOnPasses viewportWidth viewportHeight supportFile fileServerFolder supportFolder fixturesFolder integrationFolder videosFolder screenshotsFolder environmentVariables hosts".split(" ")
configKeys = "port reporter reporterOptions baseUrl execTimeout defaultCommandTimeout pageLoadTimeout requestTimeout responseTimeout numTestsKeptInMemory screenshotOnHeadlessFailure waitForAnimations animationDistanceThreshold watchForFileChanges trashAssetsBeforeHeadlessRuns chromeWebSecurity videoRecording videoCompression videoUploadOnPasses viewportWidth viewportHeight supportFile fileServerFolder supportFolder fixturesFolder integrationFolder videosFolder screenshotsFolder environmentVariables hosts slowTestThreshold".split(" ")

isCypressEnvLike = (key) ->
cypressEnvRe.test(key) and key isnt "CYPRESS_ENV"
Expand All @@ -42,6 +42,7 @@ defaults = {
responseTimeout: 30000
pageLoadTimeout: 60000
execTimeout: 60000
slowTestThreshold: 5000
videoRecording: true
videoCompression: 32
videoUploadOnPasses: true
Expand Down Expand Up @@ -85,6 +86,7 @@ validationRules = {
requestTimeout: v.isNumber
responseTimeout: v.isNumber
screenshotOnHeadlessFailure: v.isBoolean
slowTestThreshold: v.isNumber
supportFile: v.isStringOrFalse
trashAssetsBeforeHeadlessRuns: v.isBoolean
videoCompression: v.isNumberOrFalse
Expand Down
2 changes: 1 addition & 1 deletion packages/server/lib/project.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class Project extends EE
paths = Reporter.getSearchPathsForReporter(config.reporter, config.projectRoot)
errors.throw("INVALID_REPORTER_NAME", config.reporter, paths)

reporter = Reporter.create(config.reporter, config.reporterOptions, config.projectRoot)
reporter = Reporter.create(config.reporter, config.reporterOptions, config.projectRoot, config.slowTestThreshold)

@automation = Automation.create(config.namespace, config.socketIoCookie, config.screenshotsFolder)

Expand Down
26 changes: 19 additions & 7 deletions packages/server/lib/reporter.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,24 @@ mochaReporters = require("mocha/lib/reporters")

STATS = "suites tests passes pending failures start end duration".split(" ")

createSuite = (obj, parent) ->
parseOptions = (obj, slowTestThreshold) ->
_.extend(obj, {
_slow: slowTestThreshold
})
return obj

createSuite = (obj, parent, slowTestThreshold) ->
suite = new Mocha.Suite(obj.title, {})
suite.parent = parent if parent
if obj.file
console.log('has file:', obj.file)
suite.file = obj.file

suite = parseOptions(suite, slowTestThreshold)

return suite

createRunnable = (obj, parent) ->
createRunnable = (obj, parent, slowTestThreshold) ->
{body} = obj

if body
Expand All @@ -33,6 +42,8 @@ createRunnable = (obj, parent) ->

runnable.parent = parent if parent

runnable = parseOptions(runnable, slowTestThreshold)

return runnable

mergeRunnable = (testProps, runnables) ->
Expand Down Expand Up @@ -74,13 +85,14 @@ reporters = {
}

class Reporter
constructor: (reporterName = "spec", reporterOptions = {}, projectRoot) ->
constructor: (reporterName = "spec", reporterOptions = {}, projectRoot, slowTestThreshold) ->
if not (@ instanceof Reporter)
return new Reporter(reporterName)

@reporterName = reporterName
@projectRoot = projectRoot
@reporterOptions = reporterOptions
@slowTestThreshold = slowTestThreshold

setRunnables: (rootRunnable = {}) ->
@runnables = {}
Expand All @@ -96,14 +108,14 @@ class Reporter
_createRunnable: (runnableProps, type, parent) ->
runnable = switch type
when "suite"
suite = createSuite(runnableProps, parent)
suite = createSuite(runnableProps, parent, @slowTestThreshold)
suite.tests = _.map runnableProps.tests, (testProps) =>
@_createRunnable(testProps, "test", suite)
suite.suites = _.map runnableProps.suites, (suiteProps) =>
@_createRunnable(suiteProps, "suite", suite)
suite
when "test"
createRunnable(runnableProps, parent)
createRunnable(runnableProps, parent, @slowTestThreshold)
else
throw new Error("Unknown runnable type: '#{type}'")

Expand Down Expand Up @@ -166,8 +178,8 @@ class Reporter
test.videoTimestamp = test.started - videoStart
test

@create = (reporterName, reporterOptions, projectRoot) ->
new Reporter(reporterName, reporterOptions, projectRoot)
@create = (reporterName, reporterOptions, projectRoot, slowTestThreshold) ->
new Reporter(reporterName, reporterOptions, projectRoot, slowTestThreshold)

@loadReporter = (reporterName, projectRoot) ->
log("loading reporter #{reporterName}")
Expand Down

0 comments on commit 53737ec

Please sign in to comment.