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

标签 angular typescript karma-jasmine

我正在使用 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/

相关文章:

Angular 8 : Problems with QueryParamsHandling

angular - NullInjectorError : No provider for MediaMatcher

typescript - 为什么 $ 在 Angular 2 中不被识别?

angular - 如何将 Angular2 组件渲染为字符串?

javascript - 如何使用 Visual Studio Code 调试 Angular 4 单元测试

javascript - Azure 应用程序配置客户端库 - getConfigurationSetting 的缓存

npm - 无法使用 TSC - 读取文件时出错 "anything.ts": File not found

typescript - Vue/TypeScript/ESLint/Prettier/Vetur 格式不起作用

javascript - 为什么我的 Jasmine 测试在这个指令上失败了?

Angular 5/Jasmine 单元测试 - 无法读取未定义的属性 'componentInstance'