-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(tests): simplify test scripts
- Loading branch information
1 parent
51a338c
commit 29f4da9
Showing
2 changed files
with
23 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
} |