Skip to content

Commit

Permalink
Add support for Cypress v10 =<
Browse files Browse the repository at this point in the history
Also drop support for all previous versions.
  • Loading branch information
badeball committed Nov 7, 2023
1 parent 0d92169 commit 971cffa
Show file tree
Hide file tree
Showing 11 changed files with 471 additions and 85 deletions.
2 changes: 1 addition & 1 deletion features/configuration/disable-knapsack-output.feature
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Feature: --disable-knapsack-output
Rule: it should disable outputting of the knapsack
Background:
Given a file named "cypress/integration/a.js" with:
Given a file named "cypress/e2e/a.js" with:
"""
it("should pass", () => expect(true).to.be.true);
"""
Expand Down
8 changes: 4 additions & 4 deletions features/configuration/knapsack.feature
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Feature: --knapsack
Rule: it should store knapsack at provided location (default 'knapsack.json')
Background:
Given a file named "cypress/integration/a.js" with:
Given a file named "cypress/e2e/a.js" with:
"""
it("should pass", () => expect(true).to.be.true);
"""
Expand All @@ -16,7 +16,7 @@ Feature: --knapsack
And I should see a file "knapsack.json" with content matching:
"""
{
"cypress/integration/a.js": \d+
"cypress/e2e/a.js": \d+
}
"""

Expand All @@ -30,7 +30,7 @@ Feature: --knapsack
And I should see a file "sackknap.json" with content matching:
"""
{
"cypress/integration/a.js": \d+
"cypress/e2e/a.js": \d+
}
"""

Expand All @@ -44,6 +44,6 @@ Feature: --knapsack
And I should see a file "sackknap.json" with content matching:
"""
{
"cypress/integration/a.js": \d+
"cypress/e2e/a.js": \d+
}
"""
10 changes: 5 additions & 5 deletions features/configuration/node.feature
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
Feature: --node
Rule: it should determine bucket of tests
Background:
Given a file named "cypress/integration/a.js" with:
Given a file named "cypress/e2e/a.js" with:
"""
it("should pass", () => expect(true).to.be.true);
"""
And a file named "cypress/integration/b.js" with:
And a file named "cypress/e2e/b.js" with:
"""
it("should pass", () => expect(true).to.be.true);
"""
And a file named "cypress/integration/c.js" with:
And a file named "cypress/e2e/c.js" with:
"""
it("should pass", () => expect(true).to.be.true);
"""
And a file named "cypress/integration/d.js" with:
And a file named "cypress/e2e/d.js" with:
"""
it("should pass", () => expect(true).to.be.true);
"""
And a file named "cypress/integration/e.js" with:
And a file named "cypress/e2e/e.js" with:
"""
it("should pass", () => expect(true).to.be.true);
"""
Expand Down
28 changes: 15 additions & 13 deletions features/knapsack.feature
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Feature: knapsack.json
Rule: it should handle any *normal* knapsack scenario somewhat gracefully, otherwise error
Scenario: knapsack missing entirely
Given a file named "cypress/integration/a.js" with:
Given a file named "cypress/e2e/a.js" with:
"""
it("should pass", () => {});
"""
Expand All @@ -10,7 +10,7 @@ Feature: knapsack.json
But it passes

Scenario: knapsack missing a file
Given a file named "cypress/integration/a.js" with:
Given a file named "cypress/e2e/a.js" with:
"""
it("should pass", () => {});
"""
Expand All @@ -22,15 +22,15 @@ Feature: knapsack.json
Then it passes

Scenario: knapsack containing a removed file
Given a file named "cypress/integration/a.js" with:
Given a file named "cypress/e2e/a.js" with:
"""
it("should pass", () => {});
"""
And a file named "knapsack.json" with:
"""
{
"cypress/integration/a.js": 1,
"cypress/integration/b.js": 1
"cypress/e2e/a.js": 1,
"cypress/e2e/b.js": 1
}
"""
Given I run cypress-parallel with "--node 1:1"
Expand All @@ -40,30 +40,32 @@ Feature: knapsack.json
Given additional Cypress configuration
"""
{
"testFiles": "**/a.js"
"e2e": {
"specPattern": "**/a.js"
}
}
"""
And a file named "cypress/integration/a.js" with:
And a file named "cypress/e2e/a.js" with:
"""
it("should pass", () => {});
"""
And a file named "cypress/integration/b.js" with:
And a file named "cypress/e2e/b.js" with:
"""
it("should pass", () => {});
"""
And a file named "knapsack.json" with:
"""
{
"cypress/integration/a.js": 1,
"cypress/integration/b.js": 1
"cypress/e2e/a.js": 1,
"cypress/e2e/b.js": 1
}
"""
Given I run cypress-parallel with "--node 1:1"
Then it passes
And it should appear as if only a single test ran

Scenario: knapsack isn't JSON
Given a file named "cypress/integration/a.js" with:
Given a file named "cypress/e2e/a.js" with:
"""
it("should pass", () => {});
"""
Expand All @@ -79,7 +81,7 @@ Feature: knapsack.json
"""

Scenario: knapsack isn't a valid Record<string, number>
Given a file named "cypress/integration/a.js" with:
Given a file named "cypress/e2e/a.js" with:
"""
it("should pass", () => {});
"""
Expand All @@ -95,7 +97,7 @@ Feature: knapsack.json
"""

Scenario: knapsack isn't readable
Given a file named "cypress/integration/a.js" with:
Given a file named "cypress/e2e/a.js" with:
"""
it("should pass", () => {});
"""
Expand Down
41 changes: 5 additions & 36 deletions features/step_definitions/config_steps.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,10 @@
import { Given } from "@cucumber/cucumber";
import path from "path";
import { promises as fs } from "fs";
import { name as packageName } from "../../package.json";

async function addOrUpdateConfiguration(
absoluteConfigPath: string,
additionalJsonContent: string
) {
let existingConfig: any;

try {
existingConfig = JSON.parse(
(await fs.readFile(absoluteConfigPath)).toString()
);
} catch (e: any) {
if (e.code === "ENOENT") {
existingConfig = {};
} else {
throw e;
}
}

await fs.writeFile(
absoluteConfigPath,
JSON.stringify(
{
...existingConfig,
...JSON.parse(additionalJsonContent),
},
null,
2
)
);
}
import { insertValuesInConfigFile } from "../support/configFileUpdater";

Given("additional Cypress configuration", async function (jsonContent) {
const absoluteConfigPath = path.join(this.tmpDir, "cypress.json");

await addOrUpdateConfiguration(absoluteConfigPath, jsonContent);
await insertValuesInConfigFile(
path.join(this.tmpDir, "cypress.config.js"),
JSON.parse(jsonContent)
);
});
Loading

0 comments on commit 971cffa

Please sign in to comment.