From a7513a92c550651f48db0b3822efbc84b1f1b96c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8E=E4=B8=96=E6=97=A0=E4=BA=89=E5=89=91=E5=AE=87?= =?UTF-8?q?=E5=AD=90?= <1530683628@qq.com> Date: Tue, 20 Oct 2026 21:47:39 +0800 Subject: [PATCH] test: close validators and run tests in CI --- .github/workflows/ci.js.yml | 1 + typescript/test/validate.test.ts | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.js.yml b/.github/workflows/ci.js.yml index 4d10d41a..dedde931 100644 --- a/.github/workflows/ci.js.yml +++ b/.github/workflows/ci.js.yml @@ -39,3 +39,4 @@ jobs: cache-dependency-path: "typescript/package-lock.json" - run: npm ci - run: npm run build-all + - run: npm test diff --git a/typescript/test/validate.test.ts b/typescript/test/validate.test.ts index 31ef89fa..6834756e 100644 --- a/typescript/test/validate.test.ts +++ b/typescript/test/validate.test.ts @@ -1,4 +1,4 @@ -import { describe, it } from "node:test"; +import { afterEach, describe, it } from "node:test"; import assert from "node:assert/strict"; import { createTypeScriptJsonValidator } from "../dist/ts/index.js"; @@ -43,8 +43,12 @@ export interface Point { // --------------------------------------------------------------------------- // Helper // --------------------------------------------------------------------------- +const openValidators: { close(): void }[] = []; + function validatorFor(schema: string, typeName: string) { - return createTypeScriptJsonValidator(schema, typeName); + const validator = createTypeScriptJsonValidator(schema, typeName); + openValidators.push(validator); + return validator; } // --------------------------------------------------------------------------- @@ -52,6 +56,11 @@ function validatorFor(schema: string, typeName: string) { // --------------------------------------------------------------------------- describe("createTypeScriptJsonValidator", () => { + afterEach(() => { + for (const validator of openValidators.splice(0)) { + validator.close(); + } + }); describe("valid objects", () => { it("accepts an object that satisfies all required properties", () => {