简体   繁体   English

console.log 不适用于任何业力项目

[英]console.log not working on any karma project

UPDATE: tl;dr;更新:tl;博士; I updated my npm packages and couldn't see any console.log output anymore in karma.我更新了我的 npm 包,在 karma 中再也看不到任何console.log输出。 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 .看起来它是行为更改的 b/c,仅在LOG_DEBUG级别显示console.log输出并将其隐藏在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 .原文:当我从 Windows 命令提示符运行 karma 时,我看不到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.这似乎在我在一个项目中运行npm update后发生了变化。 I did not npm update any other project, but they all stopped working.我没有npm update任何其他项目,但它们都停止工作了。

I created an MCVE with a clean project and I still see the same behavior.我用一个干净的项目创建了一个 MCVE,但我仍然看到相同的行为。 Here's a list of the installed packages in my clean project (output from npm list )这是我的干净项目中已安装软件包的列表(来自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 .请注意,我已经尝试将这两个添加到我的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.注意:我在 karma github 上看到过这个问题,那里的建议都没有帮助。 Also, it's describing a setup w/ mocha, I'm using jasmine - and the official workaround is to use captureConsole which I tried.此外,它描述了一个带有 mocha 的设置,我正在使用 jasmine - 官方解决方法是使用我尝试过的captureConsole

I also created a gist for this issue.我还为这个问题创建了一个要点

Environment info:环境信息:

  • Windows 10 Home w/ all current updates带有所有当前更新的 Windows 10 家庭版
  • Node v7.2.1节点 v7.2.1
  • Chrome 56铬 56

Looks like karma added a feature in v1.5.0 to filter console capture by log level.看起来 karma 在 v1.5.0 中添加了一个功能来按日志级别过滤控制台捕获。 Here's a link to the git pull request and the code changes showing what happened.这是git pull 请求的链接, 代码更改显示发生了什么。 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.您可以在 karma conf 文件中配置browserConsoleLogOptions以指定应在终端输出中显示哪些消息。 Set the level property to specify the maximum level that should be displayed.设置level属性以指定应显示的最大级别。 To display all messages, set level to an empty string.要显示所有消息,请将level设置为空字符串。

For my case, I needed to set it like this:对于我的情况,我需要这样设置:

browserConsoleLogOptions: {
    terminal: true,
    level: ""
}

UPDATE: There's an open git issue discussing this.更新:有一个open git issue讨论这个。 There are actually two changes in karma 1.5 that matter here.实际上,业力 1.5 中有两个变化在这里很重要。

  1. They changed the order of severity for log messages so that LOG == DEBUG .他们更改了日志消息的严重性顺序,以便LOG == DEBUG The severity used LOG > INFO .严重性使用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.这意味着任何将日志级别设置为INFO的项目都会在旧版本中显示console.log消息,而不会在新系统中显示它们。
  2. As mentioned above they added support to filter console by log level with browserConsoleLogOptions .如上所述,他们使用browserConsoleLogOptions添加了按日志级别过滤控制台的支持。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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