Repository navigation
test: add browser-mode visual regression suite (BON-4) #36
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
b0f2795
test: add a browser-mode Vitest project (BON-4)
hunterbecton 33a9d71
ci: run the bones browser project in its own job (BON-4)
hunterbecton 8430e88
test: screenshot the three skeleton renderers (BON-4)
hunterbecton 53cd42b
ci: upload vitest attachment screenshots from the visual job (BON-4)
hunterbecton d4df3dd
ci: temporarily regenerate visual baselines with --update (BON-4)
hunterbecton bbe32c9
test: commit linux screenshot baselines (BON-4)
hunterbecton 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
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
Binary file added
BIN
+2.74 KB
...ones/tests/browser/__screenshots__/visual.test.tsx/bare-busy-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.74 KB
.../tests/browser/__screenshots__/visual.test.tsx/element-force-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+894 Bytes
...es/tests/browser/__screenshots__/visual.test.tsx/react-force-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,14 @@ | ||
| import { expect, test } from "vite-plus/test"; | ||
|
|
||
| // Proves the browser project runs in a real layout engine: jsdom returns | ||
| // all-zero rects, Chromium cannot. | ||
| test("layout engine is real", () => { | ||
| const el = document.createElement("div"); | ||
| el.textContent = "measure me"; | ||
| el.style.font = "16px/1.5 monospace"; | ||
| document.body.append(el); | ||
| const rect = el.getBoundingClientRect(); | ||
| expect(rect.height).toBeGreaterThan(0); | ||
| expect(rect.width).toBeGreaterThan(0); | ||
| el.remove(); | ||
| }); |
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,90 @@ | ||
| /// <reference types="vite-plus/client" /> | ||
| import type { ReactNode } from "react"; | ||
| import { flushSync } from "react-dom"; | ||
| import { createRoot, type Root } from "react-dom/client"; | ||
| import { afterEach, expect, test } from "vite-plus/test"; | ||
| import { page } from "vite-plus/test/browser"; | ||
| import "../../src/element/index.ts"; | ||
| import "../../src/css/auto.css"; | ||
| import { createBones, forceBones } from "../../src/react/index.ts"; | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // One card, three renderers. auto.css restates the text-bar geometry from | ||
| // bones.css and only a selector-text test pins the copies; these screenshots | ||
| // pin what a user actually sees. data-bone-animate="none" everywhere so the | ||
| // shimmer cannot make an image non-deterministic. | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| const CARD_STYLE = "width: 320px; padding: 16px; font: 16px/1.5 sans-serif; background: #fff;"; | ||
|
|
||
| const roots: Root[] = []; | ||
|
|
||
| afterEach(() => { | ||
| for (const root of roots.splice(0)) root.unmount(); | ||
| document.body.innerHTML = ""; | ||
| }); | ||
|
|
||
| function mountHtml(html: string): HTMLElement { | ||
| document.body.insertAdjacentHTML("beforeend", html); | ||
| return document.body.lastElementChild as HTMLElement; | ||
| } | ||
|
|
||
| function renderReact(node: ReactNode): HTMLElement { | ||
| const host = document.createElement("div"); | ||
| document.body.append(host); | ||
| const root = createRoot(host); | ||
| roots.push(root); | ||
| flushSync(() => root.render(node)); | ||
| return host.firstElementChild as HTMLElement; | ||
| } | ||
|
|
||
| function ReactCard() { | ||
| const { bone } = createBones<{ title: string }>(forceBones); | ||
| return ( | ||
| <div | ||
| data-testid="react-card" | ||
| data-bone-animate="none" | ||
| style={{ width: 320, padding: 16, font: "16px/1.5 sans-serif", background: "#fff" }} | ||
| > | ||
| <div {...bone("block")} style={{ width: 48, height: 48 }} /> | ||
| <h3 {...bone("text")}>Placeholder title</h3> | ||
| <p {...bone("text")}>Placeholder body copy that runs a little longer.</p> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| const CONTENT = ` | ||
| <img alt="" width="48" height="48" /> | ||
| <h3>Real title</h3> | ||
| <p>Real body copy that runs a little longer than one line at this width.</p> | ||
| <button type="button">Save</button> | ||
| `; | ||
|
|
||
| // Each `toMatchScreenshot` call below needs a suppression for the same | ||
| // upstream typing gap documented on the `toMatchScreenshot` config key in | ||
| // vite.config.ts: vite-plus-test's `declare module "vitest/node"` | ||
| // augmentation targets the real `vitest` package, not vite-plus's vendored | ||
| // internal copy, so `Assertion<Locator>` here has no merged type even | ||
| // though the matcher exists and passes at runtime (proven by this file). | ||
|
|
||
| test("react renderer with forceBones", async () => { | ||
| renderReact(<ReactCard />); | ||
| // @ts-expect-error — see the file-level comment above. | ||
| await expect(page.getByTestId("react-card")).toMatchScreenshot("react-force"); | ||
| }); | ||
|
|
||
| test("element renderer with auto.css", async () => { | ||
| mountHtml( | ||
| `<bones-boundary force data-testid="element-card" data-bone-animate="none" style="${CARD_STYLE} display: block;">${CONTENT}</bones-boundary>`, | ||
| ); | ||
| // @ts-expect-error — see the file-level comment above. | ||
| await expect(page.getByTestId("element-card")).toMatchScreenshot("element-force"); | ||
| }); | ||
|
|
||
| test("bare aria-busy region with auto.css", async () => { | ||
| mountHtml( | ||
| `<div aria-busy="true" data-testid="bare-card" data-bone-animate="none" style="${CARD_STYLE}">${CONTENT}</div>`, | ||
| ); | ||
| // @ts-expect-error — see the file-level comment above. | ||
| await expect(page.getByTestId("bare-card")).toMatchScreenshot("bare-busy"); | ||
| }); | ||
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.