Skip to content

Commit

Permalink
chore(ci): update test scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
magic-akari committed Nov 17, 2024
1 parent 5dddd61 commit f4e0f57
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 56 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,18 @@ jobs:
node-version-file: ".node-version"

- run: node --test

bun-test:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: build
path: build

- uses: oven-sh/setup-bun@v2
name: Install bun

- run: bun test test_bun
24 changes: 24 additions & 0 deletions scripts/update_tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env -S deno run --allow-read --allow-write
import { walk } from "jsr:@std/fs/walk";

import init, { format } from "../build/dart_fmt.js"

await init();

const test_root = new URL(import.meta.resolve("../test_data"));

for await (const entry of walk(test_root, {
includeDirs: false,
exts: ["unit"],
})) {
if (entry.name.startsWith(".")) {
continue;
}

const expect_path = entry.path + ".snap";
const input = Deno.readTextFileSync(entry.path);

const actual = format(input, entry.path);
Deno.writeTextFileSync(expect_path, actual);
}
console.log("done");
25 changes: 25 additions & 0 deletions test_bun/bun.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Glob } from "bun";
import { expect, test } from "bun:test";
import { chdir } from "node:process";
import { fileURLToPath } from "node:url";

import init, { format } from "../build/dart_fmt.js";

await init();

const test_root = fileURLToPath(import.meta.resolve("../test_data"));
chdir(test_root);

const glob = new Glob("**/*.unit");

for await (const input_path of glob.scan()) {
const [input, expected] = await Promise.all([
Bun.file(input_path).text(),
Bun.file(input_path + ".snap").text(),
]);

test(input_path, () => {
const actual = format(input, input_path);
expect(actual).toBe(expected);
});
}
44 changes: 19 additions & 25 deletions test_deno/deno.test.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,29 @@
import init, { format } from "../build/dart_fmt.js"
import { assertEquals } from "jsr:@std/assert";
import { walk } from "jsr:@std/fs/walk";

import { assertEquals } from "https://deno.land/std@0.219.0/assert/mod.ts";
import { walk } from "https://deno.land/std@0.219.0/fs/walk.ts";
import { relative } from "https://deno.land/std@0.219.0/path/mod.ts";
import init, { format } from "../build/dart_fmt.js"

await init();

const update = Deno.args.includes("--update");

const test_root = new URL("../test_data", import.meta.url);
const test_root = new URL(import.meta.resolve("../test_data"));
Deno.chdir(test_root);

for await (const entry of walk(test_root, {
includeDirs: false,
exts: ["unit"],
for await (const entry of walk(".", {
includeDirs: false,
exts: ["unit"],
})) {
if (entry.name.startsWith(".")) {
continue;
}
if (entry.name.startsWith(".")) {
continue;
}

const input = Deno.readTextFileSync(entry.path);
const input_path = entry.path;
const expect_path = input_path + ".snap";

if (update) {
const actual = format(input, entry.path);
Deno.writeTextFileSync(entry.path + ".snap", actual);
} else {
const test_name = relative(test_root.pathname, entry.path);
const expected = Deno.readTextFileSync(entry.path + ".snap");
const input = Deno.readTextFileSync(input_path);
const expected = Deno.readTextFileSync(expect_path);

Deno.test(test_name, () => {
const actual = format(input, entry.path);
assertEquals(actual, expected);
});
}
Deno.test(input_path, () => {
const actual = format(input, entry.path);
assertEquals(actual, expected);
});
}
51 changes: 20 additions & 31 deletions test_node/test-node.mjs
Original file line number Diff line number Diff line change
@@ -1,42 +1,31 @@
import init, { format } from "../build/dart_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";

await init();

const test_root = fileURLToPath(new URL("../test_data", import.meta.url));

for await (const dirent of await fs.opendir(test_root, { recursive: true })) {
if (!dirent.isFile()) {
continue;
}
import init, { format } from "../build/dart_fmt_node.js";

if (dirent.name.startsWith(".")) {
continue;
}
await init();

const input_path = path.join(dirent.path, dirent.name);
const ext = path.extname(input_path);
const test_root = fileURLToPath(import.meta.resolve("../test_data"));
chdir(test_root);

switch (ext) {
case ".unit":
break;
for await (const input_path of fs.glob("**/*.unit")) {
if (basename(input_path).startsWith(".")) {
continue;
}

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" }),
]);
const [input, expected] = await Promise.all([
fs.readFile(input_path, "utf-8"),
fs.readFile(expect_path, "utf-8"),
]);

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

0 comments on commit f4e0f57

Please sign in to comment.