Skip to content

Commit

Permalink
refactor: bun test
Browse files Browse the repository at this point in the history
  • Loading branch information
magic-akari committed Aug 26, 2024
1 parent c4729bd commit a783d7b
Showing 1 changed file with 8 additions and 31 deletions.
39 changes: 8 additions & 31 deletions 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/yamlfmt";

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("**/*.yaml");

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 ".yaml":
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);

Check failure on line 25 in test_bun/bun.spec.ts

View workflow job for this annotation

GitHub Actions / bun-test

error: expect(received).toBe(expected)

Expected: "unicode: \"Sosa did fine.\\u263A\"\ncontrol: \"\\b1998\\t1999\\t2000\\n\"\nhex esc: \"\\x0d\\x0a is \\r\\n\"\n\nsingle: '\"Howdy!\" he cried.'\nquoted: \" # Not a 'comment'.\"\ntie-fighter: '|\\-*-/|'\n" Received: "unicode: \"Sosa did fine.\\u263A\"\ncontrol: \"\\b1998\\t1999\\t2000\\n\"\nhex esc: \"\\x0d\\x0a is \\r\\n\"\n\nsingle: '\"Howdy!\" he cried.'\nquoted: ' # Not a ''comment''.'\ntie-fighter: '|\\-*-/|'\n" at /home/runner/work/yamlfmt/yamlfmt/test_bun/bun.spec.ts:25:18

Check failure on line 25 in test_bun/bun.spec.ts

View workflow job for this annotation

GitHub Actions / bun-test

error: expect(received).toBe(expected)

Expected: "- \"123\"\n- \"123\"\n- \"''\"\n- '\"\"'\n- \"'\"\n- \"\\\"\\\"\"\n- '\\n123'\n- \"\\n123\"\n- \"'a\\\"b\"\n" Received: "- \"123\"\n- \"123\"\n- \"''\"\n- '\"\"'\n- ''''\n- \"\\\"\\\"\"\n- '\\n123'\n- \"\\n123\"\n- \"'a\\\"b\"\n" at /home/runner/work/yamlfmt/yamlfmt/test_bun/bun.spec.ts:25:18
});
}

0 comments on commit a783d7b

Please sign in to comment.