Skip to content

Commit

Permalink
More robust BASE_URL support for docs (#7158)
Browse files Browse the repository at this point in the history
Bring back playwright tests.
Archive playwright test report to make it easier to debug failed test runs.
Better define a BASE_URL and BASE_PATH so the playwright tests happily work during a release.
  • Loading branch information
NigelBreslaw authored Dec 19, 2024
1 parent 16ec61f commit 3de87c9
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 32 deletions.
34 changes: 20 additions & 14 deletions .github/workflows/build_docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,27 +104,33 @@ jobs:
working-directory: docs/astro
continue-on-error: true
run: pnpm format
# - name: Update URL for sitemap in astro.config.mjs
- name: Update URL for sitemap in site-config.ts
# if: ${{ env.RELEASE_INPUT == 'true' }}
# run: |
# sed -i 's|"https://snapshots.slint.dev/master/docs/slint/"|"https://releases.slint.dev/${{ steps.version.outputs.VERSION }}/docs/slint/"|' docs/astro/astro.config.mjs
# sed -i 's|"/master/docs/slint"|"/${{ steps.version.outputs.VERSION }}/docs/slint"|' docs/astro/astro.config.mjs
# sed -i 's|href="/master/docs/slint|href="/${{ steps.version.outputs.VERSION }}/docs/slint|' docs/astro/src/content/docs/index.mdx
run: |
sed -i 's|BASE_URL = "https://snapshots.slint.dev"|BASE_URL = "https://releases.slint.dev"|' docs/astro/src/utils/site-config.ts
sed -i 's|BASE_PATH = "/master/docs/slint"|BASE_PATH = "/${{ steps.version.outputs.VERSION }}/docs/slint"|' docs/astro/src/utils/site-config.ts
- name: "Slint Language Documentation"
run: cargo xtask slintdocs
- name: Spellcheck
working-directory: docs/astro
run: pnpm spellcheck
# Test docs
# - name: Install Playwright
# working-directory: docs/astro
# run: pnpm exec playwright install --with-deps
# - name: Run Playwright tests
# working-directory: docs/astro
# run: pnpm exec playwright test
# - name: Publish Test Summary Results
# working-directory: docs/astro
# run: npx github-actions-ctrf playwright-report/ctrf-report.json
- name: Install Playwright
working-directory: docs/astro
run: pnpm exec playwright install --with-deps
- name: Run Playwright tests
working-directory: docs/astro
run: pnpm exec playwright test
- name: Publish Test Summary Results
working-directory: docs/astro
run: npx github-actions-ctrf playwright-report/ctrf-report.json
- name: Upload test results
if: always()
uses: actions/upload-artifact@v3
with:
name: playwright-test-report
path: docs/astro/playwright-report/
retention-days: 30

- name: "Node docs"
run: pnpm run docs
Expand Down
5 changes: 3 additions & 2 deletions docs/astro/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import starlight from "@astrojs/starlight";
import starlightLinksValidator from "starlight-links-validator";
import rehypeExternalLinks from "rehype-external-links";
import starlightSidebarTopics from "starlight-sidebar-topics";
import { BASE_PATH, BASE_URL } from "./src/utils/site-config";

// https://astro.build/config
export default defineConfig({
site: "https://releases.slint.dev/1.9.0/docs/slint/",
base: "/1.9.0/docs/slint",
site: `${BASE_URL}${BASE_PATH}`,
base: BASE_PATH,
markdown: {
rehypePlugins: [
[
Expand Down
5 changes: 3 additions & 2 deletions docs/astro/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: MIT
import { defineConfig, devices } from "@playwright/test";
import { BASE_PATH } from "./src/utils/site-config";

/**
* Read environment variables from file.
Expand Down Expand Up @@ -37,7 +38,7 @@ export default defineConfig({
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: "http://127.0.0.1:4321/master/docs/slint/",
baseURL: `http://localhost:4321${BASE_PATH}`,

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: "on-first-retry",
Expand Down Expand Up @@ -83,7 +84,7 @@ export default defineConfig({
/* Run your local dev server before starting the tests */
webServer: {
command: "pnpm run preview",
url: "http://localhost:4321/master/docs/slint",
url: `http://localhost:4321${BASE_PATH}`,
reuseExistingServer: !process.env.CI,
timeout: 120 * 1000,
},
Expand Down
5 changes: 5 additions & 0 deletions docs/astro/src/utils/site-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: MIT

export const BASE_URL = "https://snapshots.slint.dev";
export const BASE_PATH = "/1.9.0/docs/slint/";
41 changes: 28 additions & 13 deletions docs/astro/tests/link-test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,35 @@ import { test, expect } from "@playwright/test";
import { linkMap } from "../src/utils/utils";

test("Test all links", async ({ page }) => {
const baseUrl = "http://localhost:4321/master/docs/slint";
for (const [key, value] of Object.entries(linkMap)) {
const href = value.href.replace(/^\//, "");

for (const [_key, value] of Object.entries(linkMap)) {
const fullUrl = `${baseUrl}${value.href}`;

try {
const response = await page.request.get(fullUrl);
expect
.soft(response.ok(), `${fullUrl} has no green status code`)
.toBeTruthy();
} catch {
expect
.soft(null, `${fullUrl} has no green status code`)
.toBeTruthy();
// Skip testing anchor links (internal page references)
if (href.includes("#")) {
// Optionally test if the base page exists
const basePath = href.split("#")[0];
if (basePath) {
const response = await page.goto(basePath);
const status = response?.status();
expect(
[200, 304].includes(status!),
`Link ${key} (${basePath}) returned ${status}`,
).toBeTruthy();
}
continue;
}

const response = await page.goto(href);
const status = response?.status();
expect(
[200, 304].includes(status!),
`Link ${key} (${href}) returned ${status}`,
).toBeTruthy();

// Optionally verify we didn't get to an error page
const title = await page.title();
expect(title, `Page ${href} has error title: ${title}`).not.toContain(
"404",
);
}
});
2 changes: 1 addition & 1 deletion docs/astro/tests/smoke-test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { test, expect } from "@playwright/test";

test("smoke test", async ({ page }) => {
await page.goto("http://localhost:4321/master/docs/slint");
await page.goto("");
await expect(page.locator('[id="_top"]')).toContainText("Welcome to Slint");
await page
.getByLabel("Main")
Expand Down

0 comments on commit 3de87c9

Please sign in to comment.