Compilation errors don't cause non-zero exit codes in ng test #2778
Description
Please provide us with the following information:
OS?
Windows 7, 8 or 10. Linux (which distribution). Mac OSX (Yosemite? El Capitan?)
OS X El Capitan
Versions.
Please run
ng --version. If there's nothing outputted, please run in a Terminal:node --versionand paste the result here:angular-cli: 1.0.0-beta.17 node: 6.3.0 os: darwin x64Repro steps.
Was this an app that wasn't created using the CLI? What change did you do on your code? etc.
Create a angular cli project, create a compilation error in a spec file that doesn't fail at runtime (e.g. omit constructor parameter) and runng test
The log given by the failure.
Normally this include a stack trace and some more information.
For example, this output of a test run of ng test:
ERROR in [default] /Users/jr/dev/console/console/src/app/context/context.service.spec.ts:17:12
Supplied parameters do not match any signature of call target.
ERROR in [default] /Users/jr/dev/console/console/src/app/context/location.spec.ts:8:11
Supplied parameters do not match any signature of call target.
19 10 2016 14:05:24.377:INFO [karma]: Karma v1.2.0 server started at http://localhost:9876/
19 10 2016 14:05:24.380:INFO [launcher]: Launching browser Chrome with unlimited concurrency
19 10 2016 14:05:24.511:INFO [launcher]: Starting browser Chrome
19 10 2016 14:05:25.882:INFO [Chrome 53.0.2785 (Mac OS X 10.11.6)]: Connected on socket /#pLo6aNiQB7OJVlxvAAAA with id 31332214
Chrome 53.0.2785 (Mac OS X 10.11.6): Executed 10 of 10 SUCCESS (0.77 secs / 0.754 secs)
iDevBook01:console jr$ $?
-bash: 0: command not found
Mention any other details that might be useful.
It would be useful if angular-cli captured the error code when compiling typescript code and failed early. ng build doesn't build tests, so it's not useful either.
Thanks! We'll be in touch soon.
Activity
kylecordes commentedon Oct 21, 2016
This also affects, for example,
ng build. An argument could be made thatng serveshould carry on even with typescript errors, but build and test presumably should fail if the code is broken.filipesilva commentedon Oct 27, 2016
Commands like
ng test,ng serveandng build --watchthat run in watch mode don't usually exit with an error. This is by design.Non-watch commands like
ng test --watch=false,ng buildandng e2edo exit with an error code though, so I think what you're looking for isng test --watch=false.For instance, I removed
AppComponentparameters inlet fixture = TestBed.createComponent(AppComponent);, which causes theSupplied parameters do not match any signature of call target.error:@kylecordes I don't understand what you're talking about. Have you tried
ng buildwith a compilation error and did not get an error exit code? If so, please open a new issue with a reproduction.JohannesRudolph commentedon Oct 28, 2016
Thanks for responding and your great work on angular-cli @filipesilva
sorry for not being more specific in the original request. The error is a build error not a test error. I did indeed execute the test with
ng test --watch=falseand observed that the exit code is zero (see below for a full reproduction).I agree about returning nothing meaningful in
--watch=true, but the original issue still stands. Is that enough for reopening this issue?filipesilva commentedon Nov 3, 2016
A build error should definitely make
ng test --watch=falseexit with an error code. In my test it did, but in your case it did not even though they should have been very similar.Can you give me the exact code I can use to reproduce?
fabian-dev commentedon Nov 18, 2016
I can confirm this.
In a new angular-cli Project create a spec that has TS errors, but is valid JS. Example
app.component.spec.ts:Although not valid TS, ng test will pass with RC=0.
afterwards
$ echo $?gives me0.I would expect ng test to fail on TS errors.
JohannesRudolph commentedon Jan 23, 2017
Any news on this?
fix(@angular/cli): fix error handling on test
fix(@angular/cli): fix error handling on test
fix(@angular/cli): fix error handling on test
fix(@angular/cli): fix error handling on test
fix(@angular/cli): fix error handling on test
fix(@angular/cli): fix error handling on test
smkart commentedon Apr 24, 2019
@hansl What version of cli come with this fix?
In my case I am using Jenkins to "ng test" , Because of exit code is always 0 Jenkins pipeline never goes to failed
We are using cli v1.7.3 and we don't have any roadmap to upgrade cli version for now, I am not sure in which version this issue got fixed
Thanks in advance
Regards,
Mani
Applied Materials
umutau commentedon Apr 24, 2019
in my case
ng test --watch=false --browsers=ChromeHeadless && ng buildis working as expectedangular-automatic-lock-bot commentedon Sep 9, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.
fix(@angular/cli): fix error handling on test