Execution order of `after` hooks when globally defined is not direct opposite of `before` hooks execution order
See original GitHub issueCurrent behavior:
In before
hooks, the hooks defined in support/index.js
execute first, before any hooks defined in the spec file, but in the after
hooks, the hooks defined in support/index.js
do not execute last - the after
hooks defined in the spec file run last.
I verified this is not a UI only issue - this is how they execute.
Desired behavior:
This behavior is not what I was expecting. I would expect the after
hooks to execute in the exact opposite as before
hooks had - in the same manner. Maybe I’m missing something.
This seems to be how they’ve always run, tested back to 3.4.1.
Test code to reproduce
support/index.js
before(() => {
cy.log('support/index.js before')
console.log('support/index.js before')
})
beforeEach(() => {
cy.log('support/index.js beforeEach')
console.log('support/index.js beforeEach')
})
afterEach(() => {
cy.log('support/index.js afterEach')
console.log('support/index.js afterEach')
})
after(() => {
cy.log('support/index.js after')
console.log('support/index.js after')
})
spec.js
before(() => {
cy.log('main before')
console.log('main before')
})
beforeEach(() => {
cy.log('main beforeEach')
console.log('main beforeEach')
})
describe('my tests', () => {
before(() => {
cy.log('suite before')
console.log('suite before')
})
beforeEach(() => {
cy.log('suite beforeEach')
console.log('suite beforeEach')
})
it('visit', () => {
cy.log('test body')
console.log('test body')
})
afterEach(() => {
cy.log('suite afterEach')
console.log('suite afterEach')
})
after(() => {
cy.log('suite after')
console.log('suite after')
})
})
afterEach(() => {
cy.log('main afterEach')
console.log('main afterEach')
})
after(() => {
cy.log('main after')
console.log('main after')
})
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6 (2 by maintainers)
Top Results From Across the Web
How to define Execution Order of Hooks in Cucumber - Tools QA
Order hooks to run in a particular sequence is easy to do. As we already know the way to specify hooks in cucumber-like...
Read more >Hooks - SpecFlow's documentation
Hooks are global, but can be restricted to run only for features or scenarios by defining a scoped binding, which can be filtered...
Read more >Hooks - Sequelize
Hooks (also known as lifecycle events), are functions which are called before and after calls in sequelize are executed. For example, if you...
Read more >Order of execution for event functions - Unity - Manual
Script lifecycle overview · First Scene Load · Editor · Before the first frame update · In between frames · Update order ·...
Read more >Ruby cucumber scenario hook execution order - Stack Overflow
I have an After hook that gets executed before a hook on the scenario itself. I want to reverse the order of those...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve added a reproducible example in Cypress 10 here
Still seeing this in cypress 9.6.0