This repository has been archived by the owner on May 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(config): allow env var RETRIES_HIDDEN to hide retried tests… (#22)
* fix: fix before all failure not stopping test execution * Add demonstration test * fix before-error-spec * chore: add e2e test support, tests * feat(config): add RETRIES_HIDDEN config - hides command logs of retried tests, so you only see the last failure * chore: fix e2e tests in CI * chore: fix e2e tests in CI 2 * fix: prevent erroneous passing last test in suite with after hook
- Loading branch information
Showing
15 changed files
with
818 additions
and
131 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{ | ||
"projectId": "3e57fb" | ||
"projectId": "3e57fb", | ||
"integrationFolder": "cypress/tests" | ||
} |
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 |
---|---|---|
|
@@ -4,5 +4,8 @@ | |
], | ||
"extends": [ | ||
"plugin:cypress/recommended" | ||
] | ||
], | ||
"rules": { | ||
"cypress/no-unnecessary-waiting": "off" | ||
} | ||
} |
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,30 @@ | ||
/// <reference types="cypress"/> | ||
|
||
/* EXPECT: { | ||
totalFailed: 1, | ||
totalPassed: 1 | ||
} */ | ||
|
||
describe('should not pass when really failed', () => { | ||
|
||
it('expect pass', () => { | ||
Cypress.currentTest.retries(2) | ||
|
||
cy.wait(10).should(() => { | ||
// throw new Error('foo') | ||
}) | ||
}) | ||
|
||
it('expect fail', () => { | ||
Cypress.currentTest.retries(2) | ||
|
||
cy.wait(10).should(() => { | ||
throw new Error('foo') | ||
}) | ||
}) | ||
|
||
after(() => { | ||
Cypress.log({ message: 'foo' }) | ||
}) | ||
|
||
}) |
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,20 @@ | ||
/// <reference types="cypress"/> | ||
|
||
/* EXPECT: { | ||
totalFailed: 1, | ||
totalPassed: 0 | ||
} */ | ||
|
||
describe('should not pass when really failed', () => { | ||
it('expect fail', () => { | ||
Cypress.currentTest.retries(2) | ||
|
||
cy.wait(10).should(() => { | ||
throw new Error('foo') | ||
|
||
}) | ||
}) | ||
|
||
after(() => {}) | ||
|
||
}) |
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,44 @@ | ||
/// <reference types="cypress"/> | ||
|
||
const { _ } = Cypress | ||
|
||
const getFailTwice = () => { | ||
return _.before(3, () => { | ||
throw new Error('foo') | ||
}) | ||
} | ||
|
||
let failTwice = getFailTwice() | ||
|
||
describe('suite', () => { | ||
it('expect pass 1', () => { | ||
Cypress.currentTest.retries(2) | ||
|
||
cy.wait(10).should(() => { | ||
failTwice() | ||
failTwice = getFailTwice() | ||
}) | ||
}) | ||
|
||
it('expect pass 2', () => { | ||
Cypress.currentTest.retries(2) | ||
|
||
cy.wait(10).should(() => { | ||
failTwice() | ||
failTwice = getFailTwice() | ||
}) | ||
}) | ||
|
||
it('expect pass 3', () => { | ||
Cypress.currentTest.retries(2) | ||
|
||
cy.wait(10).should(() => { | ||
// throw new Error('foo') | ||
failTwice() | ||
failTwice = getFailTwice | ||
}) | ||
}) | ||
|
||
after(() => { | ||
}) | ||
}) |
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,71 @@ | ||
/// <reference types="cypress"/> | ||
|
||
const runner = Cypress.mocha.getRunner() | ||
|
||
const getTest = (r) => r && r.ctx.currentTest || r | ||
|
||
const throwMetaError = (mes) => { | ||
const err = new Error(mes) | ||
|
||
err.name = 'MetaError' | ||
throw err | ||
} | ||
|
||
const throwFakeError = (mes) => { | ||
const err = new Error(mes) | ||
|
||
err.name = 'FakeError' | ||
throw err | ||
} | ||
|
||
Cypress.on('test:before:run', () => { | ||
|
||
runner.once('fail', (r) => { | ||
const runnable = cy.state('runnable') | ||
const test = getTest(runnable) | ||
|
||
if (test.err.name === 'Uncaught MetaError') { | ||
test.err.message = test.err.message.split('\nThis error originated from')[0] | ||
|
||
return | ||
} | ||
|
||
if (test.err.name === 'FakeError') { | ||
|
||
test.error = null | ||
test.state = 'passed' | ||
|
||
} | ||
|
||
}) | ||
|
||
}) | ||
|
||
describe('Exception in before block', () => { | ||
describe('Broken case', () => { | ||
before(() => { | ||
Cypress.currentTest.retries(1) | ||
|
||
throwFakeError('This is the real error!') | ||
}) | ||
|
||
it('shouldn\'t run this test', () => { | ||
throwMetaError('should not have ran') | ||
}) | ||
|
||
it(`also shouldn't run this`, () => { | ||
throwMetaError('should not have ran 2') | ||
}) | ||
}) | ||
|
||
describe('Working case', () => { | ||
before(() => { | ||
Cypress.currentTest.retries(0) | ||
throwFakeError('This is the real error!') | ||
}) | ||
|
||
it('shouldn\'t run this test', () => { | ||
throwMetaError('should not have ran') | ||
}) | ||
}) | ||
}) |
File renamed without changes.
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,27 @@ | ||
/// <reference types="cypress"/> | ||
|
||
const { _ } = Cypress | ||
|
||
Cypress.env('RETRIES_HIDDEN', true) | ||
|
||
if (!top.alreadyRan) { | ||
top.alreadyRan = true | ||
cy.$$('.restart', top.document).click() | ||
} | ||
|
||
const failTwice = _.before(3, () => { | ||
throw new Error('foo') | ||
}) | ||
|
||
describe('suite', () => { | ||
|
||
it('retries are hidden when RETRIES_HIDDEN', () => { | ||
Cypress.currentTest.retries(2) | ||
|
||
cy.wait(10).should(() => { | ||
failTwice() | ||
cy.wrap(cy.$$('.retry-0', top.document)).should('not.be.visible') | ||
}) | ||
|
||
}) | ||
}) |
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
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,5 @@ | ||
{ | ||
"extends": [ | ||
"plugin:@cypress/dev/tests" | ||
] | ||
} |
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,18 @@ | ||
const { runTest } = require('../helpers') | ||
const path = require('path') | ||
const glob = require('fast-glob') | ||
|
||
describe('can test', async () => { | ||
|
||
glob.sync(path.join(__dirname, '../../cypress/tests/e2e/**.*')) | ||
.map((v) => { | ||
// .mapSeries((v) => { | ||
const filename = path.relative(process.cwd(), v) | ||
|
||
it(`test: ${filename}`, async () => { | ||
await runTest({ | ||
spec: v, | ||
}) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.