|
1 | 1 | import { describe, expect, test } from "bun:test"; |
| 2 | +import { mkdtempSync, rmSync } from "node:fs"; |
| 3 | +import os from "node:os"; |
2 | 4 | import path from "node:path"; |
3 | 5 | import { fileURLToPath } from "node:url"; |
4 | 6 | import { normalizePath } from "vite"; |
@@ -285,15 +287,21 @@ describe("configResolved", () => { |
285 | 287 | throw new Error(message); |
286 | 288 | }, |
287 | 289 | }; |
288 | | - // `/tmp` has no .fsproj in it. |
289 | | - const config: ResolvedConfig = { |
290 | | - ...buildConfig(), |
291 | | - root: "/tmp", |
292 | | - } as unknown as ResolvedConfig; |
293 | | - await (plugin.configResolved as any).call(context, config); |
294 | | - |
295 | | - expect((plugin.buildStart as any).call(context, {})).rejects.toThrow(/No .fsproj was found/); |
296 | | - expect(daemon.projectChangedCalls).toHaveLength(0); |
| 290 | + // A directory that exists and holds no .fsproj. `/tmp` is not that directory on Windows, and |
| 291 | + // `configResolved` reads the root, so it failed there with ENOENT before reaching the point. |
| 292 | + const emptyRoot: string = normalizePath(mkdtempSync(path.join(os.tmpdir(), "vpf-no-fsproj-"))); |
| 293 | + try { |
| 294 | + const config: ResolvedConfig = { |
| 295 | + ...buildConfig(), |
| 296 | + root: emptyRoot, |
| 297 | + } as unknown as ResolvedConfig; |
| 298 | + await (plugin.configResolved as any).call(context, config); |
| 299 | + |
| 300 | + expect((plugin.buildStart as any).call(context, {})).rejects.toThrow(/No .fsproj was found/); |
| 301 | + expect(daemon.projectChangedCalls).toHaveLength(0); |
| 302 | + } finally { |
| 303 | + rmSync(emptyRoot, { recursive: true, force: true }); |
| 304 | + } |
297 | 305 | }); |
298 | 306 |
|
299 | 307 | test("compiles Release for a production build and Debug otherwise", async () => { |
|
0 commit comments