Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

console.log not working on any karma project

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
[email protected] C:\...\mvce
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
`-- [email protected]

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:

  • Windows 10 Home w/ all current updates
  • Node v7.2.1
  • Chrome 56
like image 766
just.another.programmer Avatar asked Feb 21 '17 21:02

just.another.programmer


People also ask

What does console log () do?

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.

How console log works in JavaScript?

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.

What is log in JavaScript?

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.


1 Answers

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.

  1. They changed the order of severity for log messages so that 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.
  2. As mentioned above they added support to filter console by log level with browserConsoleLogOptions.
like image 109
just.another.programmer Avatar answered Nov 02 '22 02:11

just.another.programmer