mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2025-01-07 23:59:22 +03:00
Log longest specs/suites during grunt test
This commit is contained in:
parent
3e626f28c4
commit
e40d837b40
@ -15,6 +15,7 @@ module.exports.runSpecSuite = (specSuite, logErrors=true) ->
|
|||||||
|
|
||||||
$ = require 'jquery'
|
$ = require 'jquery'
|
||||||
TimeReporter = require 'time-reporter'
|
TimeReporter = require 'time-reporter'
|
||||||
|
timeReporter = new TimeReporter()
|
||||||
|
|
||||||
if atom.getLoadSettings().exitWhenDone
|
if atom.getLoadSettings().exitWhenDone
|
||||||
{jasmineNode} = require 'jasmine-node/lib/jasmine-node/reporter'
|
{jasmineNode} = require 'jasmine-node/lib/jasmine-node/reporter'
|
||||||
@ -22,6 +23,10 @@ module.exports.runSpecSuite = (specSuite, logErrors=true) ->
|
|||||||
print: (args...) ->
|
print: (args...) ->
|
||||||
process.stderr.write(args...)
|
process.stderr.write(args...)
|
||||||
onComplete: (runner) ->
|
onComplete: (runner) ->
|
||||||
|
process.stdout.write('\n')
|
||||||
|
timeReporter.logLongestSuites 10, (line) -> process.stdout.write("#{line}\n")
|
||||||
|
process.stdout.write('\n')
|
||||||
|
timeReporter.logLongestSpecs 10, (line) -> process.stdout.write("#{line}\n")
|
||||||
atom.exit(runner.results().failedCount > 0 ? 1 : 0)
|
atom.exit(runner.results().failedCount > 0 ? 1 : 0)
|
||||||
else
|
else
|
||||||
AtomReporter = require 'atom-reporter'
|
AtomReporter = require 'atom-reporter'
|
||||||
@ -31,7 +36,7 @@ module.exports.runSpecSuite = (specSuite, logErrors=true) ->
|
|||||||
|
|
||||||
jasmineEnv = jasmine.getEnv()
|
jasmineEnv = jasmine.getEnv()
|
||||||
jasmineEnv.addReporter(reporter)
|
jasmineEnv.addReporter(reporter)
|
||||||
jasmineEnv.addReporter(new TimeReporter())
|
jasmineEnv.addReporter(timeReporter)
|
||||||
|
|
||||||
$('body').append $$ -> @div id: 'jasmine-content'
|
$('body').append $$ -> @div id: 'jasmine-content'
|
||||||
|
|
||||||
|
@ -1,52 +1,59 @@
|
|||||||
_ = require 'underscore'
|
_ = require 'underscore'
|
||||||
|
|
||||||
module.exports =
|
module.exports =
|
||||||
class TimeReporter extends jasmine.Reporter
|
class TimeReporter extends jasmine.Reporter
|
||||||
|
|
||||||
constructor: ->
|
constructor: ->
|
||||||
window.timedSpecs = []
|
window.timedSpecs = []
|
||||||
window.timedSuites = {}
|
window.timedSuites = {}
|
||||||
|
|
||||||
window.logLongestSpec = -> window.logLongestSpecs(1)
|
window.logLongestSpec = => @logLongestSpecs(1)
|
||||||
|
window.logLongestSpecs = (number) => @logLongestSpecs(number)
|
||||||
|
window.logLongestSuite = => @logLongestSuites(1)
|
||||||
|
window.logLongestSuites = (number) => @logLongestSuites(number)
|
||||||
|
|
||||||
window.logLongestSpecs = (number=10) =>
|
logLongestSuites: (number=10, log) ->
|
||||||
console.log "#{number} longest running specs:"
|
log ?= (line) -> console.log(line)
|
||||||
for spec in _.sortBy(window.timedSpecs, (spec) -> -spec.time)[0...number]
|
log "Longest running suites:"
|
||||||
console.log "#{spec.time}ms"
|
suites = _.map(window.timedSuites, (key, value) -> [value, key])
|
||||||
console.log spec.description
|
for suite in _.sortBy(suites, (suite) => -suite[1])[0...number]
|
||||||
|
log " #{suite[0]} (#{suite[1]}ms)"
|
||||||
|
|
||||||
window.logLongestSuite = -> window.logLongestSuites(1)
|
logLongestSpecs: (number=10, log) ->
|
||||||
|
log ?= (line) -> console.log(line)
|
||||||
window.logLongestSuites = (number=10) =>
|
log "Longest running specs:"
|
||||||
console.log "#{number} longest running suites:"
|
for spec in _.sortBy(window.timedSpecs, (spec) -> -spec.time)[0...number]
|
||||||
suites = _.map(window.timedSuites, (key, value) -> [value, key])
|
log spec.description
|
||||||
for suite in _.sortBy(suites, (suite) => -suite[1])[0...number]
|
|
||||||
console.log suite[0], suite[1]
|
|
||||||
|
|
||||||
reportSpecStarting: (spec) ->
|
reportSpecStarting: (spec) ->
|
||||||
stack = [spec.description]
|
@stack = [spec.description]
|
||||||
suite = spec.suite
|
suite = spec.suite
|
||||||
while suite
|
while suite
|
||||||
stack.unshift suite.description
|
@stack.unshift suite.description
|
||||||
@suite = suite.description
|
@suite = suite.description
|
||||||
suite = suite.parentSuite
|
suite = suite.parentSuite
|
||||||
|
|
||||||
@time = new Date().getTime()
|
@time = new Date().getTime()
|
||||||
reducer = (memo, description, index) ->
|
|
||||||
"#{memo}#{_.multiplyString(' ', index)}#{description}\n"
|
|
||||||
@description = _.reduce(stack, reducer, "")
|
|
||||||
|
|
||||||
reportSpecResults: (spec) ->
|
reportSpecResults: (spec) ->
|
||||||
return unless @time? and @description?
|
return unless @time? and @stack?
|
||||||
|
|
||||||
duration = new Date().getTime() - @time
|
duration = new Date().getTime() - @time
|
||||||
|
reducer = (memo, description, index) ->
|
||||||
|
if index is 0
|
||||||
|
"#{description} (#{duration}ms)\n"
|
||||||
|
else
|
||||||
|
"#{memo}#{_.multiplyString(' ', index)}#{description}\n"
|
||||||
|
description = _.reduce(@stack, reducer, '')
|
||||||
|
|
||||||
window.timedSpecs.push
|
window.timedSpecs.push
|
||||||
description: @description
|
description: description
|
||||||
time: duration
|
time: duration
|
||||||
name: spec.getFullName()
|
name: spec.getFullName()
|
||||||
if timedSuites[@suite]
|
if timedSuites[@suite]
|
||||||
window.timedSuites[@suite] += duration
|
window.timedSuites[@suite] += duration
|
||||||
else
|
else
|
||||||
window.timedSuites[@suite] = duration
|
window.timedSuites[@suite] = duration
|
||||||
|
|
||||||
@time = null
|
@time = null
|
||||||
@description = null
|
@stack = null
|
||||||
|
Loading…
Reference in New Issue
Block a user