commands.ts — ui Source File
Architecture documentation for commands.ts, a typescript file in the ui codebase. 1 imports, 1 dependents.
Entity Profile
Dependency Diagram
graph LR e91d8547_a204_d0f5_33e5_12f46d875f67["commands.ts"] 817e745e_bb93_8c88_07a4_2e2e390aab69["faker"] e91d8547_a204_d0f5_33e5_12f46d875f67 --> 817e745e_bb93_8c88_07a4_2e2e390aab69 c0949baa_ff75_e7c8_ee1d_c44a3b04399a["e2e.ts"] c0949baa_ff75_e7c8_ee1d_c44a3b04399a --> e91d8547_a204_d0f5_33e5_12f46d875f67 style e91d8547_a204_d0f5_33e5_12f46d875f67 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import { faker } from "@faker-js/faker";
declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace Cypress {
interface Chainable {
/**
* Logs in with a random user. Yields the user and adds an alias to the user
*
* @returns {typeof login}
* @memberof Chainable
* @example
* cy.login()
* @example
* cy.login({ email: 'whatever@example.com' })
*/
login: typeof login;
/**
* Deletes the current @user
*
* @returns {typeof cleanupUser}
* @memberof Chainable
* @example
* cy.cleanupUser()
* @example
* cy.cleanupUser({ email: 'whatever@example.com' })
*/
cleanupUser: typeof cleanupUser;
/**
* Extends the standard visit command to wait for the page to load
*
* @returns {typeof visitAndCheck}
* @memberof Chainable
* @example
* cy.visitAndCheck('/')
* @example
* cy.visitAndCheck('/', 500)
*/
visitAndCheck: typeof visitAndCheck;
}
}
}
function login({
email = faker.internet.email({ provider: "example.com" }),
}: {
email?: string;
} = {}) {
cy.then(() => ({ email })).as("user");
cy.exec(
`npx ts-node -r tsconfig-paths/register ./cypress/support/create-user.ts "${email}"`,
).then(({ stdout }) => {
const cookieValue = stdout
.replace(/.*<cookie>(?<cookieValue>.*)<\/cookie>.*/s, "$<cookieValue>")
.trim();
cy.setCookie("__session", cookieValue);
});
return cy.get("@user");
}
function cleanupUser({ email }: { email?: string } = {}) {
if (email) {
deleteUserByEmail(email);
} else {
cy.get("@user").then((user) => {
const email = (user as { email?: string }).email;
if (email) {
deleteUserByEmail(email);
}
});
}
cy.clearCookie("__session");
}
function deleteUserByEmail(email: string) {
cy.exec(
`npx ts-node -r tsconfig-paths/register ./cypress/support/delete-user.ts "${email}"`,
);
cy.clearCookie("__session");
}
// We're waiting a second because of this issue happen randomly
// https://github.com/cypress-io/cypress/issues/7306
// Also added custom types to avoid getting detached
// https://github.com/cypress-io/cypress/issues/7306#issuecomment-1152752612
// ===========================================================
function visitAndCheck(url: string, waitTime = 1000) {
cy.visit(url);
cy.location("pathname").should("contain", url).wait(waitTime);
}
export const registerCommands = () => {
Cypress.Commands.add("login", login);
Cypress.Commands.add("cleanupUser", cleanupUser);
Cypress.Commands.add("visitAndCheck", visitAndCheck);
};
Domain
Subdomains
Classes
Types
Dependencies
- faker
Source
Frequently Asked Questions
What does commands.ts do?
commands.ts is a source file in the ui codebase, written in typescript. It belongs to the FrameworkTooling domain, SchemaValidation subdomain.
What functions are defined in commands.ts?
commands.ts defines 5 function(s): cleanupUser, deleteUserByEmail, login, registerCommands, visitAndCheck.
What does commands.ts depend on?
commands.ts imports 1 module(s): faker.
What files import commands.ts?
commands.ts is imported by 1 file(s): e2e.ts.
Where is commands.ts in the architecture?
commands.ts is located at packages/shadcn/test/fixtures/frameworks/remix-indie-stack/cypress/support/commands.ts (domain: FrameworkTooling, subdomain: SchemaValidation, directory: packages/shadcn/test/fixtures/frameworks/remix-indie-stack/cypress/support).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free