Skip to content

Commit

Permalink
fix(test): bun test scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
magic-akari committed Sep 28, 2024
1 parent 6d01e21 commit a7f8e3e
Showing 1 changed file with 9 additions and 32 deletions.
41 changes: 9 additions & 32 deletions crates/lua_fmt/test_bun/bun.spec.ts
Original file line number Diff line number Diff line change
@@ -1,50 +1,27 @@
import { Glob } from "bun";
import { expect, test } from "bun:test";
import fs from "node:fs/promises";
import path from "node:path";
import init, { format } from "../pkg";
import init, { format } from "../pkg/lua_fmt";

await init();

async function* walk(dir: string): AsyncGenerator<string> {
for await (const d of await fs.readdir(dir)) {
const entry = path.join(dir, d);
const stat = await fs.stat(entry);

if (stat.isDirectory()) {
yield* walk(entry);
}

if (stat.isFile()) {
yield entry;
}
}
}

const test_root = Bun.fileURLToPath(new URL("../test_data", import.meta.url));
const glob = new Glob("**/*.lua");

for await (const input_path of walk(test_root)) {
for await (const input_path of glob.scan(test_root)) {
if (path.basename(input_path).startsWith(".")) {
continue;
}

const ext = path.extname(input_path);

switch (ext) {
case ".lua":
break;

default:
continue;
}
const full_path = path.join(test_root, input_path);

const test_name = path.relative(test_root, input_path);
const [input, expected] = await Promise.all([
Bun.file(input_path).text(),
Bun.file(input_path + ".snap").text(),
Bun.file(full_path).text(),
Bun.file(full_path + ".snap").text(),
]);

test(test_name, () => {
const actual = format(input, input_path);
test(input_path, () => {
const actual = format(input, input_path);
expect(actual).toBe(expected);
});
}

0 comments on commit a7f8e3e

Please sign in to comment.