Skip to content

Commit

Permalink
added before and after hooks to Cypress
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-burel committed Jun 18, 2020
1 parent 3e0eb15 commit 889c909
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cypress/integration/vns/i18n.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe("i18n", () => {
cy.resetDefaultLanguage();
});
// @see https://glebbahmutov.com/blog/ssr-e2e/ for testing recipes
it.only("should add fr as language and pass correct language direction", () => {
it("should add fr as language and pass correct language direction", () => {
cy.setLanguage("fr");
// request instead of visit prevents client rehydratation, we just test the static code
// => faster test when we don't need to test rehydration
Expand Down
5 changes: 5 additions & 0 deletions cypress/support/after.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
after(() => {
console.info("Running after hook from 'cypress/support/after.ts'");
// disable debugging
window.localStorage.removeItem("debug");
});
17 changes: 17 additions & 0 deletions cypress/support/before.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Initialize debug with NPM debug
*
* Note: this is a client-side file, prefix environment variables with CYPRESS_ if necessary
*/
before(() => {
console.info("Running Cypress before hook from 'cypress/support/before.ts'");
const debugEnv = Cypress.env("DEBUG"); // Set CYPRESS_DEBUG if you want this variable to be defined (the CYPRESS_ prefix is scrapped out automatically)
if (!(debugEnv && debugEnv === "false")) {
const debugLevel = debugEnv || "vns:*";
console.info("Enabling debug with namespace", debugLevel);
console.info(
"Run Cypress with CYPRESS_DEBUG=false to disable, or CYPRESS_DEBUG=<your-namespace> to change the debug namespace"
);
window.localStorage.setItem("debug", debugLevel);
}
});
4 changes: 4 additions & 0 deletions cypress/support/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ import "./commands";
// code coverage
// NOTE: this file is passed to the browser => we can't access process.env.COVERAGE
import "@cypress/code-coverage/support";

// code run before/after all tests
import "./before";
import "./after";
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"test:unit": "jest --testPathIgnorePatterns=tests/vns",
"test:vns": "jest --testPathPattern=tests/vns && npm run test:e2e # run tests for Vulcan Next Starter itself, eg scripts (long) ",
"cypress:open": "cross-env CYPRESS_coverage=false cypress open",
"cypress:run": "cross-env CYPRESS_coverage=false cypress run --headless",
"cypress:run": "cross-env CYPRESS_DEBUG=false CYPRESS_coverage=false cypress run --headless",
"coverage:e2e": "cross-env COVERAGE=1 npm run build && start-server-and-test start:test http://localhost:3000 'COVERAGE=1 cypress run'",
"coverage:unit": "jest --coverage",
"precoverage": "rm -rf .nyc_output || true # delete previous nyx instrumentation",
Expand Down

0 comments on commit 889c909

Please sign in to comment.