Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
brillout committed Aug 6, 2024
1 parent 875db34 commit 98e53b7
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions examples/full/.testRun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export { testRun };

import { test, expect, run, fetchHtml, page, getServerUrl, autoRetry, partRegex } from "@brillout/test-e2e";
import assert from "node:assert";
const dataHk = partRegex`data-hk="${/[0-9-]+/}"`;

let isProd: boolean;

Expand Down Expand Up @@ -41,6 +42,8 @@ function testRun(cmd: `pnpm run ${"dev" | "preview"}`) {
});

testNavigationBetweenWithSSRAndWithoutSSR();

testHeadComponent();
}

function testNavigationBetweenWithSSRAndWithoutSSR() {
Expand Down Expand Up @@ -105,10 +108,8 @@ function testUrl({
expect(html).toContain(text);
}

const dataHkHash = /[0-9-]+/;

expect(getTitle(html)).toBe(title);
expect(html).toMatch(partRegex`<link data-hk="${dataHkHash}" rel="icon" href="${getAssetUrl("logo.svg")}">`);
expect(html).toMatch(partRegex`<link ${dataHk} rel="icon" href="${getAssetUrl("logo.svg")}">`);

if (!description) description = "Demo showcasing Vike + Solid";
expect(html).toMatch(partRegex`<meta name="description" content="${description}">`);
Expand All @@ -123,6 +124,30 @@ function testUrl({
});
}

function testHeadComponent() {
test("Head Component (HTML)", async () => {
const html = await fetchHtml("/images");
expect(html).toMatch(
partRegex`<script ${dataHk} type="application/ld+json">{"@context":"https://schema.org/","contentUrl":{"src":"${getAssetUrl(
"logo-new.svg",
)}"},"creator":{"@type":"Person","name":"brillout"}}</script>`,
);
expect(html).toMatch(
partRegex`<script ${dataHk} type="application/ld+json">{"@context":"https://schema.org/","contentUrl":{"src":"${getAssetUrl(
"logo.svg",
)}"},"creator":{"@type":"Person","name":"Romuald Brillout"}}</script>`,
);
});
test("Head Component (Hydration)", async () => {
await page.goto(getServerUrl() + "/");
await testCounter();
ensureWasClientSideRouted("/pages/index");
await page.click('a:has-text("Head Component")');
await testCounter();
ensureWasClientSideRouted("/pages/index");
});
}

function getTitle(html: string) {
const title = html.match(/<title>(.*?)<\/title>/i)?.[1];
return title;
Expand Down

0 comments on commit 98e53b7

Please sign in to comment.