Skip to content

Commit

Permalink
fix: load Cypress commands in newer versions
Browse files Browse the repository at this point in the history
Newer versions of Cypress (12.17.4+) do not load commands.ts because
of sideEffects: false in package.json:

cypress-io/cypress#27641

This is probably caused by Webpack 5 skipping the import. The fix is to
explicitly register the commands without relying on side effects. This
allows upgrading Cypress to 12.17.4+ or 13+.
  • Loading branch information
luzat committed Sep 27, 2023
1 parent da0c6b7 commit 0163133
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
8 changes: 5 additions & 3 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ function visitAndCheck(url: string, waitTime: number = 1000) {
cy.location("pathname").should("contain", url).wait(waitTime);
}

Cypress.Commands.add("login", login);
Cypress.Commands.add("cleanupUser", cleanupUser);
Cypress.Commands.add("visitAndCheck", visitAndCheck);
export function registerCommands() {
Cypress.Commands.add("login", login);
Cypress.Commands.add("cleanupUser", cleanupUser);
Cypress.Commands.add("visitAndCheck", visitAndCheck);
}
4 changes: 3 additions & 1 deletion cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import "@testing-library/cypress/add-commands";
import "./commands";
import { registerCommands } from "./commands";

registerCommands();

Cypress.on("uncaught:exception", (err) => {
// Cypress and React Hydrating the document don't get along
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"binode": "^1.0.5",
"cookie": "^0.5.0",
"cross-env": "^7.0.3",
"cypress": "12.17.3",
"cypress": "^12.17.4",
"eslint": "^8.47.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-cypress": "^2.14.0",
Expand Down

0 comments on commit 0163133

Please sign in to comment.