























@@ -1,19 +1,50 @@
11import { readFile } from "node:fs/promises";
22import { resolve } from "node:path";
33import { fileURLToPath } from "node:url";
4-import { describe, expect, it } from "vitest";
4+import { beforeAll, describe, expect, it } from "vitest";
5566const repoRoot = resolve(fileURLToPath(new URL(".", import.meta.url)), "..");
7+const dockerfilePaths = [
8+"Dockerfile",
9+"Dockerfile.sandbox",
10+"Dockerfile.sandbox-browser",
11+"Dockerfile.sandbox-common",
12+"scripts/docker/cleanup-smoke/Dockerfile",
13+"scripts/docker/install-sh-smoke/Dockerfile",
14+"scripts/docker/install-sh-e2e/Dockerfile",
15+"scripts/docker/install-sh-nonroot/Dockerfile",
16+"scripts/e2e/Dockerfile",
17+"scripts/e2e/Dockerfile.qr-import",
18+] as const;
19+const aptCacheDockerfilePaths = dockerfilePaths.filter(
20+(path) => path !== "scripts/e2e/Dockerfile.qr-import" && path !== "scripts/e2e/Dockerfile",
21+);
22+const shellContinuationDockerfilePaths = dockerfilePaths.filter(
23+(path) =>
24+path !== "Dockerfile" &&
25+path !== "scripts/e2e/Dockerfile" &&
26+path !== "scripts/e2e/Dockerfile.qr-import",
27+);
28+const repoFileCache = new Map<string, Promise<string>>();
729830async function readRepoFile(path: string): Promise<string> {
9-return readFile(resolve(repoRoot, path), "utf8");
31+let cached = repoFileCache.get(path);
32+if (!cached) {
33+cached = readFile(resolve(repoRoot, path), "utf8");
34+repoFileCache.set(path, cached);
35+}
36+return cached;
1037}
11381239function indexOfPattern(source: string, pattern: RegExp): number {
1340return source.search(pattern);
1441}
15421643describe("docker build cache layout", () => {
44+beforeAll(async () => {
45+await Promise.all(dockerfilePaths.map((path) => readRepoFile(path)));
46+});
47+1748it("keeps the root dependency layer independent from scripts changes", async () => {
1849const dockerfile = await readRepoFile("Dockerfile");
1950const installIndex = dockerfile.indexOf("pnpm install --frozen-lockfile");
@@ -42,16 +73,7 @@ describe("docker build cache layout", () => {
4273});
43744475it("uses apt cache mounts in Dockerfiles that install system packages", async () => {
45-for (const path of [
46-"Dockerfile",
47-"Dockerfile.sandbox",
48-"Dockerfile.sandbox-browser",
49-"Dockerfile.sandbox-common",
50-"scripts/docker/cleanup-smoke/Dockerfile",
51-"scripts/docker/install-sh-smoke/Dockerfile",
52-"scripts/docker/install-sh-e2e/Dockerfile",
53-"scripts/docker/install-sh-nonroot/Dockerfile",
54-]) {
76+for (const path of aptCacheDockerfilePaths) {
5577const dockerfile = await readRepoFile(path);
5678expect(dockerfile, `${path} should cache apt package archives`).toContain(
5779"target=/var/cache/apt,sharing=locked",
@@ -71,15 +93,7 @@ describe("docker build cache layout", () => {
7193});
72947395it("does not leave blank lines after shell continuation markers", async () => {
74-for (const path of [
75-"Dockerfile.sandbox",
76-"Dockerfile.sandbox-browser",
77-"Dockerfile.sandbox-common",
78-"scripts/docker/cleanup-smoke/Dockerfile",
79-"scripts/docker/install-sh-smoke/Dockerfile",
80-"scripts/docker/install-sh-e2e/Dockerfile",
81-"scripts/docker/install-sh-nonroot/Dockerfile",
82-]) {
96+for (const path of shellContinuationDockerfilePaths) {
8397const dockerfile = await readRepoFile(path);
8498expect(
8599dockerfile,
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。