-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
1,444 additions
and
1,010 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { defineConfig } from "cypress"; | ||
|
||
export default defineConfig({ | ||
e2e: { | ||
setupNodeEvents: (on, config) => { | ||
const isDev = config.watchForFileChanges; | ||
const port = process.env.PORT ?? (isDev ? "3000" : "8811"); | ||
const configOverrides: Partial<Cypress.PluginConfigOptions> = { | ||
baseUrl: `http://localhost:${port}`, | ||
video: !process.env.CI, | ||
screenshotOnRunFailure: !process.env.CI, | ||
}; | ||
|
||
// To use this: | ||
// cy.task('log', whateverYouWantInTheTerminal) | ||
on("task", { | ||
log: (message) => { | ||
console.log(message); | ||
|
||
return null; | ||
}, | ||
}); | ||
|
||
return { ...config, ...configOverrides }; | ||
}, | ||
}, | ||
}); |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import faker from "@faker-js/faker"; | ||
import { faker } from "@faker-js/faker"; | ||
|
||
declare global { | ||
namespace Cypress { | ||
|
@@ -26,6 +26,18 @@ declare global { | |
* cy.cleanupUser({ email: '[email protected]' }) | ||
*/ | ||
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; | ||
} | ||
} | ||
} | ||
|
@@ -68,10 +80,16 @@ function deleteUserByEmail(email: string) { | |
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: number = 1000) { | ||
cy.visit(url); | ||
cy.location("pathname").should("contain", url).wait(waitTime); | ||
} | ||
|
||
Cypress.Commands.add("login", login); | ||
Cypress.Commands.add("cleanupUser", cleanupUser); | ||
|
||
/* | ||
eslint | ||
@typescript-eslint/no-namespace: "off", | ||
*/ | ||
Cypress.Commands.add("visitAndCheck", visitAndCheck); |
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 |
---|---|---|
|
@@ -3,7 +3,9 @@ | |
// npx ts-node --require tsconfig-paths/register ./cypress/support/delete-user.ts [email protected] | ||
// and that user will get deleted | ||
|
||
import { installGlobals } from "@remix-run/node/globals"; | ||
import { PrismaClientKnownRequestError } from "@prisma/client/runtime"; | ||
import { installGlobals } from "@remix-run/node"; | ||
|
||
import { prisma } from "~/db.server"; | ||
|
||
installGlobals(); | ||
|
@@ -16,7 +18,20 @@ async function deleteUser(email: string) { | |
throw new Error("All test emails must end in @example.com"); | ||
} | ||
|
||
await prisma.user.delete({ where: { email } }); | ||
try { | ||
await prisma.user.delete({ where: { email } }); | ||
} catch (error) { | ||
if ( | ||
error instanceof PrismaClientKnownRequestError && | ||
error.code === "P2025" | ||
) { | ||
console.log("User not found, so no need to delete"); | ||
} else { | ||
throw error; | ||
} | ||
} finally { | ||
await prisma.$disconnect(); | ||
} | ||
} | ||
|
||
deleteUser(process.argv[2]); |
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,15 @@ | ||
import "@testing-library/cypress/add-commands"; | ||
import "./commands"; | ||
|
||
Cypress.on("uncaught:exception", (err) => { | ||
// Cypress and React Hydrating the document don't get along | ||
// for some unknown reason. Hopefully we figure out why eventually | ||
// so we can remove this. | ||
if ( | ||
/hydrat/i.test(err.message) || | ||
/Minified React error #418/.test(err.message) || | ||
/Minified React error #423/.test(err.message) | ||
) { | ||
return false; | ||
} | ||
}); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.