-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Do not screenshot or trigger the failed event when tests are ski…
…pped
- Loading branch information
1 parent
dd0fc9b
commit 841c82d
Showing
4 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
packages/driver/cypress/integration/cy/skipping_async_spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
const { Screenshot } = Cypress | ||
|
||
let failedEventFired = false | ||
|
||
Cypress.on('fail', (error) => { | ||
failedEventFired = true | ||
throw new Error(error) | ||
}) | ||
|
||
let screenshotTaken = false | ||
|
||
Screenshot.defaults({ onAfterScreenshot: () => { | ||
screenshotTaken = true | ||
} }) | ||
|
||
const pendingTests = [] | ||
const passedTests = [] | ||
|
||
Cypress.on('test:after:run', (test) => { | ||
if (test.state === 'pending') { | ||
return pendingTests.push(test) | ||
} | ||
|
||
if (test.state === 'passed') { | ||
return passedTests.push(test) | ||
} | ||
}) | ||
|
||
beforeEach(() => { | ||
// Set isInteractive to false to ensure that screenshots will be | ||
// triggered in both run and open mode | ||
Cypress.config('isInteractive', false) | ||
}) | ||
|
||
describe('skipped test', () => { | ||
it('does not fail', function () { | ||
cy.then(() => { | ||
this.skip() | ||
}).then(() => { | ||
expect(true).to.be.false | ||
}) | ||
}) | ||
|
||
it('does not prevent subsequent tests from running', () => { | ||
expect(true).to.be.true | ||
}) | ||
}) | ||
|
||
describe('skipped test side effects', () => { | ||
it('does not have a screenshot taken', () => { | ||
expect(screenshotTaken).to.be.false | ||
}) | ||
|
||
it('does not fire failed event', () => { | ||
expect(failedEventFired).to.be.false | ||
}) | ||
|
||
it('does still mark all tests with the correct state', () => { | ||
expect(pendingTests).to.have.length(1) | ||
expect(passedTests).to.have.length(3) | ||
}) | ||
}) |
70 changes: 70 additions & 0 deletions
70
packages/driver/cypress/integration/cy/skipping_sync_spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
const { Screenshot } = Cypress | ||
|
||
let failedEventFired = false | ||
|
||
Cypress.on('fail', (error) => { | ||
failedEventFired = true | ||
throw new Error(error) | ||
}) | ||
|
||
let screenshotTaken = false | ||
|
||
Screenshot.defaults({ onAfterScreenshot: () => { | ||
screenshotTaken = true | ||
} }) | ||
|
||
const pendingTests = [] | ||
const passedTests = [] | ||
|
||
Cypress.on('test:after:run', (test) => { | ||
if (test.state === 'pending') { | ||
return pendingTests.push(test) | ||
} | ||
|
||
if (test.state === 'passed') { | ||
return passedTests.push(test) | ||
} | ||
}) | ||
|
||
beforeEach(() => { | ||
// Set isInteractive to false to ensure that screenshots will be | ||
// triggered in both run and open mode | ||
Cypress.config('isInteractive', false) | ||
}) | ||
|
||
describe('generally skipped test', () => { | ||
before(function () { | ||
this.skip() | ||
}) | ||
|
||
it('does not fail', function () { | ||
expect(true).to.be.false | ||
}) | ||
}) | ||
|
||
describe('individually skipped tests', () => { | ||
it('does not fail when using this.skip', function () { | ||
this.skip() | ||
expect(true).to.be.false | ||
}) | ||
|
||
// NOTE: We are skipping this test in order to test skip functionality | ||
it.skip('does not fail when using it.skip', () => { | ||
expect(true).to.be.false | ||
}) | ||
}) | ||
|
||
describe('skipped test side effects', () => { | ||
it('does not have a screenshot taken', () => { | ||
expect(screenshotTaken).to.be.false | ||
}) | ||
|
||
it('does not fire failed event', () => { | ||
expect(failedEventFired).to.be.false | ||
}) | ||
|
||
it('does still mark all tests with the correct state', () => { | ||
expect(pendingTests).to.have.length(3) | ||
expect(passedTests).to.have.length(2) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters