Skip to content

Commit

Permalink
revert: "Merge pull request #1791 from budde377/feature-adding-no-col…
Browse files Browse the repository at this point in the history
…ors-to-run-command"

This reverts commit 56073fc, reversing
changes made to b7d591f.

Fixes #1894, #1895
  • Loading branch information
dignifiedquire committed Feb 12, 2016
1 parent c6076bd commit 96ebdc4
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 87 deletions.
3 changes: 0 additions & 3 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,6 @@ var describeRun = function () {
.describe('fail-on-empty-test-suite', 'Fail on empty test suite.')
.describe('no-fail-on-empty-test-suite', 'Do not fail on empty test suite.')
.describe('help', 'Print usage.')
.describe('log-level', '<disable | error | warn | info | debug> Level of logging.')
.describe('colors', 'Use colors when reporting and printing logs.')
.describe('no-colors', 'Do not use colors when reporting or printing logs.')
}

var describeCompletion = function () {
Expand Down
13 changes: 11 additions & 2 deletions lib/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var exec = require('child_process').exec

var helper = require('./helper')
var logger = require('./logger')
var constant = require('./constants')

var log = logger.create('init')

Expand Down Expand Up @@ -210,13 +211,21 @@ var processAnswers = function (answers, basePath, testMainFile) {
}

exports.init = function (config) {
logger.setupFromConfig(config)

var useColors = true
var logLevel = constant.LOG_INFO
var colorScheme = COLOR_SCHEME.ON

if (helper.isDefined(config.colors)) {
colorScheme = config.colors ? COLOR_SCHEME.ON : COLOR_SCHEME.OFF
useColors = config.colors
}

if (helper.isDefined(config.logLevel)) {
logLevel = config.logLevel
}

logger.setup(logLevel, useColors)

// need to be registered before creating readlineInterface
process.stdin.on('keypress', function (s, key) {
sm.onKeypress(key)
Expand Down
24 changes: 0 additions & 24 deletions lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,6 @@ var setup = function (level, colors, appenders) {
})
}

// Setup the logger by passing in the config object. The function sets the
// `colors` and `logLevel` if they are defined. It takes two arguments:
//
// setupFromConfig(config, appenders)
//
// * `config`: *Object* The configuration object.
// * `appenders`: *Array* This will be passed as appenders to log4js
// to allow for fine grained configuration of log4js. For more information
// see https://github.com/nomiddlename/log4js-node.
var setupFromConfig = function (config, appenders) {
var useColors = true
var logLevel = constant.LOG_INFO

if (helper.isDefined(config.colors)) {
useColors = config.colors
}

if (helper.isDefined(config.logLevel)) {
logLevel = config.logLevel
}
setup(logLevel, useColors, appenders)
}

// Create a new logger. There are two optional arguments
// * `name`, which defaults to `karma` and
// If the `name = 'socket.io'` this will create a special wrapper
Expand All @@ -83,4 +60,3 @@ var create = function (name, level) {

exports.create = create
exports.setup = setup
exports.setupFromConfig = setupFromConfig
4 changes: 2 additions & 2 deletions lib/middleware/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ var createRunnerMiddleware = function (emitter, fileList, capturedBrowsers, repo
response.write('Waiting for previous execution...\n')
}

var data = request.body
emitter.once('run_start', function () {
var responseWrite = response.write.bind(response)
responseWrite.colors = data.colors

reporter.addAdapter(responseWrite)

// clean up, close runner response
Expand All @@ -47,6 +46,7 @@ var createRunnerMiddleware = function (emitter, fileList, capturedBrowsers, repo
})
})

var data = request.body
log.debug('Setting client.args to ', data.args)
config.client.args = data.args

Expand Down
6 changes: 2 additions & 4 deletions lib/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,8 @@ var createReporters = function (names, config, emitter, injector) {
// TODO(vojta): instantiate all reporters through DI
names.forEach(function (name) {
if (['dots', 'progress'].indexOf(name) !== -1) {
var Cls = require('./reporters/' + name)
var ClsColor = require('./reporters/' + name + '_color')
reporters.push(new Cls(errorFormatter, config.reportSlowerThan, config.colors))
return reporters.push(new ClsColor(errorFormatter, config.reportSlowerThan, config.colors))
var Cls = require('./reporters/' + name + (config.colors ? '_color' : ''))
return reporters.push(new Cls(errorFormatter, config.reportSlowerThan))
}

var locals = {
Expand Down
14 changes: 4 additions & 10 deletions lib/reporters/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var util = require('util')

var helper = require('../helper')

var BaseReporter = function (formatError, reportSlow, useColors, adapter) {
var BaseReporter = function (formatError, reportSlow, adapter) {
this.adapters = [adapter || process.stdout.write.bind(process.stdout)]

this.onRunStart = function () {
Expand Down Expand Up @@ -46,15 +46,9 @@ var BaseReporter = function (formatError, reportSlow, useColors, adapter) {

this.write = function () {
var msg = util.format.apply(null, Array.prototype.slice.call(arguments))
var self = this
this.adapters.forEach(function (adapter) {
if (!helper.isDefined(adapter.colors)) {
adapter.colors = useColors
}

if (adapter.colors === self.USE_COLORS) {
return adapter(msg)
}
this.adapters.forEach(function (adapter) {
adapter(msg)
})
}

Expand Down Expand Up @@ -142,7 +136,7 @@ BaseReporter.decoratorFactory = function (formatError, reportSlow) {
}
}

BaseReporter.decoratorFactory.$inject = ['formatError', 'config.reportSlowerThan', 'config.colors']
BaseReporter.decoratorFactory.$inject = ['formatError', 'config.reportSlowerThan']

// PUBLISH
module.exports = BaseReporter
4 changes: 2 additions & 2 deletions lib/reporters/dots.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var BaseReporter = require('./base')

var DotsReporter = function (formatError, reportSlow, useColors) {
BaseReporter.call(this, formatError, reportSlow, useColors)
var DotsReporter = function (formatError, reportSlow) {
BaseReporter.call(this, formatError, reportSlow)

var DOTS_WRAP = 80

Expand Down
4 changes: 2 additions & 2 deletions lib/reporters/dots_color.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var DotsReporter = require('./dots')
var BaseColorReporter = require('./base_color')

var DotsColorReporter = function (formatError, reportSlow, useColors) {
DotsReporter.call(this, formatError, reportSlow, useColors)
var DotsColorReporter = function (formatError, reportSlow) {
DotsReporter.call(this, formatError, reportSlow)
BaseColorReporter.call(this)
}

Expand Down
4 changes: 2 additions & 2 deletions lib/reporters/progress.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var BaseReporter = require('./base')

var ProgressReporter = function (formatError, reportSlow, useColors) {
BaseReporter.call(this, formatError, reportSlow, useColors)
var ProgressReporter = function (formatError, reportSlow) {
BaseReporter.call(this, formatError, reportSlow)

this.writeCommonMsg = function (msg) {
this.write(this._remove() + msg + this._render())
Expand Down
4 changes: 2 additions & 2 deletions lib/reporters/progress_color.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var ProgressReporter = require('./progress')
var BaseColorReporter = require('./base_color')

var ProgressColorReporter = function (formatError, reportSlow, useColors) {
ProgressReporter.call(this, formatError, reportSlow, useColors)
var ProgressColorReporter = function (formatError, reportSlow) {
ProgressReporter.call(this, formatError, reportSlow)
BaseColorReporter.call(this)
}

Expand Down
5 changes: 1 addition & 4 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ var parseExitCode = function (buffer, defaultCode, failOnEmptyTestSuite) {

// TODO(vojta): read config file (port, host, urlRoot)
exports.run = function (config, done) {
logger.setupFromConfig(config)

done = helper.isFunction(done) ? done : process.exit
config = cfg.parseConfig(config.configFile, config)

Expand Down Expand Up @@ -73,7 +71,6 @@ exports.run = function (config, done) {
removedFiles: config.removedFiles,
changedFiles: config.changedFiles,
addedFiles: config.addedFiles,
refresh: config.refresh,
colors: config.colors
refresh: config.refresh
}))
}
8 changes: 7 additions & 1 deletion lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,17 @@ function createSocketIoServer (webServer, executor, config) {
return server
}

function setupLogger (level, colors) {
var logLevel = logLevel || constant.LOG_INFO
var logColors = helper.isDefined(colors) ? colors : true
logger.setup(logLevel, logColors, [constant.CONSOLE_APPENDER])
}

// Constructor
var Server = function (cliOptions, done) {
EventEmitter.call(this)

logger.setupFromConfig(cliOptions)
setupLogger(cliOptions.logLevel, cliOptions.colors)

this.log = logger.create()

Expand Down
30 changes: 1 addition & 29 deletions test/unit/reporters/base.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('reporter', function () {

beforeEach(function () {
adapter = sinon.spy()
reporter = new m.BaseReporter(null, null, false, adapter)
reporter = new m.BaseReporter(null, null, adapter)
return reporter
})

Expand All @@ -29,34 +29,6 @@ describe('reporter', function () {
return expect(anotherAdapter).to.have.been.calledWith('some')
})

it('should omit adapters not using the right color', function () {
var anotherAdapter = sinon.spy()
anotherAdapter.colors = true
reporter.adapters.push(anotherAdapter)
reporter.write('some')
expect(adapter).to.have.been.calledWith('some')
return expect(anotherAdapter).to.not.have.been.called
})

it('should not call non-colored adapters when wrong default setting', function () {
var reporter = new m.BaseReporter(null, null, true, adapter)
var anotherAdapter = sinon.spy()
reporter.adapters.push(anotherAdapter)
reporter.write('some')
expect(adapter).to.not.have.been.called
return expect(anotherAdapter).to.not.have.been.called
})

it('should call colored adapters regardless of default setting', function () {
var reporter = new m.BaseReporter(null, null, true, adapter)
var anotherAdapter = sinon.spy()
reporter.adapters.push(anotherAdapter)
adapter.colors = false
reporter.write('some')
expect(adapter).to.have.been.calledWith('some')
return expect(anotherAdapter).to.not.have.been.called
})

it('should format', function () {
reporter.write('Success: %d Failure: %d', 10, 20)

Expand Down

0 comments on commit 96ebdc4

Please sign in to comment.