-
-
Notifications
You must be signed in to change notification settings - Fork 257
Add Cypress E2E testing with ReScript bindings and CI integration #1239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7113b01
Add Cypress E2E testing with ReScript bindings and CI integration
jderochervlk 2113bfa
Use Cypress GitHub Action for E2E tests in deploy workflow
jderochervlk 05cdbcf
pr feedback
jderochervlk 050c93f
wait again
jderochervlk 1193f73
configure retries
jderochervlk 70aa23f
change type name
jderochervlk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,18 @@ | ||
| import { defineConfig } from "cypress"; | ||
|
|
||
| export default defineConfig({ | ||
| allowCypressEnv: false, | ||
| retries: { | ||
| runMode: 2, | ||
| openMode: 0, | ||
| }, | ||
| e2e: { | ||
| baseUrl: "http://localhost:8080", | ||
| specPattern: "e2e/**/*.cy.jsx", | ||
| supportFile: "cypress/support/e2e.js", | ||
| video: false, | ||
| screenshotOnRunFailure: false, | ||
| defaultCommandTimeout: 10000, | ||
| pageLoadTimeout: 30000, | ||
| }, | ||
| }); |
This file contains hidden or 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,23 @@ | ||
| const knownHydrationErrors = [ | ||
| /Hydration failed because the initial UI does not match what was rendered on the server\.?/, | ||
| /Text content does not match server-rendered HTML\.?/, | ||
| /There was an error while hydrating\.?/, | ||
| /Minified React error #418\b/, | ||
| /Minified React error #423\b/, | ||
| /Minified React error #425\b/, | ||
| ]; | ||
|
|
||
| Cypress.on("uncaught:exception", (err) => { | ||
| const message = err && err.message ? err.message : ""; | ||
| const isKnownHydrationError = knownHydrationErrors.some((pattern) => | ||
| pattern.test(message), | ||
| ); | ||
|
|
||
| if (isKnownHydrationError) { | ||
| console.warn("Suppressing known React hydration exception in Cypress:", { | ||
| message, | ||
| error: err, | ||
| }); | ||
| return false; | ||
| } | ||
| }); |
This file contains hidden or 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,213 @@ | ||
| open Cy | ||
|
|
||
| // Wait for the app to fully hydrate before interacting with links. | ||
| // The production build is pre-rendered so React must attach event | ||
| // handlers before client-side navigation works. | ||
| let waitForHydration = () => { | ||
| getByTestId("navbar-primary")->shouldBeVisible->ignore | ||
| cyWindow()->its("document.readyState")->shouldWithValue("eq", "complete")->ignore | ||
| wait(2000) | ||
| } | ||
|
|
||
| // Use short, re-queryable selectors to avoid detached DOM issues. | ||
| // When React re-renders during navigation, long chains can hold | ||
| // references to stale elements. Separate cy.get() calls let Cypress | ||
| // re-query from the DOM root on each retry. | ||
|
|
||
| let clickNavLink = (~testId, ~text) => { | ||
| get(`[data-testid="${testId}"] a:visible`) | ||
| ->containsChainable(text) | ||
| ->click | ||
| ->ignore | ||
| } | ||
|
|
||
| let clickMobileNavLink = text => { | ||
| get(`[data-testid="mobile-nav"] a:visible`) | ||
| ->containsChainable(text) | ||
| ->click | ||
| ->ignore | ||
| } | ||
|
|
||
| let openMobileMenu = () => { | ||
| get(`[data-testid="toggle-mobile-overlay"]`)->should("be.visible")->click->ignore | ||
| get("#mobile-overlay")->should("be.visible")->ignore | ||
| } | ||
|
|
||
| // -- Desktop (1280x720) ------------------------------------------------------- | ||
|
|
||
| describe("Desktop Navigation", () => { | ||
| beforeEach(() => { | ||
| viewport(1280, 720) | ||
| visit("/") | ||
| waitForHydration() | ||
| }) | ||
|
|
||
| describe("Primary navbar", () => { | ||
| it( | ||
| "should navigate to Docs via navbar link", | ||
| () => { | ||
| clickNavLink(~testId="navbar-primary-left-content", ~text="Docs") | ||
| url()->shouldInclude("/docs/manual/introduction")->ignore | ||
| get("h1")->shouldBeVisible->ignore | ||
| }, | ||
| ) | ||
|
|
||
| it( | ||
| "should navigate to Playground via navbar link", | ||
| () => { | ||
| clickNavLink(~testId="navbar-primary-left-content", ~text="Playground") | ||
| url()->shouldInclude("/try")->ignore | ||
| }, | ||
| ) | ||
|
|
||
| it( | ||
| "should navigate to Blog via navbar link", | ||
| () => { | ||
| clickNavLink(~testId="navbar-primary-left-content", ~text="Blog") | ||
| url()->shouldInclude("/blog")->ignore | ||
| }, | ||
| ) | ||
|
|
||
| it( | ||
| "should navigate to Community via navbar link", | ||
| () => { | ||
| clickNavLink(~testId="navbar-primary-left-content", ~text="Community") | ||
| url()->shouldInclude("/community")->ignore | ||
| get("h1")->shouldBeVisible->ignore | ||
| }, | ||
| ) | ||
|
|
||
| it( | ||
| "should navigate home via logo after clicking away", | ||
| () => { | ||
| clickNavLink(~testId="navbar-primary-left-content", ~text="Blog") | ||
| url()->shouldInclude("/blog")->ignore | ||
|
|
||
| get("a[aria-label='homepage']")->should("be.visible")->first->click->ignore | ||
| cyLocation("pathname")->shouldWithValue("eq", "/")->ignore | ||
| }, | ||
| ) | ||
| }) | ||
|
|
||
| describe("Secondary navbar", () => { | ||
| it( | ||
| "should navigate through all secondary nav links from Docs", | ||
| () => { | ||
| // Click Docs in primary nav to reveal the secondary nav | ||
| clickNavLink(~testId="navbar-primary-left-content", ~text="Docs") | ||
| url()->shouldInclude("/docs/manual/introduction")->ignore | ||
|
|
||
| // Language Manual | ||
| clickNavLink(~testId="navbar-secondary", ~text="Language Manual") | ||
| url()->shouldInclude("/docs/manual/introduction")->ignore | ||
|
|
||
| // API | ||
| clickNavLink(~testId="navbar-secondary", ~text="API") | ||
| url()->shouldInclude("/docs/manual/api")->ignore | ||
|
|
||
| // Syntax Lookup | ||
| clickNavLink(~testId="navbar-secondary", ~text="Syntax Lookup") | ||
| url()->shouldInclude("/syntax-lookup")->ignore | ||
|
|
||
| // React | ||
| clickNavLink(~testId="navbar-secondary", ~text="React") | ||
| url()->shouldInclude("/docs/react/introduction")->ignore | ||
| }, | ||
| ) | ||
| }) | ||
| }) | ||
|
|
||
| // -- Mobile (375x667) --------------------------------------------------------- | ||
|
|
||
| describe("Mobile Navigation", () => { | ||
| beforeEach(() => { | ||
| viewport(375, 667) | ||
| visit("/") | ||
| waitForHydration() | ||
| }) | ||
|
|
||
| describe("Primary navbar", () => { | ||
| it( | ||
| "should navigate to Docs via navbar link", | ||
| () => { | ||
| clickNavLink(~testId="navbar-primary-left-content", ~text="Docs") | ||
| url()->shouldInclude("/docs/manual/introduction")->ignore | ||
| get("h1")->shouldBeVisible->ignore | ||
| }, | ||
| ) | ||
|
|
||
| it( | ||
| "should navigate home via logo after clicking away", | ||
| () => { | ||
| clickNavLink(~testId="navbar-primary-left-content", ~text="Docs") | ||
| url()->shouldInclude("/docs/manual/introduction")->ignore | ||
|
|
||
| get("a[aria-label='homepage']")->should("be.visible")->first->click->ignore | ||
| cyLocation("pathname")->shouldWithValue("eq", "/")->ignore | ||
| }, | ||
| ) | ||
| }) | ||
|
|
||
| describe("Mobile overlay navigation", () => { | ||
| it( | ||
| "should navigate to Playground via mobile menu", | ||
| () => { | ||
| openMobileMenu() | ||
| clickMobileNavLink("Playground") | ||
| url()->shouldInclude("/try")->ignore | ||
| }, | ||
| ) | ||
|
|
||
| it( | ||
| "should navigate to Blog via mobile menu", | ||
| () => { | ||
| openMobileMenu() | ||
| clickMobileNavLink("Blog") | ||
| url()->shouldInclude("/blog")->ignore | ||
| }, | ||
| ) | ||
|
|
||
| it( | ||
| "should navigate to Community via mobile menu", | ||
| () => { | ||
| openMobileMenu() | ||
| clickMobileNavLink("Community") | ||
| url()->shouldInclude("/community")->ignore | ||
| get("h1")->shouldBeVisible->ignore | ||
| }, | ||
| ) | ||
| }) | ||
|
|
||
| describe("Secondary navbar", () => { | ||
| it( | ||
| "should navigate through all secondary nav links from Docs", | ||
| () => { | ||
| // Click Docs in primary nav to reveal the secondary nav | ||
| clickNavLink(~testId="navbar-primary-left-content", ~text="Docs") | ||
| url()->shouldInclude("/docs/manual/introduction")->ignore | ||
|
|
||
| // Scroll to top so the secondary nav is visible | ||
| cyScrollTo("top") | ||
|
|
||
| // Language Manual | ||
| clickNavLink(~testId="navbar-secondary", ~text="Language Manual") | ||
| url()->shouldInclude("/docs/manual/introduction")->ignore | ||
|
|
||
| // API | ||
| cyScrollTo("top") | ||
| clickNavLink(~testId="navbar-secondary", ~text="API") | ||
| url()->shouldInclude("/docs/manual/api")->ignore | ||
|
|
||
| // Syntax Lookup | ||
| cyScrollTo("top") | ||
| clickNavLink(~testId="navbar-secondary", ~text="Syntax Lookup") | ||
| url()->shouldInclude("/syntax-lookup")->ignore | ||
|
|
||
| // React | ||
| cyScrollTo("top") | ||
| clickNavLink(~testId="navbar-secondary", ~text="React") | ||
| url()->shouldInclude("/docs/react/introduction")->ignore | ||
| }, | ||
| ) | ||
| }) | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.