gpt4 book ai didi

angular - Karma ng 测试未在控制台中显示构建错误

转载 作者:行者123 更新时间:2023-12-03 23:51:08 26 4
gpt4 key购买 nike

我正在使用 Karma 和 Jasmine 在我的 Angular 7 项目中执行测试。但是我遇到了一个非常恼人的场景,如果 .spec.ts 中有任何错误(或 .ts)文件,运行 ng test不会在控制台中显示这些错误。

例如,如果我在文件中有重复导入:

import { DatepickerModule } from 'ngx-bootstrap';
import { DatepickerModule } from 'ngx-bootstrap';

@Component({...})
export class MyComponent { ... }

正常 ng serve将此报告为错误。但是,正在运行 ng test并不总是这样做,它只是无法运行测试,打开带有空白页面的 chrome,说 'Waiting for localhost...' ,并最终失败:
> ng test
10 % building modules 3 / 3 modules 0 active30 08 2019 11: 28: 31.213: WARN[karma]: No captured browser, open http://localhost:9876/
30 08 2019 11: 28: 31.296: INFO[karma - server]: Karma v4.2.0 server started at http://0.0.0.0:9876/
30 08 2019 11: 28: 31.297: INFO[launcher]: Launching browsers Chrome with concurrency unlimited
10 % building modules 4 / 5 modules 1 active ...b\projects\myProject\src\styles.scss30 08 2019 11: 28: 31.720: INFO[launcher]: Starting browser Chrome
30 08 2019 11: 29: 31.722: WARN[launcher]: Chrome have not captured in 60000 ms, killing.
30 08 2019 11: 29: 31.994: INFO[launcher]: Trying to start Chrome again(1 / 2).
30 08 2019 11: 30: 31.996: WARN[launcher]: Chrome have not captured in 60000 ms, killing.
30 08 2019 11: 30: 32.277: INFO[launcher]: Trying to start Chrome again(2 / 2).
30 08 2019 11: 31: 32.279: WARN[launcher]: Chrome have not captured in 60000 ms, killing.
30 08 2019 11: 31: 32.530: ERROR[launcher]: Chrome failed 2 times(timeout).Giving up.

这使得很难弄清楚为什么 Karma 不启动测试,而只是打开一个空白窗口,其中包含神秘的消息 Chrome have not captured in 60000 ms, killing.
我尝试从 the config file documentation 设置日志级别,但它似乎还没有达到加载 karma 的地步,因为实际构建在那之前就失败了(我认为)。

我怎样才能让构建在 spec.ts 中报告这些错误文件?

编辑

使用 --watch=false 运行命令报告编译错误。同样,如果您对规范文件进行更改,导致触发重建(如果您有 --watch=true ),编译错误也会通过 cli 打印在控制台中。

最佳答案

这不是理想的解决方案,但这适用于原始问题:

Running the command with --watch=false reports the compilation errors. Similarly, if you make a change in a spec file, causing the rebuild to trigger (if you have --watch=true), the compilation error is also printed in the console through the cli.

关于angular - Karma ng 测试未在控制台中显示构建错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57724567/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com