fix: build id mismatch between CI + deploy (#1681)
This commit is contained in:
+32
-8
@@ -2,6 +2,8 @@ import * as path from "$std/path/mod.ts";
|
||||
import { puppeteer } from "./deps.ts";
|
||||
import { assert } from "$std/_util/asserts.ts";
|
||||
import { startFreshServer, waitForText } from "$fresh/tests/test_utils.ts";
|
||||
import { BuildSnapshotJson } from "$fresh/src/build/mod.ts";
|
||||
import { assertStringIncludes } from "$std/testing/asserts.ts";
|
||||
|
||||
Deno.test("build snapshot and restore from it", async (t) => {
|
||||
const fixture = path.join(Deno.cwd(), "tests", "fixture_build");
|
||||
@@ -16,6 +18,10 @@ Deno.test("build snapshot and restore from it", async (t) => {
|
||||
path.join(fixture, "dev.ts"),
|
||||
"build",
|
||||
],
|
||||
env: {
|
||||
GITHUB_SHA: "__BUILD_ID__",
|
||||
DENO_DEPLOYMENT_ID: "__BUILD_ID__",
|
||||
},
|
||||
stdin: "null",
|
||||
stdout: "piped",
|
||||
stderr: "inherit",
|
||||
@@ -31,24 +37,25 @@ Deno.test("build snapshot and restore from it", async (t) => {
|
||||
assert((await Deno.stat(outDir)).isDirectory, "Missing output directory");
|
||||
});
|
||||
|
||||
await t.step("check snapshot file", async () => {
|
||||
const snapshot = JSON.parse(
|
||||
await Deno.readTextFile(path.join(outDir, "snapshot.json")),
|
||||
);
|
||||
const snapshot = JSON.parse(
|
||||
await Deno.readTextFile(path.join(outDir, "snapshot.json")),
|
||||
) as BuildSnapshotJson;
|
||||
|
||||
await t.step("check snapshot file", () => {
|
||||
assert(
|
||||
Array.isArray(snapshot["island-counter_default.js"]),
|
||||
Array.isArray(snapshot.files["island-counter_default.js"]),
|
||||
"Island output file not found in snapshot",
|
||||
);
|
||||
assert(
|
||||
Array.isArray(snapshot["main.js"]),
|
||||
Array.isArray(snapshot.files["main.js"]),
|
||||
"main.js output file not found in snapshot",
|
||||
);
|
||||
assert(
|
||||
Array.isArray(snapshot["signals.js"]),
|
||||
Array.isArray(snapshot.files["signals.js"]),
|
||||
"signals.js output file not found in snapshot",
|
||||
);
|
||||
assert(
|
||||
Array.isArray(snapshot["deserializer.js"]),
|
||||
Array.isArray(snapshot.files["deserializer.js"]),
|
||||
"deserializer.js output file not found in snapshot",
|
||||
);
|
||||
});
|
||||
@@ -79,6 +86,23 @@ Deno.test("build snapshot and restore from it", async (t) => {
|
||||
await page.click("button");
|
||||
|
||||
await waitForText(page, "p", "1");
|
||||
|
||||
// Ensure that it uses the build id from the snapshot
|
||||
const assetUrls = await page.evaluate(() => {
|
||||
const links = Array.from(document.querySelectorAll("link")).map(
|
||||
(link) => link.href,
|
||||
);
|
||||
const scripts = Array.from(document.querySelectorAll("script"))
|
||||
.filter((script) =>
|
||||
script.src && !script.src.endsWith("refresh.js")
|
||||
).map((script) => script.src);
|
||||
|
||||
return [...links, ...scripts];
|
||||
});
|
||||
|
||||
for (let i = 0; i < assetUrls.length; i++) {
|
||||
assertStringIncludes(assetUrls[i], snapshot.build_id);
|
||||
}
|
||||
} finally {
|
||||
await browser.close();
|
||||
}
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
import { useSignal } from "@preact/signals";
|
||||
import Counter from "../islands/Counter.tsx";
|
||||
import { asset, Head } from "$fresh/runtime.ts";
|
||||
|
||||
export default function Home() {
|
||||
const signal = useSignal(0);
|
||||
return (
|
||||
<div>
|
||||
<Head>
|
||||
<link rel="stylesheet" href={asset("/style.css")} />
|
||||
</Head>
|
||||
<Counter id="counter" count={signal} />
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
body {
|
||||
background: peachpuff;
|
||||
}
|
||||
Reference in New Issue
Block a user