refactor: add integrationTest() helper to reduce test boilerplate (#3711)

## Summary
- Adds an `integrationTest()` wrapper in
`packages/fresh/src/test_utils.ts` that calls `Deno.test` with
`sanitizeOps: false` and `sanitizeResources: false`
- Converts ~88 integration tests across 5 files to use the new helper,
removing repetitive sanitizer boilerplate
- Net reduction of ~344 lines (-1678/+1334)

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Bartek Iwańczuk
2026-03-30 19:14:10 +02:00
committed by GitHub
co-authored by Claude Opus 4.6
parent 196509274f
commit a872a70e5f
7 changed files with 1501 additions and 1894 deletions
+58 -136
View File
@@ -4,16 +4,14 @@ import { Builder, specToName } from "./builder.ts";
import { App } from "../app.ts"; import { App } from "../app.ts";
import { DEV_ERROR_OVERLAY_URL } from "../constants.ts"; import { DEV_ERROR_OVERLAY_URL } from "../constants.ts";
import { BUILD_ID } from "@fresh/build-id"; import { BUILD_ID } from "@fresh/build-id";
import { withTmpDir, writeFiles } from "../test_utils.ts"; import { integrationTest, withTmpDir, writeFiles } from "../test_utils.ts";
import { import {
getStdOutput, getStdOutput,
withChildProcessServer, withChildProcessServer,
} from "../../tests/test_utils.tsx"; } from "../../tests/test_utils.tsx";
import { staticFiles } from "../middlewares/static_files.ts"; import { staticFiles } from "../middlewares/static_files.ts";
Deno.test({ integrationTest("Builder - chain onTransformStaticFile", async () => {
name: "Builder - chain onTransformStaticFile",
fn: async () => {
await using _tmp = await withTmpDir(); await using _tmp = await withTmpDir();
const tmp = _tmp.dir; const tmp = _tmp.dir;
@@ -45,14 +43,9 @@ Deno.test({
await builder.build(); await builder.build();
expect(logs).toEqual(["A", "B", "C"]); expect(logs).toEqual(["A", "B", "C"]);
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest("Builder - handles Windows paths", async () => {
name: "Builder - handles Windows paths",
fn: async () => {
await using _tmp = await withTmpDir(); await using _tmp = await withTmpDir();
const tmp = _tmp.dir; const tmp = _tmp.dir;
@@ -71,14 +64,9 @@ Deno.test({
path.join(tmp, "dist", "snapshot.js"), path.join(tmp, "dist", "snapshot.js"),
); );
expect(snapshotJson).toContain("/images/batman.svg"); expect(snapshotJson).toContain("/images/batman.svg");
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest("Builder - hashes CSS urls by default", async () => {
name: "Builder - hashes CSS urls by default",
fn: async () => {
await using _tmp = await withTmpDir(); await using _tmp = await withTmpDir();
const tmp = _tmp.dir; const tmp = _tmp.dir;
const builder = new Builder({ const builder = new Builder({
@@ -96,15 +84,10 @@ Deno.test({
path.join(tmp, "dist", "static", "foo.css"), path.join(tmp, "dist", "static", "foo.css"),
); );
expect(css).toContain('body { background: url("/foo.jpg?__frsh_c='); expect(css).toContain('body { background: url("/foo.jpg?__frsh_c=');
},
sanitizeOps: false,
sanitizeResources: false,
}); });
// Issue https://github.com/denoland/fresh/issues/2599 // Issue https://github.com/denoland/fresh/issues/2599
Deno.test({ integrationTest("Builder - hashes CSS urls by default", async () => {
name: "Builder - hashes CSS urls by default",
fn: async () => {
await using _tmp = await withTmpDir(); await using _tmp = await withTmpDir();
const tmp = _tmp.dir; const tmp = _tmp.dir;
const builder = new Builder({ const builder = new Builder({
@@ -123,14 +106,9 @@ Deno.test({
expect(css).toEqual( expect(css).toEqual(
`:root { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='rgb(76, 154.5, 137.5)' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'%3E%3C/polyline%3E%3C/svg%3E"); }`, `:root { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='rgb(76, 154.5, 137.5)' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'%3E%3C/polyline%3E%3C/svg%3E"); }`,
); );
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest("Builder - can bundle islands from JSR", async () => {
name: "Builder - can bundle islands from JSR",
fn: async () => {
await using _tmp = await withTmpDir(); await using _tmp = await withTmpDir();
const tmp = _tmp.dir; const tmp = _tmp.dir;
@@ -155,14 +133,11 @@ Deno.test({
), ),
); );
expect(code).toContain('"remote-island"'); expect(code).toContain('"remote-island"');
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest(
name: "Builder - can bundle islands with import.meta.resolve()", "Builder - can bundle islands with import.meta.resolve()",
fn: async () => { async () => {
await using _tmp = await withTmpDir(); await using _tmp = await withTmpDir();
const tmp = _tmp.dir; const tmp = _tmp.dir;
@@ -190,13 +165,9 @@ Deno.test({
); );
expect(code).toContain('"decrement"'); expect(code).toContain('"decrement"');
}, },
sanitizeOps: false, );
sanitizeResources: false,
});
Deno.test({ integrationTest("Builder - exclude files", async () => {
name: "Builder - exclude files",
fn: async () => {
await using _tmp = await withTmpDir(); await using _tmp = await withTmpDir();
const tmp = _tmp.dir; const tmp = _tmp.dir;
@@ -238,14 +209,11 @@ Deno.test({
await builder.build(); await builder.build();
expect(logs).toEqual(["A: bar.css", "B: bar.css", "C: bar.css"]); expect(logs).toEqual(["A: bar.css", "B: bar.css", "C: bar.css"]);
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest(
name: "Builder - workspace folder middleware on listen", "Builder - workspace folder middleware on listen",
fn: async () => { async () => {
await using _tmp = await withTmpDir(); await using _tmp = await withTmpDir();
const tmp = _tmp.dir; const tmp = _tmp.dir;
@@ -277,13 +245,9 @@ Deno.test({
}, },
}); });
}, },
sanitizeOps: false, );
sanitizeResources: false,
});
Deno.test({ integrationTest("Builder - .well-known static files", async () => {
name: "Builder - .well-known static files",
fn: async () => {
await using _tmp = await withTmpDir(); await using _tmp = await withTmpDir();
const tmp = _tmp.dir; const tmp = _tmp.dir;
@@ -312,14 +276,9 @@ Deno.test({
expect(res.ok).toBe(true); expect(res.ok).toBe(true);
expect(res.status).toBe(200); expect(res.status).toBe(200);
expect(json).toEqual({ ok: true }); expect(json).toEqual({ ok: true });
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest("Builder - write prod routePattern", async () => {
name: "Builder - write prod routePattern",
fn: async () => {
const root = path.join(import.meta.dirname!, "..", ".."); const root = path.join(import.meta.dirname!, "..", "..");
await using _tmp = await withTmpDir({ dir: root, prefix: "tmp_builder_" }); await using _tmp = await withTmpDir({ dir: root, prefix: "tmp_builder_" });
const tmp = _tmp.dir; const tmp = _tmp.dir;
@@ -347,14 +306,9 @@ export const app = new App().fsRoutes()`,
); );
expect(text).toEqual("ok"); expect(text).toEqual("ok");
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest("Builder - file:// islands", async () => {
name: "Builder - file:// islands",
fn: async () => {
const root = path.join(import.meta.dirname!, "..", ".."); const root = path.join(import.meta.dirname!, "..", "..");
await using _tmp = await withTmpDir({ dir: root, prefix: "tmp_builder_" }); await using _tmp = await withTmpDir({ dir: root, prefix: "tmp_builder_" });
const tmp = _tmp.dir; const tmp = _tmp.dir;
@@ -387,16 +341,16 @@ export const app = new App().fsRoutes()`,
); );
expect(text).toContain("<h1>ok</h1>"); expect(text).toContain("<h1>ok</h1>");
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest(
name: "Builder - dev server doesn't overtake _error handler", "Builder - dev server doesn't overtake _error handler",
fn: async () => { async () => {
const root = path.join(import.meta.dirname!, "..", ".."); const root = path.join(import.meta.dirname!, "..", "..");
await using _tmp = await withTmpDir({ dir: root, prefix: "tmp_builder_" }); await using _tmp = await withTmpDir({
dir: root,
prefix: "tmp_builder_",
});
const tmp = _tmp.dir; const tmp = _tmp.dir;
const app = new App() const app = new App()
@@ -421,13 +375,9 @@ Deno.test({
}, },
}); });
}, },
sanitizeOps: false, );
sanitizeResources: false,
});
Deno.test({ integrationTest("Builder - dev server supports basePath", async () => {
name: "Builder - dev server supports basePath",
fn: async () => {
const root = path.join(import.meta.dirname!, "..", ".."); const root = path.join(import.meta.dirname!, "..", "..");
await using _tmp = await withTmpDir({ dir: root, prefix: "tmp_builder_" }); await using _tmp = await withTmpDir({ dir: root, prefix: "tmp_builder_" });
const tmp = _tmp.dir; const tmp = _tmp.dir;
@@ -466,14 +416,9 @@ Deno.test({
expect(app.config.basePath).toEqual("/foo/bar"); expect(app.config.basePath).toEqual("/foo/bar");
controller.abort(); controller.abort();
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest("Builder - serves static files in subdir", async () => {
name: "Builder - serves static files in subdir",
fn: async () => {
const root = path.join(import.meta.dirname!, "..", ".."); const root = path.join(import.meta.dirname!, "..", "..");
await using _tmp = await withTmpDir({ dir: root, prefix: "tmp_builder_" }); await using _tmp = await withTmpDir({ dir: root, prefix: "tmp_builder_" });
const tmp = _tmp.dir; const tmp = _tmp.dir;
@@ -512,16 +457,16 @@ Deno.test({
}); });
await waiter.promise; await waiter.promise;
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest(
name: "Builder - serves static files in subdir in prod", "Builder - serves static files in subdir in prod",
fn: async () => { async () => {
const root = path.join(import.meta.dirname!, "..", ".."); const root = path.join(import.meta.dirname!, "..", "..");
await using _tmp = await withTmpDir({ dir: root, prefix: "tmp_builder_" }); await using _tmp = await withTmpDir({
dir: root,
prefix: "tmp_builder_",
});
const tmp = _tmp.dir; const tmp = _tmp.dir;
await writeFiles(tmp, { await writeFiles(tmp, {
@@ -545,13 +490,9 @@ export const app = new App()
}, },
); );
}, },
sanitizeOps: false, );
sanitizeResources: false,
});
Deno.test({ integrationTest("Builder - custom server entry", async () => {
name: "Builder - custom server entry",
fn: async () => {
const root = path.join(import.meta.dirname!, "..", ".."); const root = path.join(import.meta.dirname!, "..", "..");
await using _tmp = await withTmpDir({ dir: root, prefix: "tmp_builder_" }); await using _tmp = await withTmpDir({ dir: root, prefix: "tmp_builder_" });
const tmp = _tmp.dir; const tmp = _tmp.dir;
@@ -571,16 +512,16 @@ export const app = new App()
expect(await res.text()).toEqual("ok"); expect(await res.text()).toEqual("ok");
}, },
); );
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest(
name: "Builder - dev server error_overlay ignores _app and _layout", "Builder - dev server error_overlay ignores _app and _layout",
fn: async () => { async () => {
const root = path.join(import.meta.dirname!, "..", ".."); const root = path.join(import.meta.dirname!, "..", "..");
await using _tmp = await withTmpDir({ dir: root, prefix: "tmp_builder_" }); await using _tmp = await withTmpDir({
dir: root,
prefix: "tmp_builder_",
});
const tmp = _tmp.dir; const tmp = _tmp.dir;
const appLayoutSpy = fn(() => "app or layout") as () => string; const appLayoutSpy = fn(() => "app or layout") as () => string;
@@ -609,16 +550,14 @@ Deno.test({
}, },
}); });
}, },
sanitizeOps: false, );
sanitizeResources: false,
});
Deno.test({ integrationTest({
// Currently waiting on bug fixes in @deno/loader // Currently waiting on bug fixes in @deno/loader
// to support resolving without passing entry points // to support resolving without passing entry points
ignore: true, ignore: true,
name: "Builder - mapped islands", name: "Builder - mapped islands",
fn: async () => { }, async () => {
const root = path.join(import.meta.dirname!, "..", ".."); const root = path.join(import.meta.dirname!, "..", "..");
await using _tmp = await withTmpDir({ dir: root, prefix: "tmp_builder_" }); await using _tmp = await withTmpDir({ dir: root, prefix: "tmp_builder_" });
const tmp = _tmp.dir; const tmp = _tmp.dir;
@@ -653,14 +592,9 @@ export const app = new App().fsRoutes()`,
); );
expect(text).toContain("<h1>ok</h1>"); expect(text).toContain("<h1>ok</h1>");
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest("Builder - source maps", async () => {
name: "Builder - source maps",
fn: async () => {
const root = path.join(import.meta.dirname!, "..", ".."); const root = path.join(import.meta.dirname!, "..", "..");
await using _tmp = await withTmpDir({ dir: root, prefix: "tmp_builder_" }); await using _tmp = await withTmpDir({ dir: root, prefix: "tmp_builder_" });
const tmp = _tmp.dir; const tmp = _tmp.dir;
@@ -710,14 +644,9 @@ export const app = new App().fsRoutes()`,
expect(json.sourcesContent.length).toBeGreaterThan(0); expect(json.sourcesContent.length).toBeGreaterThan(0);
expect(json.sourcesContent.length).toBeGreaterThan(0); expect(json.sourcesContent.length).toBeGreaterThan(0);
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest("Builder - compile entry", async () => {
name: "Builder - compile entry",
fn: async () => {
const root = path.join(import.meta.dirname!, "..", ".."); const root = path.join(import.meta.dirname!, "..", "..");
await using _tmp = await withTmpDir({ dir: root, prefix: "tmp_builder_" }); await using _tmp = await withTmpDir({ dir: root, prefix: "tmp_builder_" });
await using _outDir = await withTmpDir(); await using _outDir = await withTmpDir();
@@ -789,14 +718,9 @@ export const app = new App()
res = await fetch(`${address}/foo.txt`); res = await fetch(`${address}/foo.txt`);
expect(await res.text()).toEqual("ok"); expect(await res.text()).toEqual("ok");
}); });
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest("Builder - island that imports json entry", async () => {
name: "Builder - island that imports json entry",
fn: async () => {
const root = path.join(import.meta.dirname!, "..", ".."); const root = path.join(import.meta.dirname!, "..", "..");
await using _tmp = await withTmpDir({ dir: root, prefix: "tmp_builder_" }); await using _tmp = await withTmpDir({ dir: root, prefix: "tmp_builder_" });
await using _outDir = await withTmpDir(); await using _outDir = await withTmpDir();
@@ -833,9 +757,6 @@ export const app = new App()
root: tmp, root: tmp,
}); });
await builder.build(); await builder.build();
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test("specToName", () => { Deno.test("specToName", () => {
@@ -885,11 +806,14 @@ Deno.test("specToName", () => {
expect(specToName("/islands/1_hello.tsx")).toEqual("_hello"); expect(specToName("/islands/1_hello.tsx")).toEqual("_hello");
}); });
Deno.test({ integrationTest(
name: "Builder - island named after global object (Map)", "Builder - island named after global object (Map)",
fn: async () => { async () => {
const root = path.join(import.meta.dirname!, "..", ".."); const root = path.join(import.meta.dirname!, "..", "..");
await using _tmp = await withTmpDir({ dir: root, prefix: "tmp_builder_" }); await using _tmp = await withTmpDir({
dir: root,
prefix: "tmp_builder_",
});
const tmp = _tmp.dir; const tmp = _tmp.dir;
await writeFiles(tmp, { await writeFiles(tmp, {
@@ -948,6 +872,4 @@ export const app = new App().fsRoutes();`,
}, },
); );
}, },
sanitizeOps: false, );
sanitizeResources: false,
});
+20
View File
@@ -182,6 +182,26 @@ export class MockBuildCache<State> implements BuildCache<State> {
} }
} }
/**
* Wrapper around `Deno.test` for integration tests that disables sanitizers.
* Accepts either a name string or an options object (without `fn`), plus the
* test function.
*/
export function integrationTest(
nameOrOptions: string | Omit<Deno.TestDefinition, "fn">,
fn: () => void | Promise<void>,
): void {
const options = typeof nameOrOptions === "string"
? { name: nameOrOptions }
: nameOrOptions;
Deno.test({
...options,
fn,
sanitizeOps: false,
sanitizeResources: false,
});
}
export async function writeFiles(dir: string, files: Record<string, string>) { export async function writeFiles(dir: string, files: Record<string, string>) {
const entries = Object.entries(files); const entries = Object.entries(files);
await Promise.all(entries.map(async (entry) => { await Promise.all(entries.map(async (entry) => {
+9 -49
View File
@@ -8,7 +8,7 @@ import {
withBrowserApp, withBrowserApp,
} from "./test_utils.tsx"; } from "./test_utils.tsx";
import { expect } from "@std/expect"; import { expect } from "@std/expect";
import { FakeServer } from "../src/test_utils.ts"; import { FakeServer, integrationTest } from "../src/test_utils.ts";
import * as path from "@std/path"; import * as path from "@std/path";
const applyHeadCache = await buildProd({ const applyHeadCache = await buildProd({
@@ -187,9 +187,7 @@ Deno.test("Head - ssr - updates link", async () => {
expect(link.href).toEqual("https://example.com/ok"); expect(link.href).toEqual("https://example.com/ok");
}); });
Deno.test({ integrationTest("Head - client - set title", async () => {
name: "Head - client - set title",
fn: async () => {
const app = new App({}) const app = new App({})
.use(staticFiles()) .use(staticFiles())
.fsRoutes(); .fsRoutes();
@@ -204,14 +202,9 @@ Deno.test({
await waitForText(page, "title", "Count: 1"); await waitForText(page, "title", "Count: 1");
}); });
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest("Head - client - match meta", async () => {
name: "Head - client - match meta",
fn: async () => {
const app = new App({}) const app = new App({})
.use(staticFiles()) .use(staticFiles())
.fsRoutes(); .fsRoutes();
@@ -240,14 +233,9 @@ Deno.test({
return true; return true;
}); });
}); });
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest("Head - client - match style by id", async () => {
name: "Head - client - match style by id",
fn: async () => {
const app = new App({}) const app = new App({})
.use(staticFiles()) .use(staticFiles())
.fsRoutes(); .fsRoutes();
@@ -276,14 +264,9 @@ Deno.test({
return true; return true;
}); });
}); });
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest("Head - client - match key", async () => {
name: "Head - client - match key",
fn: async () => {
const app = new App({}) const app = new App({})
.use(staticFiles()) .use(staticFiles())
.fsRoutes(); .fsRoutes();
@@ -316,14 +299,9 @@ Deno.test({
return true; return true;
}); });
}); });
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest("Head - client - dynamic meta update", async () => {
name: "Head - client - dynamic meta update",
fn: async () => {
const app = new App({}) const app = new App({})
.use(staticFiles()) .use(staticFiles())
.fsRoutes(); .fsRoutes();
@@ -360,14 +338,9 @@ Deno.test({
return true; return true;
}); });
}); });
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest("Head - client - link element", async () => {
name: "Head - client - link element",
fn: async () => {
const app = new App({}) const app = new App({})
.use(staticFiles()) .use(staticFiles())
.fsRoutes(); .fsRoutes();
@@ -389,14 +362,9 @@ Deno.test({
return true; return true;
}); });
}); });
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest("Head - client - multiple islands with Head", async () => {
name: "Head - client - multiple islands with Head",
fn: async () => {
const app = new App({}) const app = new App({})
.use(staticFiles()) .use(staticFiles())
.fsRoutes(); .fsRoutes();
@@ -430,14 +398,9 @@ Deno.test({
return true; return true;
}); });
}); });
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest("Head - client - title updates multiple times", async () => {
name: "Head - client - title updates multiple times",
fn: async () => {
const app = new App({}) const app = new App({})
.use(staticFiles()) .use(staticFiles())
.fsRoutes(); .fsRoutes();
@@ -457,7 +420,4 @@ Deno.test({
await page.locator("button").click(); await page.locator("button").click();
await waitForText(page, "title", "Count: 3"); await waitForText(page, "title", "Count: 3");
}); });
},
sanitizeOps: false,
sanitizeResources: false,
}); });
+61 -181
View File
@@ -8,6 +8,7 @@ import {
buildVite, buildVite,
DEMO_DIR, DEMO_DIR,
FIXTURE_DIR, FIXTURE_DIR,
integrationTest,
launchProd, launchProd,
usingEnv, usingEnv,
} from "./test_utils.ts"; } from "./test_utils.ts";
@@ -15,9 +16,7 @@ import * as path from "@std/path";
const viteResult = await buildVite(DEMO_DIR); const viteResult = await buildVite(DEMO_DIR);
Deno.test({ integrationTest("vite build - launches", async () => {
name: "vite build - launches",
fn: async () => {
await launchProd( await launchProd(
{ cwd: viteResult.tmp }, { cwd: viteResult.tmp },
async (address) => { async (address) => {
@@ -26,27 +25,17 @@ Deno.test({
expect(text).toEqual("it works"); expect(text).toEqual("it works");
}, },
); );
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest("vite build - creates compiled entry", async () => {
name: "vite build - creates compiled entry",
fn: async () => {
const stat = await Deno.stat( const stat = await Deno.stat(
path.join(viteResult.tmp, "_fresh", "compiled-entry.js"), path.join(viteResult.tmp, "_fresh", "compiled-entry.js"),
); );
expect(stat.isFile).toEqual(true); expect(stat.isFile).toEqual(true);
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest("vite build - serves static files", async () => {
name: "vite build - serves static files",
fn: async () => {
await launchProd( await launchProd(
{ cwd: viteResult.tmp }, { cwd: viteResult.tmp },
async (address) => { async (address) => {
@@ -61,14 +50,9 @@ Deno.test({
expect(textWithSpace).toEqual("space it works"); expect(textWithSpace).toEqual("space it works");
}, },
); );
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest("vite build - loads islands", async () => {
name: "vite build - loads islands",
fn: async () => {
await launchProd( await launchProd(
{ cwd: viteResult.tmp }, { cwd: viteResult.tmp },
async (address) => { async (address) => {
@@ -84,14 +68,9 @@ Deno.test({
}); });
}, },
); );
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest("vite build - nested islands", async () => {
name: "vite build - nested islands",
fn: async () => {
await launchProd( await launchProd(
{ cwd: viteResult.tmp }, { cwd: viteResult.tmp },
async (address) => { async (address) => {
@@ -105,14 +84,9 @@ Deno.test({
}); });
}, },
); );
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest("vite build - without static/ dir", async () => {
name: "vite build - without static/ dir",
fn: async () => {
const fixture = path.join(FIXTURE_DIR, "no_static"); const fixture = path.join(FIXTURE_DIR, "no_static");
await using res = await buildVite(fixture); await using res = await buildVite(fixture);
@@ -124,14 +98,9 @@ Deno.test({
expect(text).toEqual("ok"); expect(text).toEqual("ok");
}, },
); );
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest("vite build - without islands/ dir", async () => {
name: "vite build - without islands/ dir",
fn: async () => {
const fixture = path.join(FIXTURE_DIR, "no_islands"); const fixture = path.join(FIXTURE_DIR, "no_islands");
await using res = await buildVite(fixture); await using res = await buildVite(fixture);
@@ -143,14 +112,9 @@ Deno.test({
expect(text).toContain("ok"); expect(text).toContain("ok");
}, },
); );
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest("vite build - without routes/ dir", async () => {
name: "vite build - without routes/ dir",
fn: async () => {
const fixture = path.join(FIXTURE_DIR, "no_routes"); const fixture = path.join(FIXTURE_DIR, "no_routes");
await using res = await buildVite(fixture); await using res = await buildVite(fixture);
@@ -162,14 +126,9 @@ Deno.test({
expect(text).toEqual("ok"); expect(text).toEqual("ok");
}, },
); );
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest("vite build - load json inside npm package", async () => {
name: "vite build - load json inside npm package",
fn: async () => {
await launchProd( await launchProd(
{ cwd: viteResult.tmp }, { cwd: viteResult.tmp },
async (address) => { async (address) => {
@@ -182,14 +141,9 @@ Deno.test({
}); });
}, },
); );
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest("vite build - fetch static assets", async () => {
name: "vite build - fetch static assets",
fn: async () => {
await launchProd( await launchProd(
{ cwd: viteResult.tmp }, { cwd: viteResult.tmp },
async (address) => { async (address) => {
@@ -210,14 +164,9 @@ Deno.test({
}); });
}, },
); );
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest("vite build - tailwind no _app", async () => {
name: "vite build - tailwind no _app",
fn: async () => {
const fixture = path.join(FIXTURE_DIR, "tailwind_no_app"); const fixture = path.join(FIXTURE_DIR, "tailwind_no_app");
await using res = await buildVite(fixture); await using res = await buildVite(fixture);
@@ -240,14 +189,9 @@ Deno.test({
}); });
}, },
); );
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest("vite build - tailwind _app", async () => {
name: "vite build - tailwind _app",
fn: async () => {
const fixture = path.join(FIXTURE_DIR, "tailwind_app"); const fixture = path.join(FIXTURE_DIR, "tailwind_app");
await using res = await buildVite(fixture); await using res = await buildVite(fixture);
@@ -270,14 +214,9 @@ Deno.test({
}); });
}, },
); );
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest("vite build - partial island", async () => {
name: "vite build - partial island",
fn: async () => {
await launchProd( await launchProd(
{ cwd: viteResult.tmp }, { cwd: viteResult.tmp },
async (address) => { async (address) => {
@@ -295,14 +234,11 @@ Deno.test({
}); });
}, },
); );
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest(
name: "vite build - build ID uses env variables when set", "vite build - build ID uses env variables when set",
fn: async () => { async () => {
const revision = "test-commit-hash-123"; const revision = "test-commit-hash-123";
// We're running on GitHub Actions, so GITHUB_SHA will always // We're running on GitHub Actions, so GITHUB_SHA will always
@@ -335,13 +271,11 @@ Deno.test({
); );
} }
}, },
sanitizeOps: false, );
sanitizeResources: false,
});
Deno.test({ integrationTest(
name: "vite build - import json from jsr dependency", "vite build - import json from jsr dependency",
fn: async () => { async () => {
await launchProd( await launchProd(
{ cwd: viteResult.tmp }, { cwd: viteResult.tmp },
async (address) => { async (address) => {
@@ -351,13 +285,9 @@ Deno.test({
}, },
); );
}, },
sanitizeOps: false, );
sanitizeResources: false,
});
Deno.test({ integrationTest("vite build - import node:*", async () => {
name: "vite build - import node:*",
fn: async () => {
await launchProd( await launchProd(
{ cwd: viteResult.tmp }, { cwd: viteResult.tmp },
async (address) => { async (address) => {
@@ -366,14 +296,9 @@ Deno.test({
expect(res.status).toEqual(200); expect(res.status).toEqual(200);
}, },
); );
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest("vite build - css modules", async () => {
name: "vite build - css modules",
fn: async () => {
await launchProd( await launchProd(
{ cwd: viteResult.tmp }, { cwd: viteResult.tmp },
async (address) => { async (address) => {
@@ -409,14 +334,9 @@ Deno.test({
}); });
}, },
); );
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest("vite build - route css import", async () => {
name: "vite build - route css import",
fn: async () => {
await launchProd( await launchProd(
{ cwd: viteResult.tmp }, { cwd: viteResult.tmp },
async (address) => { async (address) => {
@@ -436,14 +356,9 @@ Deno.test({
}); });
}, },
); );
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest("vite build - remote island", async () => {
name: "vite build - remote island",
fn: async () => {
const fixture = path.join(FIXTURE_DIR, "remote_island"); const fixture = path.join(FIXTURE_DIR, "remote_island");
await using res = await buildVite(fixture); await using res = await buildVite(fixture);
@@ -461,27 +376,20 @@ Deno.test({
}); });
}, },
); );
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest(
name: "vite build - error on 'node:process' import", "vite build - error on 'node:process' import",
fn: async () => { async () => {
const fixture = path.join(FIXTURE_DIR, "node_builtin"); const fixture = path.join(FIXTURE_DIR, "node_builtin");
await expect(buildVite(fixture)).rejects.toThrow( await expect(buildVite(fixture)).rejects.toThrow(
"Node built-in modules cannot be imported in the browser", "Node built-in modules cannot be imported in the browser",
); );
}, },
sanitizeOps: false, );
sanitizeResources: false,
});
Deno.test({ integrationTest("vite build - static index.html", async () => {
name: "vite build - static index.html",
fn: async () => {
await launchProd( await launchProd(
{ cwd: viteResult.tmp }, { cwd: viteResult.tmp },
async (address) => { async (address) => {
@@ -494,14 +402,9 @@ Deno.test({
expect(textWithSpace).toContain("<h1>ok</h1>"); expect(textWithSpace).toContain("<h1>ok</h1>");
}, },
); );
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest("vite build - base path asset handling", async () => {
name: "vite build - base path asset handling",
fn: async () => {
await using res = await buildVite(DEMO_DIR, { base: "/my-app/" }); await using res = await buildVite(DEMO_DIR, { base: "/my-app/" });
// Read the generated server.js to check asset paths // Read the generated server.js to check asset paths
@@ -511,14 +414,11 @@ Deno.test({
// Asset paths should include the base path /my-app/ // Asset paths should include the base path /my-app/
expect(serverJs).toContain('"/my-app/assets/'); expect(serverJs).toContain('"/my-app/assets/');
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest(
name: "vite build - custom rollup entryFileNames in server.js", "vite build - custom rollup entryFileNames in server.js",
fn: async () => { async () => {
await using res = await buildVite(DEMO_DIR, { await using res = await buildVite(DEMO_DIR, {
rollupOutput: { rollupOutput: {
entryFileNames: "[hash].mjs", entryFileNames: "[hash].mjs",
@@ -537,13 +437,9 @@ Deno.test({
/from "\.\/server\/[a-zA-Z0-9_-]+\.mjs"/, /from "\.\/server\/[a-zA-Z0-9_-]+\.mjs"/,
); );
}, },
sanitizeOps: false, );
sanitizeResources: false,
});
Deno.test({ integrationTest("vite build - env files", async () => {
name: "vite build - env files",
fn: async () => {
await launchProd( await launchProd(
{ cwd: viteResult.tmp }, { cwd: viteResult.tmp },
async (address) => { async (address) => {
@@ -557,14 +453,9 @@ Deno.test({
}); });
}, },
); );
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest("vite build - support _middleware Array", async () => {
name: "vite build - support _middleware Array",
fn: async () => {
await launchProd( await launchProd(
{ cwd: viteResult.tmp }, { cwd: viteResult.tmp },
async (address) => { async (address) => {
@@ -573,14 +464,11 @@ Deno.test({
expect(text).toEqual("AB"); expect(text).toEqual("AB");
}, },
); );
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest(
name: "vite build - island named after global object (Map)", "vite build - island named after global object (Map)",
fn: async () => { async () => {
const fixture = path.join(FIXTURE_DIR, "island_global_name"); const fixture = path.join(FIXTURE_DIR, "island_global_name");
await using res = await buildVite(fixture); await using res = await buildVite(fixture);
@@ -598,18 +486,21 @@ Deno.test({
}, },
); );
}, },
sanitizeOps: false, );
sanitizeResources: false,
});
Deno.test({ integrationTest(
name: "vite build - excludes test files from routes", "vite build - excludes test files from routes",
fn: async () => { async () => {
const fixture = path.join(FIXTURE_DIR, "test_files_exclusion"); const fixture = path.join(FIXTURE_DIR, "test_files_exclusion");
await using res = await buildVite(fixture); await using res = await buildVite(fixture);
// Verify that test files in routes/ are not bundled // Verify that test files in routes/ are not bundled
const serverAssetsDir = path.join(res.tmp, "_fresh", "server", "assets"); const serverAssetsDir = path.join(
res.tmp,
"_fresh",
"server",
"assets",
);
// List all compiled route files // List all compiled route files
const files: string[] = []; const files: string[] = [];
@@ -633,13 +524,9 @@ Deno.test({
} }
} }
}, },
sanitizeOps: false, );
sanitizeResources: false,
});
Deno.test({ integrationTest("vite build - client side <Head>", async () => {
name: "vite build - client side <Head>",
fn: async () => {
await launchProd( await launchProd(
{ cwd: viteResult.tmp }, { cwd: viteResult.tmp },
async (address) => { async (address) => {
@@ -660,14 +547,11 @@ Deno.test({
}); });
}, },
); );
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest(
name: "vite build - vite-plugin-pwa generates service worker", "vite build - vite-plugin-pwa generates service worker",
fn: async () => { async () => {
const fixture = path.join(FIXTURE_DIR, "vite_plugin_pwa"); const fixture = path.join(FIXTURE_DIR, "vite_plugin_pwa");
await using res = await buildVite(fixture); await using res = await buildVite(fixture);
@@ -687,13 +571,11 @@ Deno.test({
const manifestStat = await Deno.stat(manifestPath); const manifestStat = await Deno.stat(manifestPath);
expect(manifestStat.isFile).toEqual(true); expect(manifestStat.isFile).toEqual(true);
}, },
sanitizeOps: false, );
sanitizeResources: false,
});
Deno.test({ integrationTest(
name: "vite build - vite-plugin-pwa files are accessible via HTTP", "vite build - vite-plugin-pwa files are accessible via HTTP",
fn: async () => { async () => {
const fixture = path.join(FIXTURE_DIR, "vite_plugin_pwa"); const fixture = path.join(FIXTURE_DIR, "vite_plugin_pwa");
await using res = await buildVite(fixture); await using res = await buildVite(fixture);
@@ -723,6 +605,4 @@ Deno.test({
}, },
); );
}, },
sanitizeOps: false, );
sanitizeResources: false,
});
+45 -216
View File
@@ -8,6 +8,7 @@ import {
import { import {
DEMO_DIR, DEMO_DIR,
FIXTURE_DIR, FIXTURE_DIR,
integrationTest,
launchDevServer, launchDevServer,
prepareDevServer, prepareDevServer,
spawnDevServer, spawnDevServer,
@@ -20,20 +21,13 @@ const demoServer = await spawnDevServer(tmp.dir, {
FRESH_PUBLIC_FOO: "foobar", FRESH_PUBLIC_FOO: "foobar",
}); });
Deno.test({ integrationTest("vite dev - launches", async () => {
name: "vite dev - launches",
fn: async () => {
const res = await fetch(`${demoServer.address()}/tests/it_works`); const res = await fetch(`${demoServer.address()}/tests/it_works`);
const text = await res.text(); const text = await res.text();
expect(text).toContain("it works"); expect(text).toContain("it works");
},
sanitizeResources: false,
sanitizeOps: false,
}); });
Deno.test({ integrationTest("vite dev - serves static files", async () => {
name: "vite dev - serves static files",
fn: async () => {
const res = await fetch(`${demoServer.address()}/test_static/foo.txt`); const res = await fetch(`${demoServer.address()}/test_static/foo.txt`);
const text = await res.text(); const text = await res.text();
expect(text).toContain("it works"); expect(text).toContain("it works");
@@ -43,14 +37,9 @@ Deno.test({
); );
const textWithSpace = await resWithSpace.text(); const textWithSpace = await resWithSpace.text();
expect(textWithSpace).toContain("space it works"); expect(textWithSpace).toContain("space it works");
},
sanitizeResources: false,
sanitizeOps: false,
}); });
Deno.test({ integrationTest("vite dev - loads islands", async () => {
name: "vite dev - loads islands",
fn: async () => {
await withBrowser(async (page) => { await withBrowser(async (page) => {
await page.goto(`${demoServer.address()}/tests/island_hooks`, { await page.goto(`${demoServer.address()}/tests/island_hooks`, {
waitUntil: "networkidle2", waitUntil: "networkidle2",
@@ -60,57 +49,39 @@ Deno.test({
await page.locator("button").click(); await page.locator("button").click();
await waitForText(page, "button", "count: 1"); await waitForText(page, "button", "count: 1");
}); });
},
sanitizeResources: false,
sanitizeOps: false,
}); });
Deno.test({ integrationTest("vite dev - starts without static/ dir", async () => {
name: "vite dev - starts without static/ dir",
fn: async () => {
const fixture = path.join(FIXTURE_DIR, "no_static"); const fixture = path.join(FIXTURE_DIR, "no_static");
await withDevServer(fixture, async (address) => { await withDevServer(fixture, async (address) => {
const res = await fetch(`${address}/`); const res = await fetch(`${address}/`);
const text = await res.text(); const text = await res.text();
expect(text).toContain("ok"); expect(text).toContain("ok");
}); });
},
sanitizeResources: false,
sanitizeOps: false,
}); });
Deno.test({ integrationTest("vite dev - starts without islands/ dir", async () => {
name: "vite dev - starts without islands/ dir",
fn: async () => {
const fixture = path.join(FIXTURE_DIR, "no_islands"); const fixture = path.join(FIXTURE_DIR, "no_islands");
await withDevServer(fixture, async (address) => { await withDevServer(fixture, async (address) => {
const res = await fetch(`${address}/`); const res = await fetch(`${address}/`);
const text = await res.text(); const text = await res.text();
expect(text).toContain("ok"); expect(text).toContain("ok");
}); });
},
sanitizeResources: false,
sanitizeOps: false,
}); });
Deno.test({ integrationTest("vite dev - starts without routes/ dir", async () => {
name: "vite dev - starts without routes/ dir",
fn: async () => {
const fixture = path.join(FIXTURE_DIR, "no_routes"); const fixture = path.join(FIXTURE_DIR, "no_routes");
await withDevServer(fixture, async (address) => { await withDevServer(fixture, async (address) => {
const res = await fetch(`${address}/`); const res = await fetch(`${address}/`);
const text = await res.text(); const text = await res.text();
expect(text).toContain("ok"); expect(text).toContain("ok");
}); });
},
sanitizeResources: false,
sanitizeOps: false,
}); });
Deno.test({ integrationTest({
name: "vite dev - can apply HMR to islands (hooks)", name: "vite dev - can apply HMR to islands (hooks)",
ignore: true, // Test is very flaky ignore: true, // Test is very flaky
fn: async () => { }, async () => {
await withBrowser(async (page) => { await withBrowser(async (page) => {
await page.goto(`${demoServer.address()}/tests/island_hooks`, { await page.goto(`${demoServer.address()}/tests/island_hooks`, {
waitUntil: "networkidle2", waitUntil: "networkidle2",
@@ -134,28 +105,18 @@ Deno.test({
await page.locator("button").click(); await page.locator("button").click();
await waitForText(page, "button", "hmr: 2"); await waitForText(page, "button", "hmr: 2");
}); });
},
sanitizeResources: false,
sanitizeOps: false,
}); });
Deno.test({ integrationTest("vite dev - can import json in npm package", async () => {
name: "vite dev - can import json in npm package",
fn: async () => {
await withBrowser(async (page) => { await withBrowser(async (page) => {
await page.goto(`${demoServer.address()}/tests/mime`, { await page.goto(`${demoServer.address()}/tests/mime`, {
waitUntil: "networkidle2", waitUntil: "networkidle2",
}); });
await page.locator(".ready").wait(); await page.locator(".ready").wait();
}); });
},
sanitizeResources: false,
sanitizeOps: false,
}); });
Deno.test({ integrationTest("vite dev - inline env vars", async () => {
name: "vite dev - inline env vars",
fn: async () => {
await withBrowser(async (page) => { await withBrowser(async (page) => {
await page.goto(`${demoServer.address()}/tests/env`, { await page.goto(`${demoServer.address()}/tests/env`, {
waitUntil: "networkidle2", waitUntil: "networkidle2",
@@ -169,14 +130,9 @@ Deno.test({
expect(JSON.parse(res)).toEqual({ deno: "foobar", nodeEnv: "foobar" }); expect(JSON.parse(res)).toEqual({ deno: "foobar", nodeEnv: "foobar" });
}); });
},
sanitizeResources: false,
sanitizeOps: false,
}); });
Deno.test({ integrationTest("vite dev - serves imported assets", async () => {
name: "vite dev - serves imported assets",
fn: async () => {
// Vite has an internal allowlist that is refreshed when // Vite has an internal allowlist that is refreshed when
// pathnames are requested. It will discover valid static // pathnames are requested. It will discover valid static
// files imported in JS once it encounters them. Therefore // files imported in JS once it encounters them. Therefore
@@ -188,14 +144,9 @@ Deno.test({
res = await fetch(`${demoServer.address()}/assets/deno-logo.png`); res = await fetch(`${demoServer.address()}/assets/deno-logo.png`);
expect(res.status).toEqual(200); expect(res.status).toEqual(200);
expect(res.headers.get("Content-Type")).toEqual("image/png"); expect(res.headers.get("Content-Type")).toEqual("image/png");
},
sanitizeResources: false,
sanitizeOps: false,
}); });
Deno.test({ integrationTest("vite dev - tailwind no _app", async () => {
name: "vite dev - tailwind no _app",
fn: async () => {
const fixture = path.join(FIXTURE_DIR, "tailwind_no_app"); const fixture = path.join(FIXTURE_DIR, "tailwind_no_app");
await withDevServer(fixture, async (address) => { await withDevServer(fixture, async (address) => {
await withBrowser(async (page) => { await withBrowser(async (page) => {
@@ -203,20 +154,12 @@ Deno.test({
waitUntil: "networkidle2", waitUntil: "networkidle2",
}); });
// Vite 6: data-vite-dev-id; Vite 7+: vite-module-id on injected style. await page.locator("style[vite-module-id]").wait();
await page.locator(
"style[data-vite-dev-id$='style.css'], style[vite-module-id]",
).wait();
}); });
}); });
},
sanitizeResources: false,
sanitizeOps: false,
}); });
Deno.test({ integrationTest("vite dev - tailwind _app", async () => {
name: "vite dev - tailwind _app",
fn: async () => {
const fixture = path.join(FIXTURE_DIR, "tailwind_app"); const fixture = path.join(FIXTURE_DIR, "tailwind_app");
await withDevServer(fixture, async (address) => { await withDevServer(fixture, async (address) => {
await withBrowser(async (page) => { await withBrowser(async (page) => {
@@ -224,19 +167,12 @@ Deno.test({
waitUntil: "networkidle2", waitUntil: "networkidle2",
}); });
await page.locator( await page.locator("style[vite-module-id]").wait();
"style[data-vite-dev-id$='style.css'], style[vite-module-id]",
).wait();
}); });
}); });
},
sanitizeResources: false,
sanitizeOps: false,
}); });
Deno.test({ integrationTest("vite dev - partial island", async () => {
name: "vite dev - partial island",
fn: async () => {
await withBrowser(async (page) => { await withBrowser(async (page) => {
await page.goto(`${demoServer.address()}/tests/partial`, { await page.goto(`${demoServer.address()}/tests/partial`, {
waitUntil: "networkidle2", waitUntil: "networkidle2",
@@ -249,36 +185,21 @@ Deno.test({
await page.locator(".counter-hooks button").click(); await page.locator(".counter-hooks button").click();
await waitForText(page, ".counter-hooks button", "count: 1"); await waitForText(page, ".counter-hooks button", "count: 1");
}); });
},
sanitizeResources: false,
sanitizeOps: false,
}); });
Deno.test({ integrationTest("vite dev - json from jsr dependency", async () => {
name: "vite dev - json from jsr dependency",
fn: async () => {
const res = await fetch(`${demoServer.address()}/tests/dep_json`); const res = await fetch(`${demoServer.address()}/tests/dep_json`);
const json = await res.json(); const json = await res.json();
expect(json.name).toEqual("@marvinh-test/import-json"); expect(json.name).toEqual("@marvinh-test/import-json");
},
sanitizeResources: false,
sanitizeOps: false,
}); });
Deno.test({ integrationTest("vite dev - import node:*", async () => {
name: "vite dev - import node:*",
fn: async () => {
const res = await fetch(`${demoServer.address()}/tests/feed`); const res = await fetch(`${demoServer.address()}/tests/feed`);
await res.body?.cancel(); await res.body?.cancel();
expect(res.status).toEqual(200); expect(res.status).toEqual(200);
},
sanitizeResources: false,
sanitizeOps: false,
}); });
Deno.test({ integrationTest("vite dev - css modules", async () => {
name: "vite dev - css modules",
fn: async () => {
await withBrowser(async (page) => { await withBrowser(async (page) => {
await page.goto(`${demoServer.address()}/tests/css_modules`, { await page.goto(`${demoServer.address()}/tests/css_modules`, {
waitUntil: "networkidle2", waitUntil: "networkidle2",
@@ -312,14 +233,9 @@ Deno.test({
return true; return true;
}); });
}); });
},
sanitizeResources: false,
sanitizeOps: false,
}); });
Deno.test({ integrationTest("vite dev - route css import", async () => {
name: "vite dev - route css import",
fn: async () => {
await withBrowser(async (page) => { await withBrowser(async (page) => {
await page.goto(`${demoServer.address()}/tests/css`, { await page.goto(`${demoServer.address()}/tests/css`, {
waitUntil: "networkidle2", waitUntil: "networkidle2",
@@ -334,14 +250,9 @@ Deno.test({
return true; return true;
}); });
}); });
},
sanitizeResources: false,
sanitizeOps: false,
}); });
Deno.test({ integrationTest("vite dev - nested islands", async () => {
name: "vite dev - nested islands",
fn: async () => {
await withBrowser(async (page) => { await withBrowser(async (page) => {
await page.goto(`${demoServer.address()}/tests/island_nested`, { await page.goto(`${demoServer.address()}/tests/island_nested`, {
waitUntil: "networkidle2", waitUntil: "networkidle2",
@@ -350,14 +261,9 @@ Deno.test({
await page.locator(".outer-ready").wait(); await page.locator(".outer-ready").wait();
await page.locator(".inner-ready").wait(); await page.locator(".inner-ready").wait();
}); });
},
sanitizeResources: false,
sanitizeOps: false,
}); });
Deno.test({ integrationTest("vite dev - remote island", async () => {
name: "vite dev - remote island",
fn: async () => {
const fixture = path.join(FIXTURE_DIR, "remote_island"); const fixture = path.join(FIXTURE_DIR, "remote_island");
await launchDevServer(fixture, async (address) => { await launchDevServer(fixture, async (address) => {
await withBrowser(async (page) => { await withBrowser(async (page) => {
@@ -370,14 +276,9 @@ Deno.test({
await waitForText(page, ".result", "Count: 1"); await waitForText(page, ".result", "Count: 1");
}); });
}); });
},
sanitizeResources: false,
sanitizeOps: false,
}); });
Deno.test({ integrationTest("vite dev - error on 'node:process' import", async () => {
name: "vite dev - error on 'node:process' import",
fn: async () => {
const fixture = path.join(FIXTURE_DIR, "node_builtin"); const fixture = path.join(FIXTURE_DIR, "node_builtin");
await launchDevServer(fixture, async (address) => { await launchDevServer(fixture, async (address) => {
@@ -389,106 +290,64 @@ Deno.test({
expect(res.status).toEqual(500); expect(res.status).toEqual(500);
}); });
},
sanitizeOps: false,
sanitizeResources: false,
}); });
// issue: https://github.com/denoland/fresh/issues/3322 // issue: https://github.com/denoland/fresh/issues/3322
Deno.test({ integrationTest(
name: "vite dev - allow routes looking like static paths", "vite dev - allow routes looking like static paths",
fn: async () => { async () => {
const res = await fetch( const res = await fetch(
`${demoServer.address()}/tests/api/@marvinh@infosec.exchange`, `${demoServer.address()}/tests/api/@marvinh@infosec.exchange`,
); );
const text = await res.text(); const text = await res.text();
expect(text).toEqual("ok"); expect(text).toEqual("ok");
}, },
sanitizeOps: false, );
sanitizeResources: false,
});
// issue: https://github.com/denoland/fresh/issues/3323 // issue: https://github.com/denoland/fresh/issues/3323
Deno.test({ integrationTest("vite dev - npm:pg", async () => {
name: "vite dev - npm:pg",
fn: async () => {
const res = await fetch(`${demoServer.address()}/tests/pg`); const res = await fetch(`${demoServer.address()}/tests/pg`);
const text = await res.text(); const text = await res.text();
expect(text).toContain("<h1>pg</h1>"); expect(text).toContain("<h1>pg</h1>");
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest("vite dev - npm:ioredis", async () => {
name: "vite dev - npm:ioredis",
fn: async () => {
const res = await fetch(`${demoServer.address()}/tests/ioredis`); const res = await fetch(`${demoServer.address()}/tests/ioredis`);
const text = await res.text(); const text = await res.text();
expect(text).toContain("<h1>ioredis</h1>"); expect(text).toContain("<h1>ioredis</h1>");
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest("vite dev - redis", async () => {
name: "vite dev - redis",
fn: async () => {
const res = await fetch(`${demoServer.address()}/tests/redis`); const res = await fetch(`${demoServer.address()}/tests/redis`);
const text = await res.text(); const text = await res.text();
expect(text).toContain("<h1>redis</h1>"); expect(text).toContain("<h1>redis</h1>");
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest("vite dev - @supabase/postgres-js", async () => {
name: "vite dev - @supabase/postgres-js",
fn: async () => {
const res = await fetch(`${demoServer.address()}/tests/supabase_pg`); const res = await fetch(`${demoServer.address()}/tests/supabase_pg`);
const text = await res.text(); const text = await res.text();
expect(text).toContain("<h1>supabase</h1>"); expect(text).toContain("<h1>supabase</h1>");
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest("vite dev - radix", async () => {
name: "vite dev - radix",
fn: async () => {
const res = await fetch(`${demoServer.address()}/tests/radix`); const res = await fetch(`${demoServer.address()}/tests/radix`);
const text = await res.text(); const text = await res.text();
expect(text).toContain("click me</button>"); expect(text).toContain("click me</button>");
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest("vite dev - qs", async () => {
name: "vite dev - qs",
fn: async () => {
const res = await fetch(`${demoServer.address()}/tests/qs`); const res = await fetch(`${demoServer.address()}/tests/qs`);
const text = await res.text(); const text = await res.text();
expect(text).toContain("<h1>qs</h1>"); expect(text).toContain("<h1>qs</h1>");
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest("vite dev - stripe", async () => {
name: "vite dev - stripe",
fn: async () => {
const res = await fetch(`${demoServer.address()}/tests/stripe`); const res = await fetch(`${demoServer.address()}/tests/stripe`);
const text = await res.text(); const text = await res.text();
expect(text).toContain("<h1>stripe</h1>"); expect(text).toContain("<h1>stripe</h1>");
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest("vite dev - static index.html", async () => {
name: "vite dev - static index.html",
fn: async () => {
const res = await fetch(`${demoServer.address()}/test_static/foo`); const res = await fetch(`${demoServer.address()}/test_static/foo`);
const text = await res.text(); const text = await res.text();
expect(text).toContain("<h1>ok</h1>"); expect(text).toContain("<h1>ok</h1>");
@@ -498,14 +357,9 @@ Deno.test({
); );
const textWithSpace = await resWithSpace.text(); const textWithSpace = await resWithSpace.text();
expect(textWithSpace).toContain("<h1>ok</h1>"); expect(textWithSpace).toContain("<h1>ok</h1>");
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest("vite dev - load .env files", async () => {
name: "vite dev - load .env files",
fn: async () => {
const res = await fetch(`${demoServer.address()}/tests/env_files`); const res = await fetch(`${demoServer.address()}/tests/env_files`);
const json = await res.json(); const json = await res.json();
expect(json).toEqual({ expect(json).toEqual({
@@ -514,37 +368,24 @@ Deno.test({
MY_LOCAL_ENV: "MY_LOCAL_ENV test value", MY_LOCAL_ENV: "MY_LOCAL_ENV test value",
VITE_MY_LOCAL_ENV: "VITE_MY_LOCAL_ENV test value", VITE_MY_LOCAL_ENV: "VITE_MY_LOCAL_ENV test value",
}); });
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest("vite dev - support _middleware Array", async () => {
name: "vite dev - support _middleware Array",
fn: async () => {
const res = await fetch(`${demoServer.address()}/tests/middlewares`); const res = await fetch(`${demoServer.address()}/tests/middlewares`);
const text = await res.text(); const text = await res.text();
expect(text).toEqual("AB"); expect(text).toEqual("AB");
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest("vite dev - support jsx namespace", async () => {
name: "vite dev - support jsx namespace",
fn: async () => {
const res = await fetch(`${demoServer.address()}/tests/jsx_namespace`); const res = await fetch(`${demoServer.address()}/tests/jsx_namespace`);
const text = await res.text(); const text = await res.text();
expect(text).toContain(`xml:space="preserve"`); expect(text).toContain(`xml:space="preserve"`);
},
sanitizeOps: false,
sanitizeResources: false,
}); });
// issue: https://github.com/denoland/fresh/issues/3666 // issue: https://github.com/denoland/fresh/issues/3666
Deno.test({ integrationTest(
name: "vite dev - basePath does not intercept Vite URLs", "vite dev - basePath does not intercept Vite URLs",
fn: async () => { async () => {
const fixture = path.join(FIXTURE_DIR, "basepath"); const fixture = path.join(FIXTURE_DIR, "basepath");
await launchDevServer(fixture, async (address) => { await launchDevServer(fixture, async (address) => {
// `address` already includes the base path (e.g. http://localhost:PORT/ui) // `address` already includes the base path (e.g. http://localhost:PORT/ui)
@@ -555,24 +396,15 @@ Deno.test({
expect(viteClientRes.status).toEqual(200); expect(viteClientRes.status).toEqual(200);
}); });
}, },
sanitizeOps: false, );
sanitizeResources: false,
});
Deno.test({ integrationTest("vite dev - source mapped stack traces", async () => {
name: "vite dev - source mapped stack traces",
fn: async () => {
const res = await fetch(`${demoServer.address()}/tests/throw`); const res = await fetch(`${demoServer.address()}/tests/throw`);
const text = await res.text(); const text = await res.text();
expect(text).toContain("throw.tsx:5:11"); expect(text).toContain("throw.tsx:5:11");
},
sanitizeOps: false,
sanitizeResources: false,
}); });
Deno.test({ integrationTest("vite dev - client side <Head>", async () => {
name: "vite dev - client side <Head>",
fn: async () => {
await withBrowser(async (page) => { await withBrowser(async (page) => {
await page.goto(`${demoServer.address()}/tests/head_counter`, { await page.goto(`${demoServer.address()}/tests/head_counter`, {
waitUntil: "networkidle2", waitUntil: "networkidle2",
@@ -609,7 +441,4 @@ Deno.test({
return true; return true;
}); });
}); });
},
sanitizeOps: false,
sanitizeResources: false,
}); });
+3 -1
View File
@@ -1,9 +1,11 @@
import { createBuilder } from "vite"; import { createBuilder } from "vite";
import * as path from "@std/path"; import * as path from "@std/path";
import { walk } from "@std/fs/walk"; import { walk } from "@std/fs/walk";
import { withTmpDir } from "../../fresh/src/test_utils.ts"; import { integrationTest, withTmpDir } from "../../fresh/src/test_utils.ts";
import { withChildProcessServer } from "../../fresh/tests/test_utils.tsx"; import { withChildProcessServer } from "../../fresh/tests/test_utils.tsx";
export { integrationTest };
export const DEMO_DIR = path.join(import.meta.dirname!, "..", "demo"); export const DEMO_DIR = path.join(import.meta.dirname!, "..", "demo");
export const FIXTURE_DIR = path.join(import.meta.dirname!, "fixtures"); export const FIXTURE_DIR = path.join(import.meta.dirname!, "fixtures");
+6 -12
View File
@@ -8,6 +8,7 @@ import {
buildVite, buildVite,
launchProd, launchProd,
} from "../packages/plugin-vite/tests/test_utils.ts"; } from "../packages/plugin-vite/tests/test_utils.ts";
import { integrationTest } from "../packages/fresh/src/test_utils.ts";
let result: Awaited<ReturnType<typeof buildVite>>; let result: Awaited<ReturnType<typeof buildVite>>;
@@ -19,24 +20,18 @@ Deno.test.afterAll(async () => {
await result?.[Symbol.asyncDispose](); await result?.[Symbol.asyncDispose]();
}); });
Deno.test({ integrationTest(
name: "CORS should not set on GET /fresh-badge.svg", "CORS should not set on GET /fresh-badge.svg",
sanitizeOps: false, async () => {
sanitizeResources: false,
fn: async () => {
await launchProd({ cwd: result.tmp }, async (address) => { await launchProd({ cwd: result.tmp }, async (address) => {
const resp = await fetch(`${address}/fresh-badge.svg`); const resp = await fetch(`${address}/fresh-badge.svg`);
await resp?.body?.cancel(); await resp?.body?.cancel();
expect(resp.headers.get("cross-origin-resource-policy")).toEqual(null); expect(resp.headers.get("cross-origin-resource-policy")).toEqual(null);
}); });
}, },
}); );
Deno.test({ integrationTest("shows version selector", async () => {
name: "shows version selector",
sanitizeOps: false,
sanitizeResources: false,
fn: async () => {
await retry(async () => { await retry(async () => {
await withChildProcessServer( await withChildProcessServer(
{ {
@@ -101,5 +96,4 @@ Deno.test({
}, },
); );
}); });
},
}); });