UPDATE: tl;dr; I updated my npm packages and couldn't see any console.log
output anymore in karma. Looks like it's b/c of a behavior change that only shows console.log
output at the LOG_DEBUG
level and hides it at LOG_INFO
. When was that change made and is there a way to revert it?
ORIGINAL: When I run karma from a windows command prompt I cannot see the output of console.log
. I used to see it fine in many projects, but now it's suddenly not working in any of my projects. This seems to have changed after I ran npm update
in one project. I did not npm update
any other project, but they all stopped working.
I created an MCVE with a clean project and I still see the same behavior. Here's a list of the installed packages in my clean project (output from npm list
)
C:\...\mvce>npm list
mvce@1.0.0 C:\...\mvce
+-- jasmine-core@2.5.2
+-- karma@1.5.0
+-- karma-chrome-launcher@2.0.0
+-- karma-jasmine@1.1.0
+-- karma-phantomjs-launcher@1.0.2
`-- phantomjs@2.1.7
and here's the config code
karma.conf.js
module.exports = function(config) {
config.set({
autoWatch: false,
singleRun: true,
basePath: ".",
frameworks: ["jasmine"],
logLevel: "INFO",
browsers: ["PhantomJS", "Chrome"],
files: ["test.js"]
});
};
test.js
describe("describe", function(){
it("it", function(){
console.log("test");
});
});
Note I have already tried adding both of these to my karma.conf.js
. They make no difference.
client: {
captureConsole: true
}
// or
loggers: [
{ type: "console" }
]
NOTE: I've seen this issue on karma github, none of the suggestions there help. Also, it's describing a setup w/ mocha, I'm using jasmine - and the official workaround is to use captureConsole
which I tried.
I also created a gist for this issue.
Environment info:
The console. log() is a function in JavaScript that is used to print any kind of variables defined before in it or to just print any message that needs to be displayed to the user.
The console. log() method outputs a message to the web console. The message may be a single string (with optional substitution values), or it may be any one or more JavaScript objects.
The JavaScript Math. log() function returns the natural logarithm of a number. It returns the natural logarithm (base e) of a number. It is equivalent to ln(x) in mathematics.
Looks like karma added a feature in v1.5.0 to filter console capture by log level. Here's a link to the git pull request and the code changes showing what happened. I couldn't find any updates in the docs about this new feature. Based on the code changes, here are the new rules
You can configure browserConsoleLogOptions
in your karma conf file to specify what messages should appear on your terminal output. Set the level
property to specify the maximum level that should be displayed. To display all messages, set level
to an empty string.
For my case, I needed to set it like this:
browserConsoleLogOptions: {
terminal: true,
level: ""
}
UPDATE: There's an open git issue discussing this. There are actually two changes in karma 1.5 that matter here.
LOG
== DEBUG
. The severity used LOG
> INFO
. That means any project has log level set to INFO
would show console.log
messages in the old version and not show them in the new system.browserConsoleLogOptions
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With