Skip to content
Merged
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
18 changes: 15 additions & 3 deletions packages/core/tests/integration/client/concurrent-servers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
* its own copied fixture root) both succeed.
*/

import { existsSync, readdirSync } from "node:fs";
import { join } from "node:path";

import { describe, it, expect, afterAll } from "vitest";

import type { TestServerContext } from "../server.js";
Expand Down Expand Up @@ -45,8 +48,17 @@ describe("Concurrent dev servers (#1604)", () => {
// Start both concurrently so they race for the (previously shared) lock.
const [a, b] = await Promise.all([startTracked(PORT_A), startTracked(PORT_B)]);

// Distinct roots -- the fix gives each server its own copied fixture.
expect(a.cwd).not.toBe(b.cwd);
// Vite must write optimizer output into each server's private cache root,
// not follow the shared node_modules symlink to one physical cache.
for (const cwd of [a.cwd, b.cwd]) {
const cacheDir = join(cwd, ".vite-cache");
expect(existsSync(cacheDir), `${cacheDir} was never created`).toBe(true);
const output = readdirSync(cacheDir, { recursive: true, withFileTypes: true });
expect(
output.some((entry) => entry.isFile()),
`${cacheDir} contains no Vite cache output`,
).toBe(true);
}

// Both must actually serve their independently seeded content.
const [collectionsA, collectionsB] = await Promise.all([
Expand All @@ -58,5 +70,5 @@ describe("Concurrent dev servers (#1604)", () => {
expect(slugs).toContain("posts");
expect(slugs).toContain("pages");
}
});
}, 120_000);
});
2 changes: 2 additions & 0 deletions packages/core/tests/integration/fixture/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { sqlite } from "emdash/db";

const dbUrl = process.env.EMDASH_TEST_DB || "file:./test.db";
const uploadsDir = process.env.EMDASH_TEST_UPLOADS || "./uploads";
const viteCacheDir = process.env.EMDASH_TEST_VITE_CACHE || undefined;
const _rawMaxUploadSize = process.env.EMDASH_MAX_UPLOAD_SIZE
? parseInt(process.env.EMDASH_MAX_UPLOAD_SIZE, 10)
: undefined;
Expand Down Expand Up @@ -40,6 +41,7 @@ export default defineConfig({
},
devToolbar: { enabled: false },
vite: {
cacheDir: viteCacheDir,
server: {
fs: {
// When running from a temp dir, node_modules is symlinked back to the
Expand Down
2 changes: 2 additions & 0 deletions packages/core/tests/integration/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ export async function createTestServer(options: TestServerOptions): Promise<Test
});
const dbPath = join(workDir, "test.db");
const uploadsDir = join(workDir, "uploads");
const viteCacheDir = join(workDir, ".vite-cache");
mkdirSync(uploadsDir, { recursive: true });

// Borrow the donor node_modules via symlink (resolution still hits real
Expand All @@ -181,6 +182,7 @@ export async function createTestServer(options: TestServerOptions): Promise<Test
ASTRO_DEV_BACKGROUND: "1",
EMDASH_TEST_DB: `file:${dbPath}`,
EMDASH_TEST_UPLOADS: uploadsDir,
EMDASH_TEST_VITE_CACHE: viteCacheDir,
...options.env,
},
stdio: "pipe",
Expand Down
Loading