karma: Undocumented breaking change
Expected behaviour
#2228 extended browserConsoleLogOptions.level to filter messages on the terminal. This changes the behavior of karma so that under certain circumstances messages created with console no longer show up in the terminal without configuration changes. This should be documented.
Actual behaviour
There is no documentation. In my case I spent over 3 hours investigating source code, git issues, versions, etc before I identified the problem was this change.
Environment Details
- Karma version (output of
karma --version): 1.5.0
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 18
- Comments: 25 (11 by maintainers)
Commits related to this issue
- fix: filter browser logging by level of LOG Additional fix to the bug, "filter browser logging by level" ([35965d9](https://github.com/karma-runner/karma/commit/35965d9)), closes [#2228](https://gith... — committed to karma-runner/karma by blackswanny 7 years ago
- build: fix karma console log Karma recently introduced a breaking change, that **hasn't** been noted (https://github.com/karma-runner/karma/issues/2582). Karma doesn't show any `console.log` calls a... — committed to devversion/material2 by devversion 7 years ago
- build: fix karma console log (#3484) Karma recently introduced a breaking change, that **hasn't** been noted (https://github.com/karma-runner/karma/issues/2582). Karma doesn't show any `console.lo... — committed to angular/components by devversion 7 years ago
- sync from upstream (#1) * fix(tabs): remove body and header from compatibility (#3168) * feat(ripple): expose ripple directive in template (#3165) * When programmatically calling `launch` on th... — committed to pacjin79/material2 by pacjin79 7 years ago
- fix(reporters): Revert the backwards-incompatible log priority order changes Commit 35965d9 changed the order of log priorities, making lots of configurations no longer print console.log messages. Th... — committed to mgol/karma by mgol 7 years ago
- Revert "Implement consoleRedirect: true" This reverts commit 64ca79d. It turns out that this wasn't really necessary after all, as Karma is supposed to redirect this by itself. I was however somewhat... — committed to badeball/karma-jsdom-launcher by badeball 7 years ago
- chore(*): update all Karma-related packages except Karma Karma can't be updated due to a bug: https://github.com/karma-runner/karma/issues/2582 that's already fixed on master but not released yet. T... — committed to mgol/angular.js by mgol 7 years ago
- chore(*): update all Karma-related packages except Karma Karma can't be updated due to a bug: https://github.com/karma-runner/karma/issues/2582 that's already fixed on master but not released yet. T... — committed to mgol/angular.js by mgol 7 years ago
- Upgrade Karma to 1.7.0 to pick up fix for https://github.com/karma-runner/karma/issues/2582 — committed to mixmaxhq/erik by deleted user 7 years ago
Here are exact configuration changes that should work (works great for me after these changes):
… Make sure you put a comma after the word “true” if there are additional directives after the captureConsole line.
… The comma on the ending line is there because we will add one more section after that.
logLevel: config.LOG_LOGMake sure you put a comma on the end of that line if there are additional config directives after this line.Then, whenever your test does:
console.log('TEST OUTPUT.');… you should see the output. Other console log levels should also work.
My issue has been resolved. Native
console.logwas replaced with a custom implementation.@robsimmons @dignifiedquire I first encountered this issue b/c I was working w/ the expectation that log != debug.
console.logis used as the default “write output the screen” in most tutorials I’ve seen. It’s even used in the official jasmine docs. According to the spec, most of these cases should be usingconsole.infobut I have never seen it used that way.The new behavior doesn’t seem like it could be consistent with the debug info log warn error ordering of console verbosity that the previous ticket claimed. If I include this in a spec:
then as of 1.5.0, on the command line I get
The string
browserConsoleLogOptionsonly appears under ./node_modules/karma.I still see no logs from the browser.@dignifiedquire I believe that’s mostly right. The sadness is there has to be a choice between backwards compatibility and complying with the spec that Console.log === Console.debug.
There’s a separate and not-cleanly-answerable question of whether “general expectations” match the spec. I suspect the ordering disable / error / warn / log / info / debug may be both “incorrect” and “generally expected.”
Yes, it seems that in practice the order of decreasing verbosity/increasing severity is now
log,debug,info,warn,error. Since the default value ofbrowserConsoleLogOptions.levelis"debug", this means that anybody not using this option will no longer seeconsole.logentries at all.A workaround is to set
browserConsoleLogOptions.levelto"log".Log levels keep on giving. I am sorry about that. @wesleycho could you do a small write up about the old vs the new behaviour, that we can put into the changelog?