fix: support optional static, routes and island dir in vite plugin (#3206)

This commit is contained in:
Marvin Hagemeister
2025-08-08 09:23:38 +02:00
committed by GitHub
parent 0664476e46
commit 22ebb2dbfa
12 changed files with 187 additions and 36 deletions
+52 -5
View File
@@ -1,12 +1,17 @@
import * as path from "@std/path";
import { expect } from "@std/expect";
import { waitForText, withBrowser } from "../../fresh/tests/test_utils.tsx";
import { updateFile, withDevServer } from "./test_utils.ts";
import {
DEMO_DIR,
FIXTURE_DIR,
updateFile,
withDevServer,
} from "./test_utils.ts";
Deno.test({
name: "vite dev - launches",
fn: async () => {
await withDevServer(async (address) => {
await withDevServer(DEMO_DIR, async (address) => {
const res = await fetch(`${address}/tests/it_works`);
const text = await res.text();
expect(text).toContain("it works");
@@ -19,7 +24,7 @@ Deno.test({
Deno.test({
name: "vite dev - serves static files",
fn: async () => {
await withDevServer(async (address) => {
await withDevServer(DEMO_DIR, async (address) => {
const res = await fetch(`${address}/test_static/foo.txt`);
const text = await res.text();
expect(text).toContain("it works");
@@ -32,7 +37,7 @@ Deno.test({
Deno.test({
name: "vite dev - loads islands",
fn: async () => {
await withDevServer(async (address) => {
await withDevServer(DEMO_DIR, async (address) => {
await withBrowser(async (page) => {
await page.goto(`${address}/tests/island_hooks`, {
waitUntil: "networkidle2",
@@ -48,11 +53,53 @@ Deno.test({
sanitizeOps: false,
});
Deno.test({
name: "vite dev - starts without static/ dir",
fn: async () => {
const fixture = path.join(FIXTURE_DIR, "no_static");
await withDevServer(fixture, async (address) => {
const res = await fetch(`${address}/`);
const text = await res.text();
expect(text).toContain("ok");
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
name: "vite dev - starts without islands/ dir",
fn: async () => {
const fixture = path.join(FIXTURE_DIR, "no_islands");
await withDevServer(fixture, async (address) => {
const res = await fetch(`${address}/`);
const text = await res.text();
expect(text).toContain("ok");
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
name: "vite dev - starts without routes/ dir",
fn: async () => {
const fixture = path.join(FIXTURE_DIR, "no_routes");
await withDevServer(fixture, async (address) => {
const res = await fetch(`${address}/`);
const text = await res.text();
expect(text).toContain("ok");
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
name: "vite dev - can apply HMR to islands (hooks)",
ignore: true, // Test is very flaky
fn: async () => {
await withDevServer(async (address, dir) => {
await withDevServer(DEMO_DIR, async (address, dir) => {
await withBrowser(async (page) => {
await page.goto(`${address}/tests/island_hooks`, {
waitUntil: "networkidle2",