Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add --failing #15

Merged
merged 2 commits into from
Nov 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ jobs:
install: false
command: node . run --passing 3 --spec '**/spec.js'

- name: Check --failing 🧪
uses: cypress-io/github-action@v2
with:
# we have already installed all dependencies above
install: false
command: node . run --passing 1 --failing 1 --config integrationFolder=cypress/failing

- name: Semantic Release 🚀
uses: cycjimmy/semantic-release-action@v2
env:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules/
cypress/screenshots/
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ The rest of the arguments is parsed using [Cypress CLI method](https://on.cypres

`--min-passing <N>` checks if the total number of passing tests is `>= <N>`

`--failing <N>` checks if the total number of failing tests is `<N>`

`--pending <N>` checks if the total number of pending tests is `<N>`

## Debugging
Expand Down
11 changes: 11 additions & 0 deletions cypress/failing/spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/// <reference types="cypress" />

describe('1 passing 1 failing', () => {
it('passes', () => {
cy.wait(100)
})

it('fails', () => {
expect(true).to.be.false
})
})
39 changes: 30 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const args = arg(
{
'--passing': Number, // number of total passing tests to expect
'--min-passing': Number, // at least this number of passing tests
'--failing': Number, // number of failing tests to expect
'--pending': Number, // number of pending tests to expect
},
{
Expand All @@ -26,20 +27,25 @@ debug('args %o', args)

const isPassingSpecified = '--passing' in args
const isMinPassingSpecified = '--min-passing' in args
const isFailingSpecified = '--failing' in args
const isPendingSpecified = '--pending' in args
const noOptionsSpecified =
!isPassingSpecified && !isMinPassingSpecified && !isPendingSpecified
!isPassingSpecified &&
!isMinPassingSpecified &&
!isPendingSpecified &&
!isFailingSpecified

debug('specified options %o', {
isPassingSpecified,
isMinPassingSpecified,
isFailingSpecified,
isPendingSpecified,
noOptionsSpecified,
})

if (noOptionsSpecified) {
console.error('Need to specify at least one parameter:')
console.error('--passing or --min-passing or --pending')
console.error('--passing or --min-passing or --failing or --pending')
process.exit(1)
}

Expand All @@ -60,19 +66,22 @@ if (isMinPassingSpecified) {
}
}

if (isPassingSpecified && isMinPassingSpecified) {
console.error('Cannot specify both --passing and --min-passing options')
process.exit(1)
if (isFailingSpecified) {
if (!isValidPassing(args['--failing'])) {
console.error('expected a number of --failing tests', args['--failing'])
process.exit(1)
}
}

if (!isPassingSpecified && !isMinPassingSpecified) {
if (isPassingSpecified && isMinPassingSpecified) {
console.error('Cannot specify both --passing and --min-passing options')
process.exit(1)
}

debug('params %o', {
passing: args['--passing'],
minPassing: args['--min-passing'],
failing: args['--failing'],
pending: args['--pending'],
})

Expand Down Expand Up @@ -122,9 +131,21 @@ parseArguments()
}
debug('test totals %o', totals)

if (totals.failed) {
console.error('%d test(s) failed', totals.failed)
process.exit(totals.failed)
if (isFailingSpecified) {
if (totals.failed !== args['--failing']) {
console.error(
'ERROR: expected %d failing tests, got %d',
args['--failing'],
totals.failed,
)
process.exit(1)
}
} else {
// any unexpected failed tests are bad
if (totals.failed) {
console.error('%d test(s) failed', totals.failed)
process.exit(totals.failed)
}
}

if (isPassingSpecified) {
Expand Down