From 266469953312eaee99557ebdd6113596ff598849 Mon Sep 17 00:00:00 2001 From: Wang Qiu Date: Sun, 8 Jun 2014 18:15:21 +0800 Subject: [PATCH] refactoring console status log --- src/console.status.coffee | 18 +++++++----------- src/index.coffee | 12 ++++++++---- src/viffs.coffee | 15 ++++++++++----- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/console.status.coffee b/src/console.status.coffee index 3a5603c..df4255f 100644 --- a/src/console.status.coffee +++ b/src/console.status.coffee @@ -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 '' \ No newline at end of file + console.error '' diff --git a/src/index.coffee b/src/index.coffee index 11f8b94..66d183b 100644 --- a/src/index.coffee +++ b/src/index.coffee @@ -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 diff --git a/src/viffs.coffee b/src/viffs.coffee index 432bab9..d553a17 100644 --- a/src/viffs.coffee +++ b/src/viffs.coffee @@ -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