Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cli/lib/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ const descriptions: any = {
parallel: 'enables concurrent runs and automatic load balancing of specs across multiple machines or processes',
port: 'runs Cypress on a specific port. overrides any value in cypress.config.{js,ts,mjs,cjs}.',
project: 'path to the project',
posixExitCodes: 'use POSIX exit codes for error handling',
quiet: 'run quietly, using only the configured reporter',
record: 'records the run. sends test results, screenshots and videos to Cypress Cloud.',
reporter: 'runs a specific mocha reporter. pass a path to use a custom reporter. defaults to "spec"',
Expand Down Expand Up @@ -259,6 +260,7 @@ const addCypressRunCommand = (program: any): any => {
.option('--parallel', text('parallel'))
.option('-p, --port <port>', text('port'))
.option('-P, --project <project-path>', text('project'))
.option('--posix-exit-codes', text('posixExitCodes'))
.option('-q, --quiet', text('quiet'))
.option('--record [bool]', text('record'), coerceFalse)
.option('-r, --reporter <reporter>', text('reporter'))
Expand Down
4 changes: 2 additions & 2 deletions cli/lib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ const parseOpts = (opts: any): any => {
'path',
'parallel',
'port',
'posixExitCodes',
'project',
'quiet',
'reporter',
Expand Down Expand Up @@ -449,7 +450,7 @@ const util = {

async function _getRealArch (): Promise<string> {
const osPlatform = os.platform()
// eslint-disable-next-line no-restricted-syntax

const osArch = os.arch()

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

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

if (pkgArch === 'x86') return 'ia32'
Expand Down
5 changes: 5 additions & 0 deletions cli/test/lib/cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,11 @@ describe('cli', () => {
expect(run.start).toBeCalledWith({ runnerUi: false })
})

it.only('calls run with --posix-exit-codes', async () => {
await exec('run --posix-exit-codes')
expect(run.start).toBeCalledWith({ posixExitCodes: true })
})

describe('component-testing', () => {
it('passes to run.start the correct args for component-testing', async () => {
await exec('run --component --dev')
Expand Down
4 changes: 4 additions & 0 deletions packages/server/lib/cypress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ export = {
}
}

if (options.posixExitCodes) {
return results.totalFailed ? 1 : 0
}

return results.totalFailed
})
.then(exit)
Expand Down
2 changes: 2 additions & 0 deletions packages/server/lib/util/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const allowList = [
'parallel',
'ping',
'port',
'posixExitCodes',
'project',
'proxySource',
'quiet',
Expand Down Expand Up @@ -366,6 +367,7 @@ module.exports = {
'run-project': 'runProject',
'smoke-test': 'smokeTest',
'testing-type': 'testingType',
'posix-exit-codes': 'posixExitCodes',
}

// takes an array of args and converts
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/modeOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface RunModeOptions extends CommonModeOptions {
ciBuildId?: string | null
tag?: (string)[] | null
isBrowserGivenByCli: boolean
posixExitCodes?: boolean | null
}

export type TestingType = 'e2e' | 'component'
Expand Down
10 changes: 10 additions & 0 deletions system-tests/lib/system-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ type ExecOptions = {
* Run Cypress with a custom user node version.
*/
userNodeVersion?: string
/**
* Run Cypress with POSIX exit codes.
*/
posixExitCodes?: boolean
}

type Server = {
Expand Down Expand Up @@ -764,6 +768,12 @@ const systemTests = {
args.push(`--userNodeVersion=${options.userNodeVersion}`)
}

debug('posixExitCodes', options.posixExitCodes)

if (options.posixExitCodes) {
args.push('--posix-exit-codes')
}

return args
},

Expand Down
31 changes: 31 additions & 0 deletions system-tests/test/posix_exit_codes_spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import systemTests from '../lib/system-tests'

describe('posix exit codes', () => {
systemTests.setup()

describe('when posix exit codes are enabled', () => {
systemTests.it('returns 1 when there are failing tests', {
spec: 'simple_failing.cy.js',
posixExitCodes: true,
expectedExitCode: 1,
browser: ['electron'],
project: 'e2e',
})

systemTests.it('returns 2 when there are 2 failing tests and posix is disabled', {
spec: 'simple_failing.cy.js',
posixExitCodes: false,
expectedExitCode: 2,
browser: ['electron'],
project: 'e2e',
})

systemTests.it('returns 0 when there are no failing tests', {
spec: 'simple_passing.cy.js',
posixExitCodes: true,
expectedExitCode: 0,
browser: ['electron'],
project: 'e2e',
})
})
})
Loading