Skip to content

Commit 2dc1d8e

Browse files
committed
Handle more corner cases related to reload-behavior
This fixes #1142 [1]. [1] #1142
1 parent 27c6d37 commit 2dc1d8e

File tree

10 files changed

+685
-61
lines changed

10 files changed

+685
-61
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## Unreleased
6+
7+
- Handle more corner cases related to reload-behavior, fixes [#1142](https://github.com/badeball/cypress-cucumber-preprocessor/issues/1142).
8+
59
## v20.0.0
610

711
Breaking changes:
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
[
2+
{
3+
"description": "",
4+
"elements": [
5+
{
6+
"description": "",
7+
"id": "a-feature;a-scenario",
8+
"keyword": "Scenario",
9+
"line": 3,
10+
"name": "a scenario",
11+
"steps": [
12+
{
13+
"arguments": [],
14+
"keyword": "Given ",
15+
"line": 4,
16+
"name": "a step",
17+
"match": {
18+
"location": "not available:0"
19+
},
20+
"result": {
21+
"status": "passed",
22+
"duration": 0
23+
}
24+
}
25+
],
26+
"tags": [
27+
{
28+
"name": "@env(origin=\"https://duckduckgo.com/\")",
29+
"line": 2
30+
}
31+
],
32+
"type": "scenario"
33+
},
34+
{
35+
"description": "",
36+
"id": "a-feature;another-scenario",
37+
"keyword": "Scenario",
38+
"line": 7,
39+
"name": "another scenario",
40+
"steps": [
41+
{
42+
"arguments": [],
43+
"keyword": "Given ",
44+
"line": 8,
45+
"name": "another step",
46+
"match": {
47+
"location": "not available:0"
48+
},
49+
"result": {
50+
"status": "passed",
51+
"duration": 0
52+
}
53+
}
54+
],
55+
"tags": [
56+
{
57+
"name": "@env(origin=\"https://google.com/\")",
58+
"line": 6
59+
}
60+
],
61+
"type": "scenario"
62+
}
63+
],
64+
"id": "a-feature",
65+
"line": 1,
66+
"keyword": "Feature",
67+
"name": "a feature",
68+
"tags": [],
69+
"uri": "cypress/e2e/a.feature"
70+
}
71+
]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{"meta":"meta"}
2+
{"testRunStarted":{"timestamp":{"seconds":0,"nanos":0}}}
3+
{"source":{"data":"Feature: a feature\n @env(origin=\"https://duckduckgo.com/\")\n Scenario: a scenario\n Given a step\n\n @env(origin=\"https://google.com/\")\n Scenario: another scenario\n Given another step","uri":"cypress/e2e/a.feature","mediaType":"text/x.cucumber.gherkin+plain"}}
4+
{"gherkinDocument":{"feature":{"tags":[],"location":{"line":1,"column":1},"language":"en","keyword":"Feature","name":"a feature","description":"","children":[{"scenario":{"id":"id","tags":[{"location":{"line":2,"column":3},"name":"@env(origin=\"https://duckduckgo.com/\")","id":"id"}],"location":{"line":3,"column":3},"keyword":"Scenario","name":"a scenario","description":"","steps":[{"id":"id","location":{"line":4,"column":5},"keyword":"Given ","keywordType":"Context","text":"a step"}],"examples":[]}},{"scenario":{"id":"id","tags":[{"location":{"line":6,"column":3},"name":"@env(origin=\"https://google.com/\")","id":"id"}],"location":{"line":7,"column":3},"keyword":"Scenario","name":"another scenario","description":"","steps":[{"id":"id","location":{"line":8,"column":5},"keyword":"Given ","keywordType":"Context","text":"another step"}],"examples":[]}}]},"comments":[],"uri":"cypress/e2e/a.feature"}}
5+
{"pickle":{"id":"id","uri":"cypress/e2e/a.feature","astNodeIds":["id"],"tags":[{"name":"@env(origin=\"https://duckduckgo.com/\")","astNodeId":"id"}],"name":"a scenario","language":"en","steps":[{"id":"id","text":"a step","type":"Context","astNodeIds":["id"]}]}}
6+
{"pickle":{"id":"id","uri":"cypress/e2e/a.feature","astNodeIds":["id"],"tags":[{"name":"@env(origin=\"https://google.com/\")","astNodeId":"id"}],"name":"another scenario","language":"en","steps":[{"id":"id","text":"another step","type":"Context","astNodeIds":["id"]}]}}
7+
{"stepDefinition":{"id":"id","pattern":{"type":"CUCUMBER_EXPRESSION","source":"a step"},"sourceReference":{"uri":"not available","location":{"line":0}}}}
8+
{"stepDefinition":{"id":"id","pattern":{"type":"CUCUMBER_EXPRESSION","source":"another step"},"sourceReference":{"uri":"not available","location":{"line":0}}}}
9+
{"testCase":{"id":"id","pickleId":"id","testSteps":[{"id":"id","pickleStepId":"id","stepDefinitionIds":["id"]}]}}
10+
{"testCase":{"id":"id","pickleId":"id","testSteps":[{"id":"id","pickleStepId":"id","stepDefinitionIds":["id"]}]}}
11+
{"testCaseStarted":{"id":"id","testCaseId":"id","attempt":0,"timestamp":{"seconds":0,"nanos":0}}}
12+
{"testStepStarted":{"testStepId":"id","testCaseStartedId":"id","timestamp":{"seconds":0,"nanos":0}}}
13+
{"testStepFinished":{"testStepId":"id","testCaseStartedId":"id","testStepResult":{"status":"PASSED","duration":0},"timestamp":{"seconds":0,"nanos":0}}}
14+
{"testCaseFinished":{"testCaseStartedId":"id","timestamp":{"seconds":0,"nanos":0},"willBeRetried":false}}
15+
{"testCaseStarted":{"id":"id","testCaseId":"id","attempt":0,"timestamp":{"seconds":0,"nanos":0}}}
16+
{"testStepStarted":{"testStepId":"id","testCaseStartedId":"id","timestamp":{"seconds":0,"nanos":0}}}
17+
{"testStepFinished":{"testStepId":"id","testCaseStartedId":"id","testStepResult":{"status":"PASSED","duration":0},"timestamp":{"seconds":0,"nanos":0}}}
18+
{"testCaseFinished":{"testCaseStartedId":"id","timestamp":{"seconds":0,"nanos":0},"willBeRetried":false}}
19+
{"testRunFinished":{"timestamp":{"seconds":0,"nanos":0}}}

features/issues/1142.feature

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# https://github.com/badeball/cypress-cucumber-preprocessor/issues/1142
2+
3+
@network
4+
Feature: JSON report
5+
Scenario: reload-behavior in beforeEach hook
6+
Given additional preprocessor configuration
7+
"""
8+
{
9+
"json": {
10+
"enabled": true
11+
}
12+
}
13+
"""
14+
And a file named "cypress/e2e/a.feature" with:
15+
"""
16+
Feature: a feature
17+
Scenario: a scenario
18+
Given a step
19+
"""
20+
And a file named "cypress/support/step_definitions/steps.js" with:
21+
"""
22+
const { Given } = require("@badeball/cypress-cucumber-preprocessor");
23+
Given("a step", function() {})
24+
"""
25+
And a file named "cypress/support/e2e.js" with:
26+
"""
27+
beforeEach(() => {
28+
cy.visit("https://duckduckgo.com/");
29+
});
30+
"""
31+
When I run cypress
32+
Then it passes

features/pretty_output.feature

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,3 +437,205 @@ Feature: pretty output
437437
Scenario: a scenario # cypress/e2e/a.feature:2
438438
Given a step
439439
"""
440+
441+
@network
442+
Rule: it should handle reloads gracefully in a multitude of scenarios
443+
444+
Reloading occurs when visiting or configuring baseUrl to a new domain, either different from the
445+
preconfigured value or because no value was configured to begin with. This forces Cypress to
446+
reload the window, re-fire before:spec event and re-run the current test.
447+
448+
Background:
449+
Given a file named "cypress/e2e/a.feature" with:
450+
"""
451+
Feature: a feature
452+
@env(origin="https://duckduckgo.com/")
453+
Scenario: a scenario
454+
Given a step
455+
456+
@env(origin="https://google.com/")
457+
Scenario: another scenario
458+
Given another step
459+
"""
460+
461+
Scenario: base case
462+
Given a file named "cypress/support/step_definitions/steps.js" with:
463+
"""
464+
const { Given } = require("@badeball/cypress-cucumber-preprocessor");
465+
466+
Given("a step", function() {});
467+
468+
Given("another step", function() {});
469+
"""
470+
When I run cypress
471+
Then it passes
472+
And the output should contain
473+
"""
474+
Feature: a feature # cypress/e2e/a.feature:1
475+
476+
@env(origin="https://duckduckgo.com/")
477+
Scenario: a scenario # cypress/e2e/a.feature:3
478+
Given a step
479+
480+
@env(origin="https://google.com/")
481+
Scenario: another scenario # cypress/e2e/a.feature:7
482+
Given another step
483+
"""
484+
485+
Scenario: reloading within steps
486+
Given a file named "cypress/support/step_definitions/steps.js" with:
487+
"""
488+
const { Given } = require("@badeball/cypress-cucumber-preprocessor");
489+
490+
Given("a step", function() {
491+
cy.visit("https://duckduckgo.com/");
492+
});
493+
494+
Given("another step", function() {
495+
cy.visit("https://google.com/");
496+
});
497+
"""
498+
When I run cypress
499+
Then it passes
500+
And the output should contain
501+
"""
502+
Feature: a feature # cypress/e2e/a.feature:1
503+
504+
@env(origin="https://duckduckgo.com/")
505+
Scenario: a scenario # cypress/e2e/a.feature:3
506+
Given a step
507+
508+
Reloading..
509+
510+
Feature: a feature # cypress/e2e/a.feature:1
511+
512+
@env(origin="https://duckduckgo.com/")
513+
Scenario: a scenario # cypress/e2e/a.feature:3
514+
Given a step
515+
516+
@env(origin="https://google.com/")
517+
Scenario: another scenario # cypress/e2e/a.feature:7
518+
Given another step
519+
520+
Reloading..
521+
522+
Feature: a feature # cypress/e2e/a.feature:1
523+
524+
@env(origin="https://google.com/")
525+
Scenario: another scenario # cypress/e2e/a.feature:7
526+
Given another step
527+
"""
528+
529+
Scenario: reloading in before()
530+
Given a file named "cypress/support/step_definitions/steps.js" with:
531+
"""
532+
const { Given } = require("@badeball/cypress-cucumber-preprocessor");
533+
534+
before(() => {
535+
cy.visit("https://duckduckgo.com/");
536+
});
537+
538+
Given("a step", function() {});
539+
540+
Given("another step", function() {});
541+
"""
542+
When I run cypress
543+
Then it passes
544+
And the output should not contain "Reloading.."
545+
546+
Scenario: reloading in after()
547+
Given a file named "cypress/support/step_definitions/steps.js" with:
548+
"""
549+
const { Given } = require("@badeball/cypress-cucumber-preprocessor");
550+
551+
after(() => {
552+
cy.visit("https://duckduckgo.com/");
553+
});
554+
555+
Given("a step", function() {});
556+
557+
Given("another step", function() {});
558+
"""
559+
When I run cypress
560+
Then it passes
561+
And the output should contain
562+
"""
563+
Feature: a feature # cypress/e2e/a.feature:1
564+
565+
@env(origin="https://duckduckgo.com/")
566+
Scenario: a scenario # cypress/e2e/a.feature:3
567+
Given a step
568+
569+
@env(origin="https://google.com/")
570+
Scenario: another scenario # cypress/e2e/a.feature:7
571+
Given another step
572+
573+
Reloading..
574+
575+
Feature: a feature # cypress/e2e/a.feature:1
576+
577+
@env(origin="https://google.com/")
578+
Scenario: another scenario # cypress/e2e/a.feature:7
579+
Given another step
580+
"""
581+
582+
Scenario: reloading in beforeEach()
583+
Given a file named "cypress/support/step_definitions/steps.js" with:
584+
"""
585+
const { Given } = require("@badeball/cypress-cucumber-preprocessor");
586+
587+
beforeEach(() => {
588+
cy.visit(Cypress.env("origin"));
589+
});
590+
591+
Given("a step", function() {});
592+
593+
Given("another step", function() {});
594+
"""
595+
When I run cypress
596+
Then it passes
597+
And the output should not contain "Reloading.."
598+
599+
Scenario: reloading in afterEach()
600+
Given a file named "cypress/support/step_definitions/steps.js" with:
601+
"""
602+
const { Given } = require("@badeball/cypress-cucumber-preprocessor");
603+
604+
afterEach(() => {
605+
cy.visit(Cypress.env("origin"));
606+
});
607+
608+
Given("a step", function() {});
609+
610+
Given("another step", function() {});
611+
"""
612+
When I run cypress
613+
Then it passes
614+
And the output should contain
615+
"""
616+
Feature: a feature # cypress/e2e/a.feature:1
617+
618+
@env(origin="https://duckduckgo.com/")
619+
Scenario: a scenario # cypress/e2e/a.feature:3
620+
Given a step
621+
622+
Reloading..
623+
624+
Feature: a feature # cypress/e2e/a.feature:1
625+
626+
@env(origin="https://duckduckgo.com/")
627+
Scenario: a scenario # cypress/e2e/a.feature:3
628+
Given a step
629+
630+
@env(origin="https://google.com/")
631+
Scenario: another scenario # cypress/e2e/a.feature:7
632+
Given another step
633+
634+
Reloading..
635+
636+
Feature: a feature # cypress/e2e/a.feature:1
637+
638+
@env(origin="https://google.com/")
639+
Scenario: another scenario # cypress/e2e/a.feature:7
640+
Given another step
641+
"""

0 commit comments

Comments
 (0)