@@ -2,6 +2,7 @@ Feature: hooks ordering
22
33 Hooks should be executed in the following order:
44 - before
5+ - BeforeAll
56 - beforeEach
67 - Before
78 - Background steps
@@ -10,14 +11,17 @@ Feature: hooks ordering
1011 - AfterStep (in reverse order)
1112 - After
1213 - afterEach
14+ - AfterAll
1315 - after
1416
17+ @foo
1518 Scenario : with all hooks incrementing a counter
1619 Given a file named "cypress/e2e/a.feature" with:
1720 """
1821 Feature: a feature
1922 Background:
2023 Given a background step
24+ @foo
2125 Scenario: a scenario
2226 Given an ordinary step
2327 """
@@ -28,50 +32,58 @@ Feature: hooks ordering
2832 Before,
2933 After,
3034 BeforeStep,
31- AfterStep
35+ AfterStep,
36+ BeforeAll,
37+ AfterAll
3238 } = require("@badeball/cypress-cucumber-preprocessor")
3339 let counter;
3440 before(function() {
3541 counter = 0;
3642 })
43+ BeforeAll(() => {
44+ expect(counter++, "Expect BeforeAll() to be called after beforeEach()").to.equal(0)
45+ })
3746 beforeEach(function() {
38- expect(counter++, "Expected beforeEach() to be called after before()").to.equal(0 )
47+ expect(counter++, "Expected beforeEach() to be called after before()").to.equal(1 )
3948 })
4049 Before(function() {
41- expect(counter++, "Expected Before() to be called after beforeEach()").to.equal(1 )
50+ expect(counter++, "Expected Before() to be called after beforeEach()").to.equal(2 )
4251 })
4352 Given("a background step", function() {
44- expect(counter++, "Expected a background step to be called after Before()").to.equal(2 )
53+ expect(counter++, "Expected a background step to be called after Before()").to.equal(3 )
4554 })
4655 BeforeStep(function ({ pickleStep }) {
4756 if (pickleStep.text === "an ordinary step") {
48- expect(counter++, "Expected BeforeStep() to be called before ordinary steps").to.equal(3 )
57+ expect(counter++, "Expected BeforeStep() to be called before ordinary steps").to.equal(4 )
4958 }
5059 })
5160 Given("an ordinary step", function() {
52- expect(counter++, "Expected an ordinary step to be called after a background step").to.equal(4 )
61+ expect(counter++, "Expected an ordinary step to be called after a background step").to.equal(5 )
5362 })
5463 AfterStep(function ({ pickleStep }) {
5564 if (pickleStep.text === "an ordinary step") {
56- expect(counter++, "Expected AfterStep() to be called after ordinary steps").to.equal(6 )
65+ expect(counter++, "Expected AfterStep() to be called after ordinary steps").to.equal(7 )
5766 }
5867 })
5968 AfterStep(function ({ pickleStep }) {
6069 if (pickleStep.text === "an ordinary step") {
61- expect(counter++, "Expected AfterStep() to be called after ordinary steps").to.equal(5 )
70+ expect(counter++, "Expected AfterStep() to be called after ordinary steps").to.equal(6 )
6271 }
6372 })
6473 After(function() {
65- expect(counter++, "Expected After() to be called in reverse order of definition").to.equal(8 )
74+ expect(counter++, "Expected After() to be called in reverse order of definition").to.equal(9 )
6675 })
6776 After(function() {
68- expect(counter++, "Expected After() to be called after ordinary steps").to.equal(7 )
77+ expect(counter++, "Expected After() to be called after ordinary steps").to.equal(8 )
6978 })
7079 afterEach(function() {
71- expect(counter++, "Expected afterEach() to be called after After()").to.equal(9)
80+ expect(counter++, "Expected afterEach() to be called after After()").to.equal(10)
81+ })
82+ AfterAll(function() {
83+ expect(counter++, "Expected AfterAll() to be called after afterEach()").to.equal(11)
7284 })
7385 after(function() {
74- expect(counter++, "Expected after() to be called after afterEach ()").to.equal(10 )
86+ expect(counter++, "Expected after() to be called after AfterAll ()").to.equal(12 )
7587 })
7688 """
7789 When I run cypress
0 commit comments