我正在使用mocha -w
进行连续测试。
我遇到了另一个lib的套接字连接的错误,只有在长时间使用mocha -w
时才会发生。我需要捕获定向到console.log
的调试输出到文件中,以便可以搜索和过滤大量数据以用于故障排除。
然而,摩卡的“观察”旋转器正在阻碍。当我尝试使用Windows power shell,GitHub的Git Shell或DOS将stdout重定向到文件时:
mocha -w >> log.txt
我从动画微调器中获取这样的GB数据:
[0G [96m | [90mwatching [0m [0G [96m / [90mwatching [0m [0G] [96m- [90mwatching [0m [0G [96m] [90mwatching [0m [0G [96m | [90mwatching [0m [0G [96m / [90mwatching [0m [0G [96m- [90mwatching [0m [0G [96m \ [90mwatching [0m [0G [96m | [90mwatching [0m [0G [96m / [90mwatching [0m [0G [96m- [90mwatching [0m [0G [96m \ [90mwatching [0m [0G [96m | [90mwatching [0m [0G [96m / [90mwatching [0m [0G [96m- [90mwatching [0m [0G [96m \ [90mwatching [0m [0G [96m | [90mwatching [0m [0G [96m / [90mwatching [0m [0G [96m-
This SO question suggests making a copy of Mocha and hacking the play()
method.然而,尝试通过使用黑客版本的摩卡来解决可能是摩卡错误的方法并不理想。
所以这似乎是扩展我的shell知识和node.js知识的好时机。
是否有优雅的方式来执行以下任何操作?
答案 0 :(得分:2)
我不熟悉mocha或其输出但理论上你应该能够像这样过滤:
mocha -w | Where {$_ -notmatch 'watching\['} >> log.txt
调整正则表达式('匹配[')以最适合您要过滤的输出。