Add a TAP test suite alongside mocha

Tests live in tests/, mirroring each package's src, and in
plugins/*/test/*.test.ts. They are TypeScript run by Node's type stripping,
so the @tapjs/typescript plugin is disabled and `pnpm install` runs tap build
to apply that.

The first tests cover the largest lib files: link, subscriptions, config
classes and prometheus. A shared helper checks the JSON serialisable class
pattern, and one test runs it on every serialisable class lib exports, with
samples generated from each class's schema.

Known bugs the new tests found are marked todo. Mocha, codecov and the
existing CI matrix are unchanged; tap.yml runs the new suite on the latest
Node.js and Factorio.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bbassieandClaude Opus 5.5 committed 2026-11-24 22:21:09 +00:00
1 parent bbcb64d411
commit b73b584d2d
16 files changed
+5348 -5

No files matched your search

+48
View File
@@ -0,0 +1,48 @@
import t from "tap";
import * as lib from "@clusterio/lib";
import {
type KnownSamples, jsonSamples, jsonSerialisableClasses, testJsonSerialisable,
} from "../../shared/json_serialisable.ts";
// Every JSON serialisable class exported by lib gets the common tests, so new
// classes are covered without adding anything here. Schemas the sample
// generator cannot satisfy get hand written samples, minimal first.
const known: KnownSamples = new Map<object, unknown[]>([
[lib.ModInfo.jsonSchema, [
{ name: "a", version: "1.0.0", title: "A", author: "b" },
{
name: "a", version: "1.0.0", title: "A", author: "b", contact: "c", homepage: "h", description: "d",
factorio_version: "2.0", dependencies: ["base >= 2.0", "? b", "! c", "(?) d", "~ e"],
size: 1, mtime_ms: 2, sha1: "s", updated_at_ms: 3, is_deleted: true,
},
]],
[lib.ModDependency.jsonSchema, ["base", "? a > 1.0.0"]],
[lib.ModVersionEquality.jsonSchema, ["= 1.0.0", ">= 2.1.0"]],
[lib.SubscriptionRequest.jsonSchema, [
["InstanceDetailsUpdatesEvent", "subscribe", 0],
["InstanceDetailsUpdatesEvent", "replace", 10, ["a", "b"]],
]],
]);
// Classes whose fromJSON needs more than the JSON value, they have their own tests.
const excluded = new Set([
"Config",
"ControllerConfig",
"CtlConfig",
"HostConfig",
"InstanceConfig",
]);
// Known failures, reported as todo until fixed.
const todo = new Map([
["InstanceDetailsChangedEvent", "has no toJSON, so it serialises as { details } instead of InstanceDetails"],
]);
for (const [name, Class] of jsonSerialisableClasses(lib)) {
if (excluded.has(name)) {
continue;
}
t.test(name, { todo: todo.get(name) }, async t1 => {
testJsonSerialisable(t1, Class, jsonSamples(Class, known));
});
}