-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(tests): add stylesheet fixture to test for regression from docs…
… bundle (#1429)
- Loading branch information
1 parent
8d69ce0
commit 16d61c6
Showing
14 changed files
with
179 additions
and
102 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
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
instances: | ||
- url: https://stylesheet-fixture.docs.buildwithfern.com | ||
title: Sample Styled Docs | ||
navigation: | ||
- page: Test Page | ||
path: ./page.mdx | ||
colors: | ||
accentPrimary: "#ffffff" | ||
background: "#330000" |
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,4 @@ | ||
{ | ||
"organization": "stylesheet-fixture", | ||
"version": "*" | ||
} |
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,4 @@ | ||
--- | ||
title: Welcome to a demo site | ||
slug: page | ||
--- |
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,18 @@ | ||
import test, { expect } from "@playwright/test"; | ||
import { runFixture } from "../../test-runner"; | ||
|
||
const port = "6983"; | ||
test("Check CSS variable values", async ({ page }) => { | ||
const computedStyles = await runFixture("stylesheet", port, async () => { | ||
await page.goto(`localhost:${port}`); | ||
|
||
const element = page.locator("body"); | ||
return await element.evaluate((el) => { | ||
const styles = window.getComputedStyle(el); | ||
return { | ||
backgroundColor: styles.getPropertyValue("--background"), | ||
}; | ||
}); | ||
}); | ||
expect(computedStyles.backgroundColor.trim()).toBe("51, 0, 0"); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
cd playwright/fixtures/$1 | ||
fern-dev docs dev --port $2 --bundle-path ../../../packages/ui/local-preview-bundle/out |
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,10 @@ | ||
import { expect, test } from "@playwright/test"; | ||
import { getPlaywrightTestUrls } from "../test-runner"; | ||
|
||
const existenceUrls = getPlaywrightTestUrls("existence"); | ||
existenceUrls.forEach((testUrl) => { | ||
test(`Check if ${testUrl} is online`, async ({ page }) => { | ||
const response = await page.goto(testUrl); | ||
expect(response?.status()).toBe(200); | ||
}); | ||
}); |
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,22 @@ | ||
import test, { expect } from "@playwright/test"; | ||
import { getPlaywrightTestUrls } from "../test-runner"; | ||
|
||
const faviconUrls = getPlaywrightTestUrls("favicon"); | ||
faviconUrls.forEach((testUrl) => { | ||
test(`Check if favicon exists and URL does not return 404 for ${testUrl}`, async ({ page }) => { | ||
await page.goto(testUrl); | ||
|
||
const faviconUrl = await page.getAttribute('link[rel="icon"]', "href", { | ||
timeout: 5000, | ||
}); | ||
|
||
expect(faviconUrl).not.toBeNull(); | ||
|
||
if (faviconUrl) { | ||
const response = await page.goto(faviconUrl); | ||
expect(response?.status()).toBe(200); | ||
} else { | ||
throw new Error("Favicon link not found"); | ||
} | ||
}); | ||
}); |
2 changes: 1 addition & 1 deletion
2
playwright/versioned-docs.spec.ts → playwright/smoke/versioned-docs.spec.ts
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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { spawn } from "child_process"; | ||
import * as fs from "fs"; | ||
import * as yaml from "js-yaml"; | ||
|
||
export function getPlaywrightTestUrls(type: string): string[] { | ||
const testUrls: string[] = []; | ||
const playwrightConfig = yaml.load(fs.readFileSync("playwright/inclusions.yml", "utf-8")); | ||
|
||
if (!(type in playwrightConfig)) { | ||
throw new Error(`Test type ${type} not found in playwright/inclusions.yml`); | ||
} | ||
const testInclusions = new Set<string>(playwrightConfig[type]); | ||
|
||
function processLineByLineSync(filePath: string): void { | ||
const fileContent = fs.readFileSync(filePath, "utf-8"); | ||
|
||
const lines = fileContent.split(/\r?\n/); | ||
|
||
lines.forEach((line) => { | ||
const urlPattern = /\(([^)]+\?host=([^&]+))\)/; | ||
const match = line.match(urlPattern); | ||
if (match) { | ||
const fullUrl = match[1]; | ||
const isIncludedUrl = match[2]; | ||
if (fullUrl && testInclusions.has(isIncludedUrl ?? "")) { | ||
testUrls.push(fullUrl); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
processLineByLineSync("preview.txt"); | ||
|
||
if (testUrls.length === 0) { | ||
throw new Error("No URLs found in preview.txt"); | ||
} | ||
|
||
return testUrls; | ||
} | ||
|
||
function sleep(ms: number): Promise<void> { | ||
return new Promise((resolve) => setTimeout(resolve, ms)); | ||
} | ||
|
||
export async function runFixture<T>(fixturePath: string, port: string, test: () => Promise<T>): Promise<T> { | ||
const l = spawn("playwright/run-fixture.sh", [fixturePath, port]); | ||
l.stdout.pipe(process.stdout); | ||
l.stderr.pipe(process.stderr); | ||
await sleep(7500); | ||
|
||
const result = await test(); | ||
|
||
await sleep(500); | ||
const livePort = spawn("lsof", ["-i", `:${port}`, "-t"]); | ||
livePort.stdout.on("data", (data) => { | ||
data.toString() | ||
.split("\n") | ||
.forEach((pid: string) => { | ||
if (pid.length > 0 && Number(pid) !== process.pid) { | ||
process.kill(Number(pid)); | ||
} | ||
}); | ||
}); | ||
await sleep(500); | ||
|
||
return result; | ||
} |