Skip to content

Commit baeb520

Browse files
committed
Fix error in non-feature specs under certain conditions
This fixes #1028 [1]. [1] #1028
1 parent 65b6a57 commit baeb520

File tree

5 files changed

+41
-5
lines changed

5 files changed

+41
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ All notable changes to this project will be documented in this file.
66

77
- Step hooks are logged using separate log groups, similar to how scenario hooks are logged.
88

9+
- Fix error in non-feature specs under certain conditions, fixes [#1028](https://github.com/badeball/cypress-cucumber-preprocessor/issues/1028).
10+
911
## v17.2.0
1012

1113
- Add BeforeStep and AfterStep hooks, fixes [#847](https://github.com/badeball/cypress-cucumber-preprocessor/issues/847).

features/issues/1017.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
@network
44
Feature: JSON report
5-
Scenario: with after hook
5+
Scenario: with after hook and reload-behavior
66
Given additional preprocessor configuration
77
"""
88
{

features/issues/1028.feature

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# https://github.com/badeball/cypress-cucumber-preprocessor/issues/1028
2+
3+
@network
4+
Feature: non-feature specs
5+
Scenario: with messages enabled + reload-behavior
6+
Given additional preprocessor configuration
7+
"""
8+
{
9+
"messages": {
10+
"enabled": true
11+
}
12+
}
13+
"""
14+
And additional Cypress configuration
15+
"""
16+
{
17+
"e2e": {
18+
"specPattern": "**/spec.js"
19+
}
20+
}
21+
"""
22+
And a file named "cypress/e2e/spec.js" with:
23+
"""
24+
it("should work", () => {
25+
cy.visit("https://duckduckgo.com/")
26+
})
27+
"""
28+
When I run cypress
29+
Then it passes

lib/add-cucumber-preprocessor-plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export default async function addCucumberPreprocessorPlugin(
9595
}
9696

9797
if (!options.omitBeforeSpecHandler) {
98-
on("before:spec", () => beforeSpecHandler(config));
98+
on("before:spec", (spec) => beforeSpecHandler(config, spec));
9999
}
100100

101101
if (!options.omitAfterSpecHandler) {

lib/plugin-event-handlers.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ let state: State = {
9898
state: "initial",
9999
};
100100

101+
const isFeature = (spec: Cypress.Spec) => spec.name.endsWith(".feature");
102+
101103
export async function beforeRunHandler(config: Cypress.PluginConfigOptions) {
102104
debug("beforeRunHandler()");
103105

@@ -281,10 +283,13 @@ export async function afterRunHandler(config: Cypress.PluginConfigOptions) {
281283
}
282284
}
283285

284-
export async function beforeSpecHandler(config: Cypress.PluginConfigOptions) {
286+
export async function beforeSpecHandler(
287+
config: Cypress.PluginConfigOptions,
288+
spec: Cypress.Spec
289+
) {
285290
debug("beforeSpecHandler()");
286291

287-
if (!config.isTextTerminal) {
292+
if (!config.isTextTerminal || !isFeature(spec)) {
288293
return;
289294
}
290295

@@ -320,7 +325,7 @@ export async function afterSpecHandler(
320325
) {
321326
debug("afterSpecHandler()");
322327

323-
if (!config.isTextTerminal) {
328+
if (!config.isTextTerminal || !isFeature(spec)) {
324329
return;
325330
}
326331

0 commit comments

Comments
 (0)