简体   繁体   中英

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
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:

  • Windows 10 Home w/ all current updates
  • Node v7.2.1
  • Chrome 56

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM