【问题标题】:Forcing console.log to stdout with buster-test?使用 buster-test 强制 console.log 到标准输出?
【发布时间】:2014-03-04 00:54:49
【问题描述】:

在 shell 中运行测试时,我惊讶地发现即使指定了 -o/--release-console,从外部 .js 文件对 console.log() 的调用也会被压缩。根据documentation,shell 实用程序buster-test 应该在指定该选项的情况下单独保留全局console

在我之前使用 JUnit 和 PyUnit 的经验中,当测试用例在 shell 中运行时,打印到 stdout 会产生输出(在 stdout 或 stderr 上),而不管在哪里调用了“echo”。我更喜欢并且需要这种行为,因为我使用日志记录/打印作为主要工具来了解正在发生的事情。

如果我想在终端中回收 console.log 输出,我有哪些选择?


详情、更新:

  • 测试配置了浏览器环境。

【问题讨论】:

    标签: javascript unit-testing output buster.js


    【解决方案1】:

    您对此设置的架构存在误解。特别是,浏览器(例如 Firefox)中的 console.log 与测试运行器(节点)中的 console.log 无关,如下面的屏幕截图所示。正如您可能已经怀疑的那样,您在 浏览器 环境中运行的事实确实是相关的。

    我对 BusterJS 或 Node 不是很有经验,但是为了让所有 console.log 输出出现在 shell 中,您需要在 node 环境中运行测试。这造成了一个障碍,因为您需要一个 Node 模块来处理 DOM 和其他常见的依赖项,例如 jQuery。

    var config = module.exports;
    config["Interval Buttons"] = {
        environment: 'node',
    };
    

    Firebug 控制台有你的输出:

    【讨论】:

      猜你喜欢
      • 2015-03-14
      • 1970-01-01
      • 1970-01-01
      • 2013-08-26
      • 2011-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-05
      相关资源
      最近更新 更多