Skip to content

Commit

Permalink
WIP feat(runner): Return emitter that forwards server data
Browse files Browse the repository at this point in the history
Allow the consumer to decide whether to echo the runner progress or not.

This might be the case when Karma.run() is called inside the same
process/terminal as the server is running in (e.g. development
servers).

Fixes karma-runner#2121, karma-runner#2799
  • Loading branch information
is-already-taken committed Apr 10, 2019
1 parent c7ebf0b commit 5fca98e
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const http = require('http')

const constant = require('./constants')
const EventEmitter = require('events').EventEmitter
const helper = require('./helper')
const cfg = require('./config')
const logger = require('./logger')
Expand Down Expand Up @@ -40,6 +41,7 @@ function run (config, done) {
config = cfg.parseConfig(config.configFile, config)

let exitCode = 1
let emitter = new EventEmitter()
const options = {
hostname: config.hostname,
path: config.urlRoot + 'run',
Expand All @@ -54,6 +56,7 @@ function run (config, done) {
response.on('data', function (buffer) {
const parsedResult = parseExitCode(buffer, exitCode, config.failOnEmptyTestSuite)
exitCode = parsedResult.exitCode
emitter.emit('progress', parsedResult.buffer)
process.stdout.write(parsedResult.buffer)
})

Expand All @@ -77,6 +80,8 @@ function run (config, done) {
refresh: config.refresh,
colors: config.colors
}))

return emitter
}

exports.run = run

0 comments on commit 5fca98e

Please sign in to comment.