Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(runner): Config option to prevent logging to the console twice #3288

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/dev/04-public-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,17 @@ runner.run({port: 9876}, function(exitCode) {
})
```

`runner.run()` returns an `EventEmitter` which emits a `progress` event passing
the reporter output as a `Buffer` object.

You may listen for that event to print the reporter output to the console:

```javascript
runner.run({port: 9876}).on('progress', function(data) {
process.stdout.write(data)
})
```

## karma.stopper

### **stopper.stop(options, [callback=process.exit])**
Expand Down
8 changes: 7 additions & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ function describeCompletion () {
.describe('help', 'Print usage.')
}

function printRunnerProgress (data) {
process.stdout.write(data)
}

exports.process = function () {
const argv = optimist.parse(argsBeforeDoubleDash(process.argv.slice(2)))
const options = {
Expand Down Expand Up @@ -291,7 +295,9 @@ exports.run = function () {
new Server(config).start()
break
case 'run':
require('./runner').run(config)
require('./runner')
.run(config)
.on('progress', printRunnerProgress)
break
case 'stop':
require('./stopper').stop(config)
Expand Down
6 changes: 5 additions & 1 deletion 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,7 +56,7 @@ function run (config, done) {
response.on('data', function (buffer) {
const parsedResult = parseExitCode(buffer, exitCode, config.failOnEmptyTestSuite)
exitCode = parsedResult.exitCode
process.stdout.write(parsedResult.buffer)
emitter.emit('progress', parsedResult.buffer)
})

response.on('end', () => done(exitCode))
Expand All @@ -77,6 +79,8 @@ function run (config, done) {
refresh: config.refresh,
colors: config.colors
}))

return emitter
}

exports.run = run