Skip to content

Commit 9a89d8a

Browse files
committed
Ensure output directory existence
This partially fixes #736.
1 parent f497416 commit 9a89d8a

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

features/issues/736.feature

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# https://github.com/badeball/cypress-cucumber-preprocessor/issues/736
2+
3+
Feature: create output directories
4+
Background:
5+
Given additional preprocessor configuration
6+
"""
7+
{
8+
"messages": {
9+
"enabled": true,
10+
"output": "foo/cucumber-messages.ndjson"
11+
},
12+
"json": {
13+
"enabled": true,
14+
"output": "bar/cucumber-report.json"
15+
}
16+
}
17+
"""
18+
And I've ensured cucumber-json-formatter is installed
19+
20+
Scenario:
21+
Given a file named "cypress/e2e/a.feature" with:
22+
"""
23+
Feature: a feature
24+
Scenario: a scenario
25+
Given a step
26+
"""
27+
And a file named "cypress/support/step_definitions/steps.js" with:
28+
"""
29+
const { Given } = require("@badeball/cypress-cucumber-preprocessor");
30+
Given("a step", function() {})
31+
"""
32+
When I run cypress
33+
Then it passes

lib/add-cucumber-preprocessor-plugin.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ export async function afterRunHandler(config: Cypress.PluginConfigOptions) {
9191
return;
9292
}
9393

94+
await fs.mkdir(path.dirname(jsonPath), { recursive: true });
95+
9496
const messages = await fs.open(messagesPath, "r");
9597

9698
try {
@@ -156,6 +158,8 @@ export async function afterSpecHandler(
156158
)
157159
);
158160
} else {
161+
await fs.mkdir(path.dirname(messagesPath), { recursive: true });
162+
159163
await fs.writeFile(
160164
messagesPath,
161165
currentSpecMessages.map((message) => JSON.stringify(message)).join("\n") +

0 commit comments

Comments
 (0)