Skip to content

Commit

Permalink
fix: use window to detect if cypress is running instead of localstorage
Browse files Browse the repository at this point in the history
  • Loading branch information
maximeperrault committed Sep 18, 2024
1 parent 2b66533 commit 66e1239
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 63 deletions.
3 changes: 1 addition & 2 deletions frontend/config/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ export default defineConfig({
initCypressMousePositionPlugin(on)
initPlugin(on, config)
},
specPattern: ['cypress/e2e/**/*.spec.ts'],
testIsolation: false
specPattern: ['cypress/e2e/**/*.spec.ts']
},
env: {
'cypress-plugin-snapshots': {
Expand Down
10 changes: 0 additions & 10 deletions frontend/cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,3 @@ Cypress.on('uncaught:exception', err => {

return undefined
})

// Run before each spec
before(() => {
// We use a Cypress session to inject inject a Local Storage key
// so that we can detect when the browser app is running in Cypress.
// https://docs.cypress.io/faq/questions/using-cypress-faq#How-do-I-preserve-cookies--localStorage-in-between-my-tests
cy.session('cypress', () => {
window.localStorage.setItem('IS_CYPRESS', 'true')
})
})
45 changes: 0 additions & 45 deletions frontend/src/utils/__tests__/isCypress.test.ts

This file was deleted.

8 changes: 2 additions & 6 deletions frontend/src/utils/isCypress.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
/**
* Detects whether the browser app is running in Cypress.
*
* @description
* We use a Cypress session to inject inject a Local Storage key
* so that we can detect when the browser app is running in Cypress.
*
* @see https://docs.cypress.io/faq/questions/using-cypress-faq#How-do-I-preserve-cookies--localStorage-in-between-my-tests
* @see https://docs.cypress.io/faq/questions/using-cypress-faq#Is-there-any-way-to-detect-if-my-app-is-running-under-Cypress
*/
export function isCypress() {
return localStorage.getItem('IS_CYPRESS') === 'true'
return !!window.Cypress
}

0 comments on commit 66e1239

Please sign in to comment.