-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #559 from bartoval/add_basic_auth_e2e
test: ✅ Add support for e2e with auth basic
- Loading branch information
Showing
7 changed files
with
113 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,17 @@ | ||
import { defineConfig } from 'cypress'; | ||
|
||
const remoteUrl = process.env.CYPRESS_BASE_URL; | ||
|
||
export default defineConfig({ | ||
e2e: { | ||
baseUrl: process.env.CYPRESS_BASE_URL || 'http://localhost:3000', | ||
chromeWebSecurity: false, | ||
defaultCommandTimeout: 15000, | ||
screenshotOnRunFailure: false, | ||
video: false, | ||
viewportHeight: 1080, | ||
viewportWidth: 1920, | ||
specPattern: (() => { | ||
switch (process.env.TEST_TYPE) { | ||
case 'e2e': | ||
return 'cypress/e2e/**/*.cy.{ts,tsx}'; | ||
case 'local': | ||
return 'cypress/local/**/*.cy.{ts,tsx}'; | ||
default: | ||
return ['cypress/local/**/*.cy.{ts,tsx}', 'cypress/e2e/**/*.cy.{ts,tsx}']; | ||
} | ||
})() | ||
} | ||
baseUrl: remoteUrl || 'http://localhost:3000', | ||
specPattern: remoteUrl ? 'cypress/e2e/**/*.cy.{ts,tsx}' : 'cypress/local/**/*.cy.{ts,tsx}' | ||
}, | ||
|
||
defaultCommandTimeout: 15000, | ||
screenshotOnRunFailure: false, | ||
video: false, | ||
|
||
viewportHeight: 1080, | ||
viewportWidth: 1920 | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const getAuthConfig = () => { | ||
const username = Cypress.env('USERNAME'); | ||
const password = Cypress.env('PASSWORD'); | ||
|
||
if (username && password) { | ||
return { | ||
auth: { | ||
username, | ||
password | ||
} | ||
}; | ||
} | ||
|
||
return {}; | ||
}; | ||
|
||
Cypress.Commands.add('visitWithAuth', (url: string = '/', options = {}) => { | ||
cy.visit(url, { | ||
...getAuthConfig(), | ||
...options | ||
}); | ||
}); | ||
|
||
Cypress.Commands.add('requestWithAuth', (method: string, url: string, options = {}) => { | ||
const authConfig = getAuthConfig(); | ||
cy.request({ | ||
method, | ||
url, | ||
...authConfig, | ||
...options | ||
}).as('requestResponse'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
declare namespace Cypress { | ||
interface Chainable { | ||
visitWithAuth(url?: string, options?: Record<string, unknown>): Chainable<null>; | ||
requestWithAuth(method: string, url: string, options?: Record<string, unknown>): Chainable<null>; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters