Skip to content

Commit ab39abe

Browse files
committed
Make test cross plat
1 parent a3a914e commit ab39abe

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

packages/vite-plugin-fable/tests/index.test.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { describe, expect, test } from "bun:test";
2+
import { mkdtempSync, rmSync } from "node:fs";
3+
import os from "node:os";
24
import path from "node:path";
35
import { fileURLToPath } from "node:url";
46
import { normalizePath } from "vite";
@@ -285,15 +287,21 @@ describe("configResolved", () => {
285287
throw new Error(message);
286288
},
287289
};
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+
}
297305
});
298306

299307
test("compiles Release for a production build and Debug otherwise", async () => {

0 commit comments

Comments
 (0)