I've encountered a frustrating issue while working with Karma and Jasmine for testing in my Angular 7 project. The problem arises when there are errors present in the .spec.ts or .ts files, as running ng test does not display these errors in the console.
For example, if I mistakenly have a duplicate import in a file:
import { DatepickerModule } from 'ngx-bootstrap';
import { DatepickerModule } from 'ngx-bootstrap';
@Component({...})
export class MyComponent { ... }
While ng serve correctly flags this as an error, running ng test often fails to do so. Instead of displaying the errors, it simply fails to run the tests, opening Chrome with a blank page and showing 'Waiting for localhost...' before eventually failing to complete:
> 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.
This lack of feedback makes it challenging to diagnose why Karma isn't launching the tests and instead displays the vague message 'Chrome have not captured in 60000 ms, killing.'
I attempted adjusting the log level as per the configuration file documentation, but it seems that the build fails before reaching this point (I suspect).
Is there a way to ensure that compilation errors in the spec.ts files are reported during the build?
Edit
By running the command with --watch=false, I was able to view the compilation errors. Similarly, initiating a rebuild by modifying a spec file (if --watch=true), also triggers the display of compilation errors in the console through the CLI.