Skip to content

Commit

Permalink
refactoring console status log
Browse files Browse the repository at this point in the history
  • Loading branch information
winsonwq committed Jun 8, 2014
1 parent 3ea8275 commit 2664699
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
18 changes: 7 additions & 11 deletions src/console.status.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,27 @@ Viff = require './viff'

durationFormat = (duration) -> (duration / 1000).toFixed(2) + 's'

module.exports = (viff) ->
module.exports =

exceptions = []
logBefore: (cases) -> console.log 'Viff is taking screenshots...\n'

# clean the images and report.json
viff.on 'before', (cases) -> console.log 'Viff is taking screenshots...\n'

viff.on 'afterEach', (_case, duration, fex, tex) ->
logAfterEach: (_case, duration, fex, tex, exceptions = []) ->
if fex or tex
exceptions.push { fex: fex, tex: tex, key: _case.key() }
console.log " #{(exceptions.length + ')').error} #{_case.browser.error} #{_case.key().error} "
else
else
drationStr = "(#{durationFormat(duration)})".greyColor
console.log " - #{_case.browser.info} #{_case.key().greyColor} #{drationStr}"

# generate report.json
viff.on 'after', (cases, duration) ->
logAfter: (cases, duration, exceptions = []) ->
console.log "\nDone in #{durationFormat(duration)}, #{(exceptions.length + ' failed.').greyColor}\n"

if total = exceptions.length
while ex = exceptions.shift()
fexMsg = ex.fex.message + '\n\n' if ex.fex?.message?
texMsg = ex.tex.message + '\n\n' if ex.tex?.message?
texMsg = ex.tex.message + '\n\n' if ex.tex?.message?
title = (total - exceptions.length) + ') ' + ex.key + '\n'
message = " #{title}#{fexMsg.error}#{texMsg.error}".replace(/\n/g, '\n ')
console.error message

console.error ''
console.error ''
12 changes: 8 additions & 4 deletions src/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,24 @@ config = processArgs process.argv
return console.log config if _.isString config

viff = new Viff config.seleniumHost

consoleStatus viff
exceptions = []

# clean the images and report.json
viff.on 'before', (cases) -> imgGen.reset();
viff.on 'before', (cases) ->
imgGen.reset()
consoleStatus.logBefore()

# generate images by each case
viff.on 'afterEach', (_case, duration) -> imgGen.generateByCase _case if duration != 0
viff.on 'afterEach', (_case, duration, fex, tex) ->
imgGen.generateByCase _case if duration != 0
consoleStatus.logAfterEach _case, duration, fex, tex, exceptions

# generate report.json
viff.on 'after', (cases, duration) ->
imgGen.generateReport cases
resemble.exit()
partialCanvas.exit()
consoleStatus.logAfter cases, duration, exceptions

cases = Viff.constructCases config.browsers, config.envHosts, config.paths
viff.run cases
15 changes: 10 additions & 5 deletions src/viffs.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,27 @@ config = processArgs process.argv

return console.log config if _.isString config

count = 3
count = config.maxInstance ? 2

cases = Viff.constructCases config.browsers, config.envHosts, config.paths
testGroups = Viff.split cases, count
resolvedCases = []
exceptions = []

imgGen.reset();
imgGen.reset()
consoleStatus.logBefore()

for group in testGroups
viff = new Viff config.seleniumHost
viff.on 'afterEach', (_case, duration) -> imgGen.generateByCase _case if duration != 0
consoleStatus viff

viff.run group, ([cases, endTime]) ->
viff.on 'afterEach', (_case, duration, fex, tex) ->
imgGen.generateByCase _case if duration != 0
consoleStatus.logAfterEach _case, duration, fex, tex, exceptions

viff.run group, ([cases, duration]) ->
resolvedCases = resolvedCases.concat cases
unless --count
imgGen.generateReport resolvedCases
resemble.exit()
partialCanvas.exit()
consoleStatus.logAfter resolvedCases, duration, exceptions

0 comments on commit 2664699

Please sign in to comment.