forked from unjs/jiti
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bun.test.ts
42 lines (33 loc) · 998 Bytes
/
bun.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { fileURLToPath } from "node:url";
import { readdir, writeFile, mkdir } from "node:fs/promises";
import { join } from "node:path";
// @ts-ignore
import { test, expect } from "bun:test";
import jiti from "../lib/index.js";
const fixturesDir = fileURLToPath(new URL("fixtures", import.meta.url));
const fixtures = await readdir(fixturesDir);
const _jiti = jiti(fixturesDir, {
debug: true,
interopDefault: true,
requireCache: false,
cache: false,
});
for (const fixture of fixtures) {
if (fixture.startsWith("error-")) {
continue;
}
test("fixtures/" + fixture, () => {
_jiti("./" + fixture);
});
}
test("hmr", async () => {
await mkdir(join(fixturesDir, "../.tmp"), { recursive: true });
const tmpFile = join(fixturesDir, "../.tmp/bun.mjs");
let value;
await writeFile(tmpFile, "export default 1");
value = _jiti(tmpFile);
expect(value).toBe(1);
await writeFile(tmpFile, "export default 2");
value = _jiti(tmpFile);
expect(value).toBe(2);
});