mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-04 18:58:36 +00:00
More robust BASE_URL support for docs (#7158)
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.
This commit is contained in:
parent
16ec61f922
commit
3de87c9bd8
6 changed files with 60 additions and 32 deletions
34
.github/workflows/build_docs.yaml
vendored
34
.github/workflows/build_docs.yaml
vendored
|
@ -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
|
||||
|
|
|
@ -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: [
|
||||
[
|
||||
|
|
|
@ -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.
|
||||
|
@ -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",
|
||||
|
@ -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,
|
||||
},
|
||||
|
|
5
docs/astro/src/utils/site-config.ts
Normal file
5
docs/astro/src/utils/site-config.ts
Normal file
|
@ -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/";
|
|
@ -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",
|
||||
);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue