-
Notifications
You must be signed in to change notification settings - Fork 180
test: add visual contract CI foundation #799
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
5 commits
Select commit
Hold shift + click to select a range
21ba45f
test: add tooltip visual contract
mattrothenberg 396d566
chore: capture linux visual contract baseline
mattrothenberg b261de5
test: add linux visual contract baseline
mattrothenberg e28e05b
ci: add visual contract PR gallery
mattrothenberg a30891a
Merge branch 'main' into test/tooltip-visual-contract
mattrothenberg 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@cloudflare/kumo": patch | ||
| --- | ||
|
|
||
| Add a visual regression contract for truncating text in default Tooltip triggers. |
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
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,93 @@ | ||
| #!/usr/bin/env tsx | ||
|
|
||
| /** | ||
| * Publish the curated visual-contract gallery for a pull request. | ||
| * | ||
| * This runs from the trusted default-branch checkout after the untrusted PR | ||
| * workflow completes. Screenshot paths come from GitHub's tree API, and only | ||
| * PNGs beneath Kumo component screenshot directories are rendered. | ||
| */ | ||
|
|
||
| import { Octokit } from "@octokit/rest"; | ||
| import { | ||
| GITHUB_REPO_NAME, | ||
| GITHUB_REPO_OWNER, | ||
| upsertPRComment, | ||
| } from "../utils/github-api"; | ||
|
|
||
| const COMMENT_MARKER = "<!-- kumo-visual-contracts-report -->"; | ||
| const SCREENSHOT_PATH = | ||
| /^packages\/kumo\/src\/components\/.+\/__screenshots__\/.+\.png$/; | ||
|
|
||
| function displayName(path: string): string { | ||
| return ( | ||
| path | ||
| .split("/") | ||
| .at(-1) | ||
| ?.replace(/-chromium-(darwin|linux)\.png$/, "") | ||
| .replace(/\.png$/, "") | ||
| .replaceAll("-", " ") ?? path | ||
| ); | ||
| } | ||
|
|
||
| async function main(): Promise<void> { | ||
| const token = process.env.GITHUB_TOKEN ?? ""; | ||
| const prNumber = Number(process.env.GITHUB_PR_NUMBER); | ||
| const headSha = process.env.VISUAL_CONTRACTS_HEAD_SHA ?? ""; | ||
|
|
||
| if (!token || !Number.isInteger(prNumber) || prNumber <= 0 || !headSha) { | ||
| throw new Error( | ||
| "GITHUB_TOKEN, GITHUB_PR_NUMBER, and VISUAL_CONTRACTS_HEAD_SHA are required", | ||
| ); | ||
| } | ||
|
|
||
| const octokit = new Octokit({ auth: token }); | ||
| const { data } = await octokit.git.getTree({ | ||
| owner: GITHUB_REPO_OWNER, | ||
| repo: GITHUB_REPO_NAME, | ||
| tree_sha: headSha, | ||
| recursive: "true", | ||
| }); | ||
| const screenshots = data.tree | ||
| .filter( | ||
| (entry) => | ||
| entry.type === "blob" && SCREENSHOT_PATH.test(entry.path ?? ""), | ||
| ) | ||
| .map((entry) => entry.path as string) | ||
| .filter((path) => path.endsWith("-chromium-linux.png")) | ||
| .sort(); | ||
|
|
||
| if (screenshots.length === 0) { | ||
| console.log( | ||
| "No Linux visual-contract screenshots found; skipping PR comment", | ||
| ); | ||
| return; | ||
| } | ||
|
|
||
| const gallery = screenshots | ||
| .map((path) => { | ||
| const url = `https://github.com/${GITHUB_REPO_OWNER}/${GITHUB_REPO_NAME}/blob/${headSha}/${path}?raw=true`; | ||
| return `#### ${displayName(path)}\n\n`; | ||
| }) | ||
| .join("\n\n"); | ||
| const content = [ | ||
| "## Visual contracts", | ||
| "", | ||
| "Linux Chromium references exercised by the PR's `visual-contracts` job.", | ||
| "", | ||
| "<details>", | ||
| `<summary>${screenshots.length} curated contract${screenshots.length === 1 ? "" : "s"}</summary>`, | ||
| "", | ||
| gallery, | ||
| "", | ||
| "</details>", | ||
| ].join("\n"); | ||
|
|
||
| await upsertPRComment(token, prNumber, COMMENT_MARKER, content); | ||
| console.log(`Visual-contract gallery posted to PR #${prNumber}`); | ||
| } | ||
|
|
||
| main().catch((error) => { | ||
| console.error("Failed to post visual-contract gallery:", error); | ||
| process.exit(1); | ||
| }); |
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
+3.15 KB
...s__/tooltip.visual.browser.test.tsx/truncating-text-trigger-chromium-darwin.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
+1.21 KB
...ts__/tooltip.visual.browser.test.tsx/truncating-text-trigger-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.
22 changes: 22 additions & 0 deletions
22
packages/kumo/src/components/tooltip/tooltip.visual.browser.test.tsx
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,22 @@ | ||
| import { describe, expect, test } from "vite-plus/test"; | ||
| import { render } from "vitest-browser-react"; | ||
| import { Text } from "../text/text"; | ||
| import { Tooltip } from "./tooltip"; | ||
|
|
||
| describe("Tooltip visual contracts", () => { | ||
| test("keeps a truncating Text trigger visible", async () => { | ||
| const { getByTestId } = await render( | ||
| <div className="w-24" data-testid="tooltip-text-trigger"> | ||
| <Tooltip content="Network range details"> | ||
| <Text as="span" size="sm" truncate> | ||
| 192.0.2.0/24 | ||
| </Text> | ||
| </Tooltip> | ||
| </div>, | ||
| ); | ||
|
|
||
| await expect | ||
| .element(getByTestId("tooltip-text-trigger")) | ||
| .toMatchScreenshot("truncating-text-trigger"); | ||
| }); | ||
| }); | ||
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,19 @@ | ||
| import { defineConfig } from "vite-plus"; | ||
| import { playwright } from "vite-plus/test/browser-playwright"; | ||
| import react from "@vitejs/plugin-react"; | ||
| import tailwindcss from "@tailwindcss/vite"; | ||
|
|
||
| export default defineConfig({ | ||
| plugins: [react(), tailwindcss()], | ||
| test: { | ||
| include: ["**/*.visual.browser.test.tsx"], | ||
| setupFiles: ["./tests/setup-browser.css"], | ||
| browser: { | ||
| enabled: true, | ||
| provider: playwright(), | ||
| instances: [{ browser: "chromium" }], | ||
| screenshotFailures: true, | ||
| }, | ||
| testTimeout: 2_000, | ||
| }, | ||
| }); |
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.