Fix Cypress Clerk OTP helper for same-origin SignIn
This commit is contained in:
@@ -53,44 +53,55 @@ Cypress.Commands.add("loginWithClerkOtp", () => {
|
|||||||
// Cypress cannot reliably drive Clerk modal/iframe flows.
|
// Cypress cannot reliably drive Clerk modal/iframe flows.
|
||||||
cy.visit("/sign-in");
|
cy.visit("/sign-in");
|
||||||
|
|
||||||
// The Clerk UI is hosted on a different origin.
|
// Clerk SignIn can render on our app origin (localhost) or redirect to Clerk-hosted UI,
|
||||||
cy.origin(
|
// depending on config/version. Handle both.
|
||||||
opts.clerkOrigin,
|
const fillOtpFlow = (email: string, otp: string) => {
|
||||||
{ args: { email: opts.email, otp: opts.otp } },
|
cy.get(
|
||||||
({ email, otp }) => {
|
'input[type="email"], input[name="identifier"], input[autocomplete="email"]',
|
||||||
cy.get(
|
{ timeout: 20_000 },
|
||||||
'input[type="email"], input[name="identifier"], input[autocomplete="email"]',
|
)
|
||||||
{ timeout: 20_000 },
|
.first()
|
||||||
)
|
.clear()
|
||||||
.first()
|
.type(email, { delay: 10 });
|
||||||
.clear()
|
|
||||||
.type(email, { delay: 10 });
|
|
||||||
|
|
||||||
cy.get('button[type="submit"], button')
|
cy.get('button[type="submit"], button')
|
||||||
.contains(/continue|sign in|send|next/i)
|
.contains(/continue|sign in|send|next/i)
|
||||||
.click({ force: true });
|
.click({ force: true });
|
||||||
|
|
||||||
cy.get(
|
cy.get(
|
||||||
'input[autocomplete="one-time-code"], input[name*="code"], input[inputmode="numeric"]',
|
'input[autocomplete="one-time-code"], input[name*="code"], input[inputmode="numeric"]',
|
||||||
{ timeout: 20_000 },
|
{ timeout: 20_000 },
|
||||||
)
|
)
|
||||||
.first()
|
.first()
|
||||||
.clear()
|
.clear()
|
||||||
.type(otp, { delay: 10 });
|
.type(otp, { delay: 10 });
|
||||||
|
|
||||||
cy.get("body").then(($body) => {
|
cy.get("body").then(($body) => {
|
||||||
const hasSubmit = $body
|
const hasSubmit = $body
|
||||||
.find('button[type="submit"], button')
|
.find('button[type="submit"], button')
|
||||||
.toArray()
|
.toArray()
|
||||||
.some((el) => /verify|continue|sign in|confirm/i.test(el.textContent || ""));
|
.some((el) => /verify|continue|sign in|confirm/i.test(el.textContent || ""));
|
||||||
if (hasSubmit) {
|
if (hasSubmit) {
|
||||||
cy.get('button[type="submit"], button')
|
cy.get('button[type="submit"], button')
|
||||||
.contains(/verify|continue|sign in|confirm/i)
|
.contains(/verify|continue|sign in|confirm/i)
|
||||||
.click({ force: true });
|
.click({ force: true });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
};
|
||||||
);
|
|
||||||
|
cy.location("origin", { timeout: 20_000 }).then((origin) => {
|
||||||
|
if (origin === opts.clerkOrigin) {
|
||||||
|
cy.origin(
|
||||||
|
opts.clerkOrigin,
|
||||||
|
{ args: { email: opts.email, otp: opts.otp } },
|
||||||
|
({ email, otp }) => {
|
||||||
|
fillOtpFlow(email, otp);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
fillOtpFlow(opts.email, opts.otp);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
|||||||
Reference in New Issue
Block a user