Skip to content

Commit 572f35d

Browse files
committed
docs: detailed exit code scenarios
1 parent 76b9478 commit 572f35d

File tree

1 file changed

+11
-77
lines changed

1 file changed

+11
-77
lines changed

docs/app/references/command-line.mdx

Lines changed: 11 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -598,86 +598,20 @@ Cypress Cloud will display any tags sent with the appropriate run.
598598
599599
#### Exit code
600600
601-
When Cypress finishes running tests, it exits. If there are no failed tests, the
602-
exit code will be 0.
601+
Cypress supports two different exit code behaviors. The default behavior is similar to that of Mocha, but is not POSIX compliant: reserved exit codes can be returned for certain conditions. As well, the default behavior
602+
can return a false negative when there are a number of tests that fail in multiples of 255.
603603
604-
```text
605-
## All tests pass
606-
$ cypress run
607-
...
608-
Tests Passing Failing
609-
✔ All specs passed! 00:16 17 17 0
604+
POSIX compliant exit codes are available via the `--posix-exit-codes` flag. When this flag is passed, additional conditions can be returned that are not possible with the default behavior, including when Cypress fails due to
605+
network errors when connections to Cypress Cloud are required, such as in `--record` or `--parallel` runs.
610606
611-
## print exit code on Mac or Linux
612-
$ echo $?
613-
0
614-
```
615-
616-
By default, if there are any test failures, then the exit code will match the number of
617-
tests that failed.
618-
619-
```text
620-
## Spec with two failing tests
621-
$ cypress run
622-
...
623-
Tests Passing Failing
624-
✖ 1 of 1 failed (100%) 00:22 17 14 2
625-
626-
## print exit code on Mac or Linux
627-
$ echo $?
628-
2
629-
```
630-
631-
You can change this behavior by passing the `--posix-exit-codes` flag. When this flag is passed,
632-
the exit code will be 0 if all tests pass. If there are any test failures or if Cypress could not run,
633-
the exit code will be 1.
634-
635-
```text
636-
## Spec with two failing tests
637-
$ cypress run --posix-exit-codes
638-
...
639-
Tests Passing Failing
640-
✖ 1 of 1 failed (100%) 00:22 17 14 2
641-
642-
## print exit code on Mac or Linux
643-
$ echo $?
644-
1
645-
```
646-
647-
When you use the `--posix-exit-codes` flag in a run that requires [Cypress Cloud](/cloud/get-started/introduction), and the Cypress application cannot communicate with the Cypress Cloud API due to a network error, the exit code will be `112`. Runs that use either `--record` or `--parallel` require communication with Cypress Cloud API.
648-
649-
```text
650-
$ cypress run --posix-exit-codes --parallel --group=foo --ciBuildId=ciBuildId123
651-
We encountered an unexpected error communicating with our servers.
607+
When using POSIX compliant exit codes, the number of failed tests can be determined from [structured reporter data](/app/tooling/reporters).
652608
653-
RequestError: Error: ESOCKETTIMEDOUT
654-
655-
Because you passed the --parallel flag, this run cannot proceed since it requires a valid response from our servers.
656-
657-
The --group flag you passed was: foo
658-
The --ciBuildId flag you passed was: ciBuildId123
659-
660-
$ echo $?
661-
112
662-
```
663-
664-
If Cypress could not run for some reason (for example if no spec files were
665-
found) then the exit code will be 1.
666-
667-
```text
668-
## No spec files found
669-
$ cypress run --spec not-found.js
670-
...
671-
Can't run because no spec files were found.
672-
673-
We searched for any files matching this glob pattern:
674-
675-
not-found.js
676-
677-
## print exit code on Mac or Linux
678-
$ echo $?
679-
1
680-
```
609+
| Exit Condition | POSIX Exit Code (with `--posix-exit-codes`) | Default Exit Code (without `--posix-exit-codes`) |
610+
| ------------------------------------------------------------------------------------------- | ------------------------------------------- | ------------------------------------------------ |
611+
| All tests pass | 0 | 0 |
612+
| _n_ tests fail | 1 | _n_ |
613+
| Cypress could not run due to a network error when connections to Cypress Cloud are required | 112 | 1 |
614+
| Cypress could not run for any other reason, including no spec files found | 1 | 1 |
681615
682616
### `cypress open`
683617

0 commit comments

Comments
 (0)