运行“npm test”时没有console.log到STDOUT (笑话) [英] No console.log to STDOUT when running "npm test" (jest)

查看:210
本文介绍了运行“npm test”时没有console.log到STDOUT (笑话)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知 console.log()在运行脚本时应该可以正常打印到控制台的STDOUT。

From what I know console.log() should work without problem printing to the STDOUT of my console, when running a script.

但在我的情况下,我将NPM配置为在从shell发出 npm test 时运行Jest,以及任何 console.log测试文件中的()不会在屏幕上打印任何内容。
我还尝试使用 process.stdout.write()但是在运行 npm test

But in my case I have NPM configured to run Jest when issuing npm test from the shell, and any console.log() inside the test files doesn't print anything on the screen. I tried also to use process.stdout.write() but still I get no custom output when running npm test.

我应该如何调试测试脚本中的内容?
我无法弄清楚它是来自Node,来自NPM还是来自Jest的问题。
有一个 Jest问题看起来与我的相似但仍然无法解决并输出一个简单的字符串;而JEST输出的其余部分像往常一样回应。

How am I supposed to debug stuff in my test scripts? I can't figure out if it is a problem from Node, from NPM, or from Jest. There's a Jest issue that looks similar to mine but still I cannot solve and get to output a simple string; while there rest of Jest output is echoed as usual.

是否有人遇到过类似的问题?

Anybody experienced a similar problem?

编辑1:
我尝试运行 npm test - --runInBand 但是日志没有出现。

EDIT 1: I tried running npm test -- --runInBand but the log doesn't appear.

注意:尝试重复运行该命令我有时可以查看日志,但这会被以下Jest的其余部分覆盖/隐藏输出。

Note: trying to run the command repeatedly I can sometimes see the log, but this is then overwritten/hidden by the rest of the following Jest output.

推荐答案

从问题发生以来的链接问题多年来......

From the linked issue since the problem is going on since years...

alpha 中的拉取请求发布即将解决此问题。看起来最后一次改进是在过去几个小时内完成的(参见Github问题链接)。

There is a pull request in the alpha release that is going to fix this problem. Looks like the last refining is being worked in the past few hours (see Github issue link).

但是我发现了一个适用于我最简单案例的解决方案:

However I found a solution that works for my simplest case:


  • 只需运行 npm test - --verbose = true ,日志就会神奇地出现!

  • just run npm test -- --verbose=true and the log will magically appear!

这种不会在每种情况下修复;也许异步/多线程/等仍然会有问题(请报告你的经验,所以我可以更新答案);例如,在日志再次隐藏它之后添加 process.exit(1)

This will not fix in every case; maybe async/multi-thread/etc will still have problems (please report your experiences, so I can update the answer); for example adding a process.exit(1) after the log will hide it again.

尝试按 ctrl + c process.exit()运行之前(正确的时间...)将显示日志实际上已经被覆盖了。

Trying to press ctrl + c before the process.exit() runs (with the right timing...) will show that the log is actually there and being overridden.

我将用新闻更新答案,但这可能会帮助其他人开始使用Node / NPM / Jest设置!

I will update the answer with news, but probably this will help others in starting with Node/NPM/Jest setups!

这篇关于运行“npm test”时没有console.log到STDOUT (笑话)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆