diff --git a/crates/lua_fmt/test_bun/bun.spec.ts b/crates/lua_fmt/test_bun/bun.spec.ts index f20618c..8592b15 100644 --- a/crates/lua_fmt/test_bun/bun.spec.ts +++ b/crates/lua_fmt/test_bun/bun.spec.ts @@ -1,23 +1,21 @@ import { Glob } from "bun"; import { expect, test } from "bun:test"; -import path from "node:path"; +import { chdir } from "node:process"; +import { fileURLToPath } from "node:url"; + import init, { format } from "../pkg/lua_fmt"; await init(); -const test_root = Bun.fileURLToPath(new URL("../test_data", import.meta.url)); -const glob = new Glob("**/*.lua"); - -for await (const input_path of glob.scan(test_root)) { - if (path.basename(input_path).startsWith(".")) { - continue; - } +const test_root = fileURLToPath(import.meta.resolve("../test_data")); +chdir(test_root); - const full_path = path.join(test_root, input_path); +const glob = new Glob("**/*.lua"); +for await (const input_path of glob.scan()) { const [input, expected] = await Promise.all([ - Bun.file(full_path).text(), - Bun.file(full_path + ".snap").text(), + Bun.file(input_path).text(), + Bun.file(input_path + ".snap").text(), ]); test(input_path, () => { diff --git a/crates/lua_fmt/test_node/test-node.mjs b/crates/lua_fmt/test_node/test-node.mjs index aea917a..0da38cb 100644 --- a/crates/lua_fmt/test_node/test-node.mjs +++ b/crates/lua_fmt/test_node/test-node.mjs @@ -1,42 +1,31 @@ -import init, { format } from "../pkg/lua_fmt_node.js"; -import { test } from "node:test"; import assert from "node:assert/strict"; import fs from "node:fs/promises"; -import path from "node:path"; +import { basename } from "node:path"; +import { chdir } from "node:process"; +import { test } from "node:test"; import { fileURLToPath } from "node:url"; +import init, { format } from "../pkg/lua_fmt_node.js"; + await init(); -const test_root = fileURLToPath(new URL("../test_data", import.meta.url)); +const test_root = fileURLToPath(import.meta.resolve("../test_data")); +chdir(test_root); -for await (const dirent of await fs.opendir(test_root, { recursive: true })) { - if (!dirent.isFile()) { +for await (const input_path of fs.glob("**/*.lua")) { + if (basename(input_path).startsWith(".")) { continue; } - if (dirent.name.startsWith(".")) { - continue; - } - - const input_path = path.join(dirent.path, dirent.name); - const ext = path.extname(input_path); - - switch (ext) { - case ".lua": - break; - - default: - continue; - } + const expect_path = input_path + ".snap"; - const test_name = path.relative(test_root, input_path); const [input, expected] = await Promise.all([ - fs.readFile(input_path, { encoding: "utf-8" }), - fs.readFile(input_path + ".snap", { encoding: "utf-8" }), + fs.readFile(input_path, "utf-8"), + fs.readFile(expect_path, "utf-8"), ]); - test(test_name, () => { - const actual = format(input, input_path); + test(input_path, () => { + const actual = format(input, input_path); assert.equal(actual, expected); }); }