Skip to content

Commit

Permalink
feat(runner): Config option to prevent logging to the console twice
Browse files Browse the repository at this point in the history
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 Mar 30, 2019
1 parent c7ebf0b commit a7579dc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
10 changes: 10 additions & 0 deletions docs/config/01-configuration-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,16 @@ Additional reporters, such as `growl`, `junit`, `teamcity` or `coverage` can be
Note: Just about all additional reporters in Karma (other than progress) require an additional library to be installed (via NPM).


## runnerLogging
**Type:** Boolean

**Default:** `true`

**Description:** Prevent `Karma.run()` from logging test results to `stdout`.

When `Karma.run()` is executed in the same process/terminal as the server, this option allows the developer to prevent the runner from logging the output to the terminal. This helps to avoid duplicated test result output in development servers.


## formatError
**Type:** Function

Expand Down
1 change: 1 addition & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ class Config {
this.restartOnFileChange = false
this.usePolling = process.platform === 'linux'
this.reporters = ['progress']
this.runnerLogging = true
this.singleRun = false
this.browsers = []
this.captureTimeout = 60000
Expand Down
9 changes: 8 additions & 1 deletion lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,14 @@ function run (config, done) {
response.on('data', function (buffer) {
const parsedResult = parseExitCode(buffer, exitCode, config.failOnEmptyTestSuite)
exitCode = parsedResult.exitCode
process.stdout.write(parsedResult.buffer)

// When Karma.run() is issued in the same process as the Karma server,
// test results will be logged twice: by the reporter and directly by
// the runner (here). Give the developer an option to disable this
// logging to prevent duplicated output.
if (config.runnerLogging !== false) {
process.stdout.write(parsedResult.buffer)
}
})

response.on('end', () => done(exitCode))
Expand Down

0 comments on commit a7579dc

Please sign in to comment.