|
1 | | -import { mkdtemp, rm, writeFile } from "node:fs/promises"; |
2 | | -import { tmpdir } from "node:os"; |
3 | 1 | import { join } from "node:path"; |
4 | 2 | import { expect, test } from "bun:test"; |
5 | 3 |
|
6 | | -import { schemaMaterializations } from "../schema/lazy.js"; |
| 4 | +const settingsLazinessProbe = join( |
| 5 | + import.meta.dirname, |
| 6 | + "../../scripts/settings-lazy-probe.ts", |
| 7 | +); |
7 | 8 |
|
8 | | -test("importing settings does not build schemas; a malformed file fails when read", async () => { |
9 | | - const before = schemaMaterializations(); |
10 | | - const settings = await import("./settings.js"); |
11 | | - expect(schemaMaterializations()).toBe(before); |
| 9 | +test("importing settings does not build schemas", async () => { |
| 10 | + const child = Bun.spawn([process.execPath, settingsLazinessProbe], { |
| 11 | + stdout: "pipe", |
| 12 | + stderr: "pipe", |
| 13 | + }); |
| 14 | + const [exitCode, stdout, stderr] = await Promise.all([ |
| 15 | + child.exited, |
| 16 | + new Response(child.stdout).text(), |
| 17 | + new Response(child.stderr).text(), |
| 18 | + ]); |
12 | 19 |
|
13 | | - const dir = await mkdtemp(join(tmpdir(), "lazy-settings-")); |
14 | | - try { |
15 | | - const path = join(dir, "settings.json"); |
16 | | - await writeFile(path, JSON.stringify({ providers: "nope" })); |
17 | | - await expect(settings.loadSettings(path)).rejects.toThrow(); |
18 | | - expect(schemaMaterializations()).toBeGreaterThan(before); |
19 | | - } finally { |
20 | | - await rm(dir, { recursive: true, force: true }); |
21 | | - } |
| 20 | + expect(exitCode, stderr).toBe(0); |
| 21 | + const materializations = JSON.parse(stdout) as { |
| 22 | + before: number; |
| 23 | + afterImport: number; |
| 24 | + }; |
| 25 | + expect(materializations.afterImport).toBe(materializations.before); |
22 | 26 | }); |
0 commit comments