Skip to content

Commit 62c60bb

Browse files
committed
Merge branch 'update-cck'
2 parents 6e49cf2 + 56bf63b commit 62c60bb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+742
-209
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Other changes:
2424

2525
- This is similar to how steps themselves can also return the above mentioned literals. This is in line with how cucumber-js behaves.
2626

27+
- Attachments (using log(), link() or attach()) can be added in test run hooks (BeforeAll/AfterAll). This is in line with how cucumber-js behaves.
28+
2729
- Remove use of patch-package in development mode, which was causing some issues, closes [#1255](https://github.com/badeball/cypress-cucumber-preprocessor/pull/1255).
2830

2931
## v23.2.1

compatibility/cck_spec.ts

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,15 @@ const ignorableKeys = [
3838
"testCaseStartedId",
3939
"testStepId",
4040
"testRunStartedId",
41+
"testRunHookStartedId",
4142
// time
4243
"nanos",
4344
"seconds",
4445
// errors
4546
"message",
4647
"stackTrace",
48+
// suggestions
49+
"snippets",
4750
];
4851

4952
function isObject(object: any): object is object {
@@ -90,15 +93,19 @@ describe("Cucumber Compatibility Kit", () => {
9093
const suiteName = path.basename(path.dirname(ndjsonFile));
9194

9295
/**
93-
* Unknown parameter type will generate an exception outside of a Cypress test and halt all
94-
* execution. Thus, cucumber-js' behavior is tricky to mirror.
95-
*
96-
* Markdown is unsupported.
96+
* cucumber-js' behavior is tricky to mirror in a variety of cases.
9797
*/
9898
switch (suiteName) {
99-
case "unknown-parameter-type":
100-
case "markdown":
101-
case "hooks-conditional":
99+
case "unknown-parameter-type": // Unknown parameter type will generate an exception outside of a Cypress test and halt all execution
100+
case "markdown": // Markdown is unsupported
101+
case "hooks-conditional": // Expections during hooks are difficult to mimick due to no try-catch
102+
case "global-hooks-beforeall-error": // See above
103+
case "global-hooks-afterall-error": // See above
104+
case "hooks-undefined": // See above
105+
case "hooks-skipped": // See above
106+
case "multiple-features": // The "correct" message order is difficult to mimick
107+
case "multiple-features-reversed": // Cypress has no `reversed` option
108+
case "test-run-exception": // Difficult to reproduce such scenario
102109
it.skip(`passes the cck suite for '${suiteName}'`);
103110
continue;
104111
}
@@ -183,11 +190,17 @@ describe("Cucumber Compatibility Kit", () => {
183190

184191
await fs.mkdir(path.join(tmpDir, "cypress", "e2e"), { recursive: true });
185192

186-
await fs.copyFile(
187-
path.join(CCK_FEATURES_PATH, suiteName, `${suiteName}.feature`),
188-
path.join(tmpDir, "cypress", "e2e", `${suiteName}.feature`),
193+
const features = glob.sync(
194+
path.join(CCK_FEATURES_PATH, suiteName, "*.feature"),
189195
);
190196

197+
for (const feature of features) {
198+
await fs.copyFile(
199+
path.join(feature),
200+
path.join(tmpDir, "cypress", "e2e", path.basename(feature)),
201+
);
202+
}
203+
191204
if (suiteName === "hooks-attachment") {
192205
await fs.copyFile(
193206
path.join(CCK_FEATURES_PATH, suiteName, "cucumber.svg"),
@@ -270,7 +283,7 @@ describe("Cucumber Compatibility Kit", () => {
270283
(await fs.readFile(ndjsonFile)).toString(),
271284
).map(normalizeMessage);
272285

273-
if (suiteName === "pending") {
286+
if (suiteName === "pending" || suiteName === "retry-pending") {
274287
/**
275288
* We can't control Cypress exit code without failing a test, thus is cucumber-js behavior
276289
* difficult to mimic.
@@ -294,6 +307,14 @@ describe("Cucumber Compatibility Kit", () => {
294307
messages.TestStepResultStatus.PASSED;
295308
}
296309
});
310+
} else if (suiteName === "global-hooks") {
311+
// Move testCase after testRunHookStarted & testRunHookFinished. This is a bit difficult to
312+
// account for in the preprocessor, but since it doesn't matter we just modify the
313+
// expectation.
314+
expectedMessages.splice(12, 0, ...expectedMessages.splice(16, 2));
315+
} else if (suiteName === "global-hooks-attachments") {
316+
// Same as above.
317+
expectedMessages.splice(8, 0, ...expectedMessages.splice(11, 1));
297318
}
298319

299320
assert.deepEqual(actualMessages, expectedMessages);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Given } from "@badeball/cypress-cucumber-preprocessor";
2+
3+
Given(/^a (.*?) with (.*?)$/, function () {
4+
// first one
5+
});
6+
7+
Given(/^a step with (.*)$/, function () {
8+
// second one
9+
});

compatibility/step_definitions/attachments.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,6 @@ When(
3838
},
3939
);
4040

41-
When("a JPEG image is attached", function () {
42-
cy.readFile("cucumber.jpeg", "base64").then((file) =>
43-
attach(file, "base64:image/jpeg"),
44-
);
45-
});
46-
47-
When("a PNG image is attached", function () {
48-
cy.readFile("cucumber.png", "base64").then((file) =>
49-
attach(file, "base64:image/png"),
50-
);
51-
});
52-
5341
When("a PDF document is attached and renamed", function () {
5442
cy.readFile("document.pdf", "base64").then((file) =>
5543
attach(file, {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Given, Then, When } from "@badeball/cypress-cucumber-preprocessor";
2+
3+
Given("an order for {string}", () => {
4+
// no-op
5+
});
6+
7+
When("an action", () => {
8+
// no-op
9+
});
10+
11+
Then("an outcome", () => {
12+
// no-op
13+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { Given } from "@badeball/cypress-cucumber-preprocessor";
2+
3+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
4+
Given("a doc string:", (docString: string) => {
5+
// no-op
6+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Given, Then, When } from "@badeball/cypress-cucumber-preprocessor";
2+
3+
Given("there are {int} cucumbers", function (initialCount) {
4+
this.count = initialCount;
5+
});
6+
7+
When("I eat {int} cucumbers", function (eatCount: number) {
8+
this.count -= eatCount;
9+
});
10+
11+
Then("I should have {int} cucumbers", function (expectedCount: number) {
12+
expect(this.count).to.equal(expectedCount);
13+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import {
2+
AfterAll,
3+
attach,
4+
BeforeAll,
5+
When,
6+
} from "@badeball/cypress-cucumber-preprocessor";
7+
8+
BeforeAll({}, function () {
9+
attach("Attachment from BeforeAll hook", "text/plain");
10+
});
11+
12+
When("a step passes", function () {
13+
// no-op
14+
});
15+
16+
AfterAll({}, function () {
17+
attach("Attachment from AfterAll hook", "text/plain");
18+
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import {
2+
AfterAll,
3+
BeforeAll,
4+
When,
5+
} from "@badeball/cypress-cucumber-preprocessor";
6+
7+
BeforeAll({}, function () {
8+
// no-op
9+
});
10+
11+
BeforeAll({}, function () {
12+
// no-op
13+
});
14+
15+
When("a step passes", function () {
16+
// no-op
17+
});
18+
19+
When("a step fails", function () {
20+
throw new Error("Exception in step");
21+
});
22+
23+
AfterAll({}, function () {
24+
// no-op
25+
});
26+
27+
AfterAll({}, function () {
28+
// no-op
29+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { Given } from "@badeball/cypress-cucumber-preprocessor";
2+
3+
Given("an order for {string}", () => {
4+
// no-op
5+
});

0 commit comments

Comments
 (0)