feat(package): add Cypress for end-to-end testing and enhance scripts
- Added Cypress as a dependency for end-to-end testing. - Introduced new npm scripts for running Cypress tests and starting the development server for testing. - Updated package-lock.json to reflect the new dependencies and their versions.
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
/// <reference types="cypress" />
|
||||
|
||||
const AUTH_COOKIE_KEYS = {
|
||||
accessToken: "TENDER_PANEL_token",
|
||||
refreshToken: "TENDER_PANEL_refresh_token",
|
||||
user: "TENDER_PANEL_user",
|
||||
} as const;
|
||||
|
||||
Cypress.Commands.add("loginAsAdmin", () => {
|
||||
cy.session(
|
||||
"admin-session",
|
||||
() => {
|
||||
cy.visit("/auth/sign-in");
|
||||
|
||||
cy.setCookie(AUTH_COOKIE_KEYS.accessToken, "e2e-access-token");
|
||||
cy.setCookie(AUTH_COOKIE_KEYS.refreshToken, "e2e-refresh-token");
|
||||
cy.setCookie(
|
||||
AUTH_COOKIE_KEYS.user,
|
||||
encodeURIComponent(
|
||||
JSON.stringify({
|
||||
id: "507f1f77bcf86cd799439012",
|
||||
username: "e2e-admin",
|
||||
email: "e2e-admin@example.com",
|
||||
role: "admin",
|
||||
}),
|
||||
),
|
||||
);
|
||||
},
|
||||
{
|
||||
validate: () => {
|
||||
cy.getCookie(AUTH_COOKIE_KEYS.accessToken).should("exist");
|
||||
cy.getCookie(AUTH_COOKIE_KEYS.user).should("exist");
|
||||
},
|
||||
cacheAcrossSpecs: true,
|
||||
},
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,10 @@
|
||||
/// <reference types="cypress" />
|
||||
|
||||
// Central place for global Cypress hooks/commands.
|
||||
import "./commands";
|
||||
|
||||
beforeEach(() => {
|
||||
if (Cypress.env("AUTO_LOGIN") !== false) {
|
||||
cy.loginAsAdmin();
|
||||
}
|
||||
});
|
||||
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
/// <reference types="cypress" />
|
||||
|
||||
declare global {
|
||||
namespace Cypress {
|
||||
interface Chainable {
|
||||
loginAsAdmin(): Chainable<void>;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export {};
|
||||
Reference in New Issue
Block a user