Skip to content

Commit 14beae3

Browse files
feat: --posix-exit-codes cli flag in run mode (#32609)
* pass posix exit code to server * return 1 if any tests fail and posix exit codes are enabled * changelog * rm .only * snapshot * changelog * update typedef * changelog * Update cli/CHANGELOG.md Co-authored-by: Jennifer Shehane <[email protected]> * lift disabled posix system test to different desc block * add posix-exit-codes in lib/exec/run.ts#processRunOptions * Apply suggestion from @jennifer-shehane Co-authored-by: Jennifer Shehane <[email protected]> --------- Co-authored-by: Jennifer Shehane <[email protected]>
1 parent 7062573 commit 14beae3

File tree

13 files changed

+81
-3
lines changed

13 files changed

+81
-3
lines changed

cli/CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
<!-- See the ../guides/writing-the-cypress-changelog.md for details on writing the changelog. -->
2-
## 15.3.1
2+
## 15.4.0
33

44
_Released 10/07/2025 (PENDING)_
55

6+
**Features:**
7+
8+
- Added the `--posix-exit-codes` flag for the `run` command. When this flag is passed, Cypress will exit with 1 if any tests fail, rather than the number of failed tests. Addresses [#32605](https://github.com/cypress-io/cypress/issues/32605) and [#24695](https://github.com/cypress-io/cypress/issues/24695). Addressed in [#32609](https://github.com/cypress-io/cypress/pull/32609).
9+
610
**Bugfixes:**
711

812
- Fixed a regression introduced in [`15.0.0`](https://docs.cypress.io/guides/references/changelog#15-0-0) where `dbus` connection error messages appear in docker containers when launching Cypress. Fixes [#32290](https://github.com/cypress-io/cypress/issues/32290).

cli/lib/cli.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ const descriptions: any = {
127127
parallel: 'enables concurrent runs and automatic load balancing of specs across multiple machines or processes',
128128
port: 'runs Cypress on a specific port. overrides any value in cypress.config.{js,ts,mjs,cjs}.',
129129
project: 'path to the project',
130+
posixExitCodes: 'use POSIX exit codes for error handling',
130131
quiet: 'run quietly, using only the configured reporter',
131132
record: 'records the run. sends test results, screenshots and videos to Cypress Cloud.',
132133
reporter: 'runs a specific mocha reporter. pass a path to use a custom reporter. defaults to "spec"',
@@ -259,6 +260,7 @@ const addCypressRunCommand = (program: any): any => {
259260
.option('--parallel', text('parallel'))
260261
.option('-p, --port <port>', text('port'))
261262
.option('-P, --project <project-path>', text('project'))
263+
.option('--posix-exit-codes', text('posixExitCodes'))
262264
.option('-q, --quiet', text('quiet'))
263265
.option('--record [bool]', text('record'), coerceFalse)
264266
.option('-r, --reporter <reporter>', text('reporter'))

cli/lib/exec/run.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ const processRunOptions = (options: any = {}): string[] => {
110110
args.push('--parallel')
111111
}
112112

113+
if (options.posixExitCodes) {
114+
args.push('--posix-exit-codes')
115+
}
116+
113117
if (options.port) {
114118
args.push('--port', options.port)
115119
}

cli/lib/util.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ const parseOpts = (opts: any): any => {
201201
'path',
202202
'parallel',
203203
'port',
204+
'posixExitCodes',
204205
'project',
205206
'quiet',
206207
'reporter',
@@ -449,7 +450,7 @@ const util = {
449450

450451
async function _getRealArch (): Promise<string> {
451452
const osPlatform = os.platform()
452-
// eslint-disable-next-line no-restricted-syntax
453+
453454
const osArch = os.arch()
454455

455456
debug('detecting arch %o', { osPlatform, osArch })
@@ -474,7 +475,6 @@ const util = {
474475
if (['aarch64_be', 'aarch64', 'armv8b', 'armv8l'].includes(stdout)) return 'arm64'
475476
}
476477

477-
// eslint-disable-next-line no-restricted-syntax
478478
const pkgArch = arch()
479479

480480
if (pkgArch === 'x86') return 'ia32'

cli/test/lib/__snapshots__/cli.spec.ts.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ exports[`cli > unknown option > shows help for run command 1`] = `
538538
--parallel enables concurrent runs and automatic load balancing of specs across multiple machines or processes
539539
-p, --port <port> runs Cypress on a specific port. overrides any value in cypress.config.{js,ts,mjs,cjs}.
540540
-P, --project <project-path> path to the project
541+
--posix-exit-codes use POSIX exit codes for error handling
541542
-q, --quiet run quietly, using only the configured reporter
542543
--record [bool] records the run. sends test results, screenshots and videos to Cypress Cloud.
543544
-r, --reporter <reporter> runs a specific mocha reporter. pass a path to use a custom reporter. defaults to "spec"

cli/test/lib/cli.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,11 @@ describe('cli', () => {
651651
expect(run.start).toBeCalledWith({ runnerUi: false })
652652
})
653653

654+
it('calls run with --posix-exit-codes', async () => {
655+
await exec('run --posix-exit-codes')
656+
expect(run.start).toBeCalledWith({ posixExitCodes: true })
657+
})
658+
654659
describe('component-testing', () => {
655660
it('passes to run.start the correct args for component-testing', async () => {
656661
await exec('run --component --dev')

cli/test/lib/exec/run.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ describe('exec run', () => {
142142
it('throws if --config-file is false', () => {
143143
expect(() => run.processRunOptions({ configFile: 'false' })).toThrow()
144144
})
145+
146+
it('adds --posix-exit-codes', () => {
147+
expect(run.processRunOptions({ posixExitCodes: true })).toEqual(expect.arrayContaining(['--posix-exit-codes']))
148+
})
145149
})
146150

147151
describe('.start', () => {

cli/types/cypress-npm-api.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ declare namespace CypressCommandLine {
6868
* Override default port
6969
*/
7070
port: number
71+
/**
72+
* Use POSIX exit codes for error handling
73+
*/
74+
posixExitCodes: boolean
7175
/**
7276
* Run quietly, using only the configured reporter
7377
*/

packages/server/lib/cypress.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,10 @@ export = {
266266
}
267267
}
268268

269+
if (options.posixExitCodes) {
270+
return results.totalFailed ? 1 : 0
271+
}
272+
269273
return results.totalFailed
270274
})
271275
.then(exit)

packages/server/lib/util/args.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const allowList = [
3737
'parallel',
3838
'ping',
3939
'port',
40+
'posixExitCodes',
4041
'project',
4142
'proxySource',
4243
'quiet',
@@ -366,6 +367,7 @@ module.exports = {
366367
'run-project': 'runProject',
367368
'smoke-test': 'smokeTest',
368369
'testing-type': 'testingType',
370+
'posix-exit-codes': 'posixExitCodes',
369371
}
370372

371373
// takes an array of args and converts

0 commit comments

Comments
 (0)