Skip to content

Commit a7f8e3e

Browse files
committed
fix(test): bun test scripts
1 parent 6d01e21 commit a7f8e3e

File tree

1 file changed

+9
-32
lines changed

1 file changed

+9
-32
lines changed
Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,27 @@
1+
import { Glob } from "bun";
12
import { expect, test } from "bun:test";
2-
import fs from "node:fs/promises";
33
import path from "node:path";
4-
import init, { format } from "../pkg";
4+
import init, { format } from "../pkg/lua_fmt";
55

66
await init();
77

8-
async function* walk(dir: string): AsyncGenerator<string> {
9-
for await (const d of await fs.readdir(dir)) {
10-
const entry = path.join(dir, d);
11-
const stat = await fs.stat(entry);
12-
13-
if (stat.isDirectory()) {
14-
yield* walk(entry);
15-
}
16-
17-
if (stat.isFile()) {
18-
yield entry;
19-
}
20-
}
21-
}
22-
238
const test_root = Bun.fileURLToPath(new URL("../test_data", import.meta.url));
9+
const glob = new Glob("**/*.lua");
2410

25-
for await (const input_path of walk(test_root)) {
11+
for await (const input_path of glob.scan(test_root)) {
2612
if (path.basename(input_path).startsWith(".")) {
2713
continue;
2814
}
2915

30-
const ext = path.extname(input_path);
31-
32-
switch (ext) {
33-
case ".lua":
34-
break;
35-
36-
default:
37-
continue;
38-
}
16+
const full_path = path.join(test_root, input_path);
3917

40-
const test_name = path.relative(test_root, input_path);
4118
const [input, expected] = await Promise.all([
42-
Bun.file(input_path).text(),
43-
Bun.file(input_path + ".snap").text(),
19+
Bun.file(full_path).text(),
20+
Bun.file(full_path + ".snap").text(),
4421
]);
4522

46-
test(test_name, () => {
47-
const actual = format(input, input_path);
23+
test(input_path, () => {
24+
const actual = format(input, input_path);
4825
expect(actual).toBe(expected);
4926
});
5027
}

0 commit comments

Comments
 (0)