From 66ae80b2f95f721cbbe4368ec591a883b833e661 Mon Sep 17 00:00:00 2001 From: Christian Budde Christensen Date: Thu, 28 Jan 2016 20:46:01 +0100 Subject: [PATCH 1/6] feat: Add possibility to stop a karma server Add detached mode using the `karma start --detached` command. Add middleware for stopping a server (detached or not). Described the detached option. --- docs/config/01-configuration-file.md | 12 +++++ lib/cli.js | 37 +++++++++++++++- lib/config.js | 1 + lib/middleware/runner.js | 2 +- lib/middleware/stopper.js | 18 ++++++++ lib/stopper.js | 33 ++++++++++++++ lib/web-server.js | 2 + test/e2e/steps/core_steps.js | 65 ++++++++++++++++++++-------- test/e2e/stop.feature | 44 +++++++++++++++++++ 9 files changed, 195 insertions(+), 19 deletions(-) create mode 100644 lib/middleware/stopper.js create mode 100644 lib/stopper.js create mode 100644 test/e2e/stop.feature diff --git a/docs/config/01-configuration-file.md b/docs/config/01-configuration-file.md index 6198f6ea5..280615607 100644 --- a/docs/config/01-configuration-file.md +++ b/docs/config/01-configuration-file.md @@ -249,6 +249,18 @@ customHeaders: [{ }] ``` + +## detached +**Type:** Boolean + +**Default:** `false` + +**CLI:** `--detached` + +**Description:** When true, this will start the karma server in another process, writing no output to the console. +The server can be stopped using the `karma stop` command. + + ## exclude **Type:** Array diff --git a/lib/cli.js b/lib/cli.js index 520dd43d3..3c23f0596 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -1,6 +1,7 @@ var path = require('path') var optimist = require('optimist') var fs = require('graceful-fs') +var spawn = require('child_process').spawn var Server = require('./server') var helper = require('./helper') @@ -159,6 +160,7 @@ var describeStart = function () { ' $0 start [] []') .describe('port', ' Port where the server is running.') .describe('auto-watch', 'Auto watch source files and run on change.') + .describe('detached', 'Detach the server.') .describe('no-auto-watch', 'Do not watch source files.') .describe('log-level', ' Level of logging.') .describe('colors', 'Use colors when reporting and printing logs.') @@ -187,6 +189,17 @@ var describeRun = function () { .describe('help', 'Print usage.') } +var describeStop = function () { + optimist + .usage('Karma - Spectacular Test Runner for JavaScript.\n\n' + + 'STOP - Stop the server (requires running server).\n\n' + + 'Usage:\n' + + ' $0 run [] []') + .describe('port', ' Port where the server is listening.') + .describe('log-level', ' Level of logging.') + .describe('help', 'Print usage.') +} + var describeCompletion = function () { optimist .usage('Karma - Spectacular Test Runner for JavaScript.\n\n' + @@ -196,6 +209,21 @@ var describeCompletion = function () { .describe('help', 'Print usage.') } +var startServer = function (config) { + var args = process.argv + var detachedIndex = args.indexOf('--detached') + if (detachedIndex === -1) { + new Server(config).start() + return + } + args.splice(detachedIndex, 1) + var child = spawn(args[0], args.slice(1), { + detached: true, + stdio: ['ignore', 'ignore', 'ignore'] + }) + child.unref() +} + exports.process = function () { var argv = optimist.parse(argsBeforeDoubleDash(process.argv.slice(2))) var options = { @@ -212,6 +240,10 @@ exports.process = function () { options.clientArgs = parseClientArgs(process.argv) break + case 'stop': + describeStop() + break + case 'init': describeInit() break @@ -240,11 +272,14 @@ exports.run = function () { switch (config.cmd) { case 'start': - new Server(config).start() + startServer(config) break case 'run': require('./runner').run(config) break + case 'stop': + require('./stopper').stop(config) + break case 'init': require('./init').init(config) break diff --git a/lib/config.js b/lib/config.js index 7c90eb459..6f5f0d8f9 100644 --- a/lib/config.js +++ b/lib/config.js @@ -267,6 +267,7 @@ var Config = function () { this.concurrency = Infinity this.failOnEmptyTestSuite = true this.retryLimit = 2 + this.detached = false } var CONFIG_SYNTAX_HELP = ' module.exports = function(config) {\n' + diff --git a/lib/middleware/runner.js b/lib/middleware/runner.js index 377b1e39d..06334fc44 100644 --- a/lib/middleware/runner.js +++ b/lib/middleware/runner.js @@ -1,5 +1,5 @@ /** - * Runner middleware is reponsible for communication with `karma run`. + * Runner middleware is responsible for communication with `karma run`. * * It basically triggers a test run and streams stdout back. */ diff --git a/lib/middleware/stopper.js b/lib/middleware/stopper.js new file mode 100644 index 000000000..ecd2b0b90 --- /dev/null +++ b/lib/middleware/stopper.js @@ -0,0 +1,18 @@ +/** + * Stopper middleware is responsible for communicating with `karma stop`. + */ + +var log = require('../logger').create('middleware:stopper') + +var createStopperMiddleware = function (urlRoot) { + return function (request, response, next) { + if (request.url !== urlRoot + 'stop') return next() + response.writeHead(200) + log.info('Stopping server') + response.end('OK') + process.exit(0) + } +} + +createStopperMiddleware.$inject = ['config.urlRoot'] +exports.create = createStopperMiddleware diff --git a/lib/stopper.js b/lib/stopper.js new file mode 100644 index 000000000..e67480792 --- /dev/null +++ b/lib/stopper.js @@ -0,0 +1,33 @@ +var http = require('http') + +var cfg = require('./config') +var logger = require('./logger') + +exports.stop = function (config) { + logger.setupFromConfig(config) + var log = logger.create('stopper') + config = cfg.parseConfig(config.configFile, config) + var options = { + hostname: config.hostname, + path: config.urlRoot + 'stop', + port: config.port, + method: 'GET' + } + + var request = http.request(options) + + request.on('response', function (response) { + log.info('Server stopped.') + process.exit(response.statusCode === 200 ? 0 : 1) + }) + + request.on('error', function (e) { + if (e.code === 'ECONNREFUSED') { + log.error('There is no server listening on port %d', options.port) + process.exit(1, e.code) + } else { + throw e + } + }) + request.end() +} diff --git a/lib/web-server.js b/lib/web-server.js index f84570cfa..dc200fda6 100644 --- a/lib/web-server.js +++ b/lib/web-server.js @@ -7,6 +7,7 @@ var Promise = require('bluebird') var common = require('./middleware/common') var runnerMiddleware = require('./middleware/runner') +var stopperMiddleware = require('./middleware/stopper') var stripHostMiddleware = require('./middleware/strip_host') var karmaMiddleware = require('./middleware/karma') var sourceFilesMiddleware = require('./middleware/source_files') @@ -56,6 +57,7 @@ var createWebServer = function (injector, emitter, fileList) { var handler = connect() .use(injector.invoke(runnerMiddleware.create)) + .use(injector.invoke(stopperMiddleware.create)) .use(injector.invoke(stripHostMiddleware.create)) .use(injector.invoke(karmaMiddleware.create)) .use(injector.invoke(sourceFilesMiddleware.create)) diff --git a/test/e2e/steps/core_steps.js b/test/e2e/steps/core_steps.js index 999214f20..0adcdd6a8 100644 --- a/test/e2e/steps/core_steps.js +++ b/test/e2e/steps/core_steps.js @@ -15,19 +15,18 @@ module.exports = function coreSteps () { var cleansingNeeded = true var additionalArgs = [] - var cleanseIfNeeded = (function (_this) { - return function () { - if (cleansingNeeded) { - try { - rimraf.sync(tmpDir) - } catch (e) {} + var cleanseIfNeeded = function () { + if (cleansingNeeded) { + try { + rimraf.sync(tmpDir) + } catch (e) { + } - cleansingNeeded = false + cleansingNeeded = false - return cleansingNeeded - } + return cleansingNeeded } - })(this) + } this.Given(/^a configuration with:$/, function (fileContent, callback) { cleanseIfNeeded() @@ -40,17 +39,39 @@ module.exports = function coreSteps () { return callback() }) - this.When(/^I (run|runOut|start|init) Karma$/, function (command, callback) { + this.When(/^I start a server in background/, function (callback) { this.writeConfigFile(tmpDir, tmpConfigFile, (function (_this) { return function (err, hash) { if (err) { return callback.fail(new Error(err)) } + var configFile = path.join(tmpDir, hash + '.' + tmpConfigFile) + var runtimePath = path.join(baseDir, 'bin', 'karma') + _this.child = spawn('' + runtimePath, ['start', '--log-level', 'debug', configFile]) + _this.child.stdout.on('data', function () { + callback() + callback = function () { + } + }) + _this.child.on('exit', function (exitCode) { + _this.childExitCode = exitCode + }) + } + })(this)) + }) + + this.When(/^I (run|runOut|start|init|stop) Karma( with log-level ([a-z]+))?$/, function (command, withLogLevel, level, callback) { + this.writeConfigFile(tmpDir, tmpConfigFile, (function (_this) { + return function (err, hash) { + if (err) { + return callback.fail(new Error(err)) + } + level = withLogLevel === undefined ? 'warn' : level var configFile = path.join(tmpDir, hash + '.' + tmpConfigFile) var runtimePath = path.join(baseDir, 'bin', 'karma') var execKarma = function (done) { - var cmd = runtimePath + ' ' + command + ' --log-level warn ' + configFile + ' ' + additionalArgs + var cmd = runtimePath + ' ' + command + ' --log-level ' + level + ' ' + configFile + ' ' + additionalArgs return exec(cmd, { cwd: baseDir @@ -107,11 +128,10 @@ module.exports = function coreSteps () { })(this)) }) - this.Then(/^it passes with( no debug)?:$/, {timeout: 10 * 1000}, function (noDebug, expectedOutput, callback) { - noDebug = noDebug === ' no debug' + this.Then(/^it passes with( no debug| like)?:$/, {timeout: 10 * 1000}, function (mode, expectedOutput, callback) { + var noDebug = mode === ' no debug' + var like = mode === ' like' var actualOutput = this.lastRun.stdout.toString() - var actualError = this.lastRun.error - var actualStderr = this.lastRun.stderr.toString() var lines if (noDebug) { @@ -120,12 +140,15 @@ module.exports = function coreSteps () { }) actualOutput = lines.join('\n') } + if (like && actualOutput.indexOf(expectedOutput) >= 0) { + return callback() + } if (actualOutput.indexOf(expectedOutput) === 0) { return callback() } - if (actualError || actualStderr) { + if (actualOutput) { return callback(new Error('Expected output to match the following:\n ' + expectedOutput + '\nGot:\n ' + actualOutput)) } @@ -159,4 +182,12 @@ module.exports = function coreSteps () { callback(new Error('Expected output to match the following:\n ' + expectedOutput + '\nGot:\n ' + actualOutput)) } }) + + this.Then(/^The server is dead( with exit code ([0-9]+))?$/, function (withExitCode, code, callback) { + setTimeout((function (_this) { + if (_this.childExitCode === undefined) return callback(new Error('Server has not exited.')) + if (code === undefined || parseInt(code, 10) === _this.childExitCode) return callback() + callback(new Error('Exit-code mismatch')) + })(this), 1000) + }) } diff --git a/test/e2e/stop.feature b/test/e2e/stop.feature new file mode 100644 index 000000000..d9eb0e4c9 --- /dev/null +++ b/test/e2e/stop.feature @@ -0,0 +1,44 @@ +Feature: Stop karma + In order to use Karma + As a person who wants to write great tests + I want to be able to stop Karma. + + Scenario: A server can't be stopped if it isn't running + When I stop Karma + Then it fails with like: + """ + ERROR \[stopper\]: There is no server listening on port [0-9]+ + """ + + Scenario: A server can be stopped + Given a configuration with: + """ + files = ['basic/plus.js', 'basic/test.js']; + browsers = ['PhantomJS']; + plugins = [ + 'karma-jasmine', + 'karma-phantomjs-launcher' + ]; + singleRun = false; + """ + When I start a server in background + And I stop Karma + Then The server is dead with exit code 0 + + Scenario: A server can be stopped and give informative output + Given a configuration with: + """ + files = ['basic/plus.js', 'basic/test.js']; + browsers = ['PhantomJS']; + plugins = [ + 'karma-jasmine', + 'karma-phantomjs-launcher' + ]; + singleRun = false; + """ + When I start a server in background + And I stop Karma with log-level info + Then it passes with like: + """ + Server stopped. + """ From 3d4fa00d32154a1573f0dbf04a5a86ac38fd89a2 Mon Sep 17 00:00:00 2001 From: Christian Budde Christensen Date: Thu, 11 Feb 2016 19:39:17 +0100 Subject: [PATCH 2/6] feat: Add `stopper` to the public API Add the `stopper` as a command to the public API allowing for enabling users to programically terminate a running server. --- docs/dev/04-public-api.md | 16 ++++++++++++++++ lib/index.js | 2 ++ lib/stopper.js | 15 ++++++++++++--- test/e2e/steps/core_steps.js | 31 ++++++++++++++++++++++--------- test/e2e/stop.feature | 18 ++++++++++++++++++ 5 files changed, 70 insertions(+), 12 deletions(-) diff --git a/docs/dev/04-public-api.md b/docs/dev/04-public-api.md index c9bc02017..2c341f646 100644 --- a/docs/dev/04-public-api.md +++ b/docs/dev/04-public-api.md @@ -118,6 +118,22 @@ runner.run({port: 9876}, function(exitCode) { }) ``` +## karma.stopper + +### **stopper.stop(options, [callback=process.exit])** + +This function will signal a running server to stop. Equivalent of `karma stop`. + +```javascript +var stopper = require('karma').stopper +runner.stop({port: 9876}, function(exitCode) { + if (exitCode === 0) { + console.log('Server stop as initiated') + } + process.exit(exitCode) +}) +``` + ## Callback function notes - If there is an error, the error code will be provided as the second parameter to the error callback. diff --git a/lib/index.js b/lib/index.js index 8631260f1..d894a444b 100644 --- a/lib/index.js +++ b/lib/index.js @@ -3,6 +3,7 @@ var constants = require('./constants') var Server = require('./server') var runner = require('./runner') +var stopper = require('./stopper') var launcher = require('./launcher') // TODO: remove in 1.0 @@ -21,6 +22,7 @@ module.exports = { VERSION: constants.VERSION, Server: Server, runner: runner, + stopper: stopper, launcher: launcher, server: oldServer } diff --git a/lib/stopper.js b/lib/stopper.js index e67480792..c2a839a0c 100644 --- a/lib/stopper.js +++ b/lib/stopper.js @@ -2,11 +2,14 @@ var http = require('http') var cfg = require('./config') var logger = require('./logger') +var helper = require('./helper') -exports.stop = function (config) { +exports.stop = function (config, done) { logger.setupFromConfig(config) + done = helper.isFunction(done) ? done : process.exit var log = logger.create('stopper') config = cfg.parseConfig(config.configFile, config) + var options = { hostname: config.hostname, path: config.urlRoot + 'stop', @@ -17,14 +20,20 @@ exports.stop = function (config) { var request = http.request(options) request.on('response', function (response) { + if (response.statusCode !== 200) { + log.error('Server returned status code: ' + response.statusCode) + done(1) + return + } + log.info('Server stopped.') - process.exit(response.statusCode === 200 ? 0 : 1) + done(0) }) request.on('error', function (e) { if (e.code === 'ECONNREFUSED') { log.error('There is no server listening on port %d', options.port) - process.exit(1, e.code) + done(1, e.code) } else { throw e } diff --git a/test/e2e/steps/core_steps.js b/test/e2e/steps/core_steps.js index 0adcdd6a8..014e24283 100644 --- a/test/e2e/steps/core_steps.js +++ b/test/e2e/steps/core_steps.js @@ -5,6 +5,7 @@ module.exports = function coreSteps () { var exec = ref.exec var spawn = ref.spawn var rimraf = require('rimraf') + var stopper = require('../../../lib/stopper') this.World = require('../support/world').World require('../support/after_hooks').call(this) @@ -39,13 +40,22 @@ module.exports = function coreSteps () { return callback() }) + this.When(/^I stop a server programmatically/, function (callback) { + var _this = this + setTimeout(function () { + stopper.stop(_this.configFile, function (exitCode) { + _this.stopperExitCode = exitCode + }) + callback() + }, 1000) + }) + this.When(/^I start a server in background/, function (callback) { this.writeConfigFile(tmpDir, tmpConfigFile, (function (_this) { return function (err, hash) { if (err) { return callback.fail(new Error(err)) } - var configFile = path.join(tmpDir, hash + '.' + tmpConfigFile) var runtimePath = path.join(baseDir, 'bin', 'karma') _this.child = spawn('' + runtimePath, ['start', '--log-level', 'debug', configFile]) @@ -173,7 +183,6 @@ module.exports = function coreSteps () { var actualOutput = this.lastRun.stdout.toString() var actualError = this.lastRun.error var actualStderr = this.lastRun.stderr.toString() - if (actualOutput.match(new RegExp(expectedOutput))) { return callback() } @@ -183,11 +192,15 @@ module.exports = function coreSteps () { } }) - this.Then(/^The server is dead( with exit code ([0-9]+))?$/, function (withExitCode, code, callback) { - setTimeout((function (_this) { - if (_this.childExitCode === undefined) return callback(new Error('Server has not exited.')) - if (code === undefined || parseInt(code, 10) === _this.childExitCode) return callback() - callback(new Error('Exit-code mismatch')) - })(this), 1000) - }) + this.Then(/^The (server|stopper) is dead( with exit code ([0-9]+))?$/, + function (stopperOrServer, withExitCode, code, callback) { + var server = stopperOrServer === 'server' + var _this = this + setTimeout(function () { + var actualExitCode = server ? _this.childExitCode : _this.stopperExitCode + if (actualExitCode === undefined) return callback(new Error('Server has not exited.')) + if (code === undefined || parseInt(code, 10) === actualExitCode) return callback() + callback(new Error('Exit-code mismatch')) + }, 1000) + }) } diff --git a/test/e2e/stop.feature b/test/e2e/stop.feature index d9eb0e4c9..bed515dc6 100644 --- a/test/e2e/stop.feature +++ b/test/e2e/stop.feature @@ -42,3 +42,21 @@ Feature: Stop karma """ Server stopped. """ + + + Scenario: A server can be stopped programically + Given a configuration with: + """ + files = ['basic/plus.js', 'basic/test.js']; + browsers = ['PhantomJS']; + plugins = [ + 'karma-jasmine', + 'karma-phantomjs-launcher' + ]; + singleRun = false; + logLevel = 'error'; + """ + When I start a server in background + And I stop a server programmatically + Then The server is dead with exit code 0 + And The stopper is dead with exit code 0 From f10fd816179ec4b4abfff3d599c0331b7be96980 Mon Sep 17 00:00:00 2001 From: Christian Budde Christensen Date: Sat, 13 Feb 2016 17:14:27 +0100 Subject: [PATCH 3/6] feat(stopper): Enable programically detached server When setting `detached=true` in config, the server will start detached. --- lib/cli.js | 18 +----------------- lib/detached.js | 9 +++++++++ lib/middleware/stopper.js | 2 +- lib/server.js | 30 +++++++++++++++++++++++++++++- package.json | 1 + 5 files changed, 41 insertions(+), 19 deletions(-) create mode 100644 lib/detached.js diff --git a/lib/cli.js b/lib/cli.js index 3c23f0596..9d6c774c7 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -1,7 +1,6 @@ var path = require('path') var optimist = require('optimist') var fs = require('graceful-fs') -var spawn = require('child_process').spawn var Server = require('./server') var helper = require('./helper') @@ -209,21 +208,6 @@ var describeCompletion = function () { .describe('help', 'Print usage.') } -var startServer = function (config) { - var args = process.argv - var detachedIndex = args.indexOf('--detached') - if (detachedIndex === -1) { - new Server(config).start() - return - } - args.splice(detachedIndex, 1) - var child = spawn(args[0], args.slice(1), { - detached: true, - stdio: ['ignore', 'ignore', 'ignore'] - }) - child.unref() -} - exports.process = function () { var argv = optimist.parse(argsBeforeDoubleDash(process.argv.slice(2))) var options = { @@ -272,7 +256,7 @@ exports.run = function () { switch (config.cmd) { case 'start': - startServer(config) + new Server(config).start() break case 'run': require('./runner').run(config) diff --git a/lib/detached.js b/lib/detached.js new file mode 100644 index 000000000..76af943f4 --- /dev/null +++ b/lib/detached.js @@ -0,0 +1,9 @@ +var fs = require('fs') + +var Server = require('./server') +var configurationFile = process.argv[2] +var fileContents = fs.readFileSync(configurationFile, 'utf-8') +fs.unlink(configurationFile, function () {}) +var data = JSON.parse(fileContents) +var server = new Server(data) +server.start(data) diff --git a/lib/middleware/stopper.js b/lib/middleware/stopper.js index ecd2b0b90..8d41cee00 100644 --- a/lib/middleware/stopper.js +++ b/lib/middleware/stopper.js @@ -10,7 +10,7 @@ var createStopperMiddleware = function (urlRoot) { response.writeHead(200) log.info('Stopping server') response.end('OK') - process.exit(0) + process.kill(process.pid, 'SIGINT') } } diff --git a/lib/server.js b/lib/server.js index 34de4ed2c..e7f496264 100644 --- a/lib/server.js +++ b/lib/server.js @@ -2,7 +2,10 @@ var SocketIO = require('socket.io') var di = require('di') var util = require('util') var Promise = require('bluebird') - +var spawn = require('child_process').spawn +var tmp = require('tmp') +var fs = require('fs') +var path = require('path') var root = global || window || this var cfg = require('./config') @@ -131,6 +134,10 @@ Server.prototype.refreshFiles = function () { Server.prototype._start = function (config, launcher, preprocess, fileList, webServer, capturedBrowsers, socketServer, executor, done) { var self = this + if (config.detached) { + this._detach(config, done) + return + } self._fileList = fileList @@ -362,6 +369,27 @@ Server.prototype._start = function (config, launcher, preprocess, fileList, webS }) } +Server.prototype._detach = function (config, done) { + var log = this.log + var tmpFile = tmp.fileSync({keep: true}) + log.info('Starting karma detached') + log.info('Run "karma stop" to stop the server.') + log.debug('Writing config to tmp-file %s', tmpFile.name) + config.detached = false + try { + fs.writeFileSync(tmpFile.name, JSON.stringify(config), 'utf8') + } catch (e) { + log.error("Couldn't write temporary configuration file") + done(1) + return + } + var child = spawn(process.argv[0], [path.resolve(__dirname, '../lib/detached.js'), tmpFile.name], { + detached: true, + stdio: 'ignore' + }) + child.unref() +} + // Export // ------ diff --git a/package.json b/package.json index ff1bfebe1..e39f62535 100644 --- a/package.json +++ b/package.json @@ -283,6 +283,7 @@ "rimraf": "^2.3.3", "socket.io": "^1.4.5", "source-map": "^0.5.3", + "tmp": "0.0.28", "useragent": "^2.1.6" }, "devDependencies": { From 414db8983d9c5015b8b4f164b68aa141ca122e1c Mon Sep 17 00:00:00 2001 From: Christian Budde Christensen Date: Sat, 13 Feb 2016 18:18:58 +0100 Subject: [PATCH 4/6] fix: Setting default value for config in runner and stopper Default config to empty Object if undefined. --- lib/runner.js | 7 ++++++- lib/stopper.js | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/runner.js b/lib/runner.js index 2df29715f..5f74cd199 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -31,6 +31,10 @@ var parseExitCode = function (buffer, defaultCode, failOnEmptyTestSuite) { // TODO(vojta): read config file (port, host, urlRoot) exports.run = function (config, done) { + config = config || {} + + logger.setupFromConfig(config) + done = helper.isFunction(done) ? done : process.exit config = cfg.parseConfig(config.configFile, config) @@ -71,6 +75,7 @@ exports.run = function (config, done) { removedFiles: config.removedFiles, changedFiles: config.changedFiles, addedFiles: config.addedFiles, - refresh: config.refresh + refresh: config.refresh, + colors: config.colors })) } diff --git a/lib/stopper.js b/lib/stopper.js index c2a839a0c..3f0d72cfc 100644 --- a/lib/stopper.js +++ b/lib/stopper.js @@ -5,6 +5,7 @@ var logger = require('./logger') var helper = require('./helper') exports.stop = function (config, done) { + config = config || {} logger.setupFromConfig(config) done = helper.isFunction(done) ? done : process.exit var log = logger.create('stopper') From d14bd62b14a1e42d3a24be848916f5defe5a7e84 Mon Sep 17 00:00:00 2001 From: Christian Budde Christensen Date: Sun, 21 Feb 2016 10:56:07 +0100 Subject: [PATCH 5/6] feat(logging): Add logging-setup function Add a setup-function for setting up the log-level and colors from config. --- lib/logger.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/logger.js b/lib/logger.js index 455081dbe..210242996 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -43,6 +43,29 @@ 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 @@ -60,3 +83,4 @@ var create = function (name, level) { exports.create = create exports.setup = setup +exports.setupFromConfig = setupFromConfig From 0cb6204f157c4ec1078aeb622ea33bbde930da4a Mon Sep 17 00:00:00 2001 From: Christian Budde Christensen Date: Sun, 21 Feb 2016 21:00:40 +0100 Subject: [PATCH 6/6] fix: Change timing on test Change the timing on tests, allowing Node 0.10 to catch-up. --- test/e2e/steps/core_steps.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/steps/core_steps.js b/test/e2e/steps/core_steps.js index 014e24283..de79e6f6d 100644 --- a/test/e2e/steps/core_steps.js +++ b/test/e2e/steps/core_steps.js @@ -201,6 +201,6 @@ module.exports = function coreSteps () { if (actualExitCode === undefined) return callback(new Error('Server has not exited.')) if (code === undefined || parseInt(code, 10) === actualExitCode) return callback() callback(new Error('Exit-code mismatch')) - }, 1000) + }, 4000) }) }