Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions packages/core/tests/dev/error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,26 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";

describe("dev error fixture", () => {
let fixture: ReturnType<typeof getFixture>;
let stop: () => Promise<void>;

beforeEach(() => {
fixture = getFixture("dev.basic");
stop = () => fixture.clean();
vi.spyOn(console, "error").mockImplementation(() => {});
});

afterEach(async () => {
vi.restoreAllMocks();
await fixture.clean();
await stop();
});

it("renders the Astro error overlay", async () => {
const { render } = await fixture.startDevServer({
const devServer = await fixture.startDevServer({
config: { logLevel: "silent" },
});
stop = devServer.stop;

const response = await render({
const response = await devServer.render({
component: "error",
partial: false,
});
Expand All @@ -30,15 +33,16 @@ describe("dev error fixture", () => {
});

it("throws an error when hmr.overlay is false", async () => {
const { render } = await fixture.startDevServer({
const devServer = await fixture.startDevServer({
config: {
logLevel: "silent",
vite: { server: { hmr: { overlay: false } } },
},
});
stop = devServer.stop;

await expect(
render({
devServer.render({
component: "error",
partial: false,
}),
Expand Down
19 changes: 11 additions & 8 deletions packages/core/tests/fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,20 @@ export function getFixture(fixtureName: string): {
`dist-${Math.random().toString(36).substring(2, 15)}`,
);

// Isolate Vite dep-optimization cache per Vitest run to prevent
// ENOTEMPTY race when multiple `pnpm test` processes run in parallel.
const viteCacheDir = path.join(
import.meta.dirname,
"..",
"node_modules",
`.vite-${process.ppid || process.pid}`,
);

const clean = async () => {
await rm(outDir, {
recursive: true,
force: true,
});
await rm(path.join(fixtureRoot, ".astro"), {
recursive: true,
force: true,
});
await rm(path.join(fixtureRoot, "node_modules"), {
recursive: true,
force: true,
});
};

const DEV_TEST_ADDRESS = "http://host-placeholder.test";
Expand All @@ -78,6 +79,7 @@ export function getFixture(fixtureName: string): {
{
root: fixtureRoot,
logLevel: "warn",
vite: { cacheDir: viteCacheDir },
},
params?.config ?? {},
),
Expand Down Expand Up @@ -115,6 +117,7 @@ export function getFixture(fixtureName: string): {
outDir,
logLevel: "warn",
vite: {
cacheDir: viteCacheDir,
build: {
rollupOptions: { external: ["@/context"] },
},
Expand Down
3 changes: 2 additions & 1 deletion packages/core/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default defineConfig({
"@/": `${path.resolve(import.meta.dirname, "src")}/`,
"@tests/": `${path.resolve(import.meta.dirname, "tests")}/`,
},
testTimeout: 30000,
testTimeout: 120000,
hookTimeout: 60000,
},
});
23 changes: 18 additions & 5 deletions packages/hono/tests/cli.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readFile } from "node:fs/promises";
import { mkdir, readFile, symlink } from "node:fs/promises";
import path from "node:path";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import { runCli } from "../src/cli/run";
Expand Down Expand Up @@ -30,12 +30,25 @@ describe("cli", () => {
});

it("builds the fixture when --root is provided before the command", async () => {
await expect(
runCli(["--root", fixture.fixtureRoot, "build"]),
).resolves.toBe(undefined);
// Use the unique outDir as a build root (with symlinks to fixture source)
// to avoid parallel build conflicts on the shared dist/ directory.
const buildRoot = fixture.outDir;
await mkdir(buildRoot, { recursive: true });
await symlink(
path.join(fixture.fixtureRoot, "astro.config.ts"),
path.join(buildRoot, "astro.config.ts"),
);
await symlink(
path.join(fixture.fixtureRoot, "src"),
path.join(buildRoot, "src"),
);

await expect(runCli(["--root", buildRoot, "build"])).resolves.toBe(
undefined,
);

const output = await readFile(
path.join(fixture.fixtureRoot, "dist", "client", "index.html"),
path.join(buildRoot, "dist", "client", "index.html"),
"utf-8",
);

Expand Down
28 changes: 15 additions & 13 deletions packages/hono/tests/fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,17 @@ export function getFixture(fixtureName: string): {
`dist-${Math.random().toString(36).substring(2, 15)}`,
);

// Isolate Vite dep-optimization cache per Vitest run to prevent
// ENOTEMPTY race when multiple `pnpm test` processes run in parallel.
const viteCacheDir = path.join(
import.meta.dirname,
"..",
"node_modules",
`.vite-${process.ppid || process.pid}`,
);

const clean = async (): Promise<void> => {
await rm(outDir, { recursive: true, force: true });
await rm(path.join(fixtureRoot, "dist"), {
recursive: true,
force: true,
});
await rm(path.join(fixtureRoot, ".astro"), {
recursive: true,
force: true,
});
await rm(path.join(fixtureRoot, "node_modules"), {
recursive: true,
force: true,
});
};

return {
Expand All @@ -69,6 +66,7 @@ export function getFixture(fixtureName: string): {
outDir,
logLevel: "warn",
vite: {
cacheDir: viteCacheDir,
build: {
rollupOptions: {
external: ["@gomighty/core/context"],
Expand All @@ -94,7 +92,11 @@ export function getFixture(fixtureName: string): {
const middleware = devMiddleware({
...params,
config: mergeConfig<AstroInlineConfig>(
{ root: fixtureRoot, logLevel: "warn" },
{
root: fixtureRoot,
logLevel: "warn",
vite: { cacheDir: viteCacheDir },
},
params?.config ?? {},
),
});
Expand Down
3 changes: 2 additions & 1 deletion packages/hono/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default defineConfig({
alias: {
"@/": `${path.resolve(import.meta.dirname, "src")}/`,
},
testTimeout: 30000,
testTimeout: 120000,
hookTimeout: 60000,
},
});
3 changes: 2 additions & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
projects: ["packages/*"],
testTimeout: 30000,
testTimeout: 120000,
hookTimeout: 60000,
},
});
Loading