From 37cdbb6d38f4738645af4f23ef95f467800291c2 Mon Sep 17 00:00:00 2001 From: Meinte Boersma Date: Fri, 1 Sep 2023 11:49:29 +0200 Subject: [PATCH] replace using ajv from Deno with a direct npx call --- deno.lock | 10 +--------- src/deps.ts | 12 +----------- src/m3-instances.test.ts | 42 +++++++++------------------------------- test.sh | 2 ++ 4 files changed, 13 insertions(+), 53 deletions(-) diff --git a/deno.lock b/deno.lock index 9a30805..16113a1 100644 --- a/deno.lock +++ b/deno.lock @@ -80,14 +80,6 @@ "https://deno.land/std@0.63.0/encoding/yaml.ts": "f60f56addab7cffa465e0f35fb2b5296158bd952aa50cb8b22aa446861ce093b", "https://deno.land/x/exec@0.0.5/mod.ts": "2a71f7e23e25be883275b22d872bbd2c3dfa3058934f1f156c8663fb81f5894f", "https://deno.land/x/yaml_loader@v0.1.0/mod.ts": "3d17e2a18aa78eec71a145f72e9c17bf6d3ca27da6ff59cd6499e74794640b86", - "https://deno.land/x/yaml_loader@v0.1.0/yaml_loader.ts": "66501a8ae8d0082a802251bcfb998b3b5f7d299ec094e668721f4e19e9f80938", - "https://esm.sh/v106/ajv-formats@2.1.0": "f00187ff80d3f85df4b9de237532592365f3c3a276d3bb134de3d6aaad8fa071", - "https://esm.sh/v106/ajv-formats@2.1.0/denonext/ajv-formats.mjs": "2c57d042b1226144d142c15e2951a0c777be2d5d0d575e633a91ef4283f59178", - "https://esm.sh/v106/ajv@8.12.0": "8bbb336a8a5e8859505feeeffae8cd5daadfc55e0c284ab9e4d5ddb5bcb8e5bd", - "https://esm.sh/v106/ajv@8.12.0/denonext/ajv.mjs": "a6fb3969014475e6fcd9cbea3871d660382a8f34ed3375d701f88e09124f2053", - "https://esm.sh/v106/ajv@8.12.0/denonext/dist/compile/codegen.js": "d981238e5b1e78217e1c6db59cbd594369279722c608ed630d08717ee44edd84", - "https://esm.sh/v106/fast-deep-equal@3.1.3/denonext/fast-deep-equal.mjs": "6313b3e05436550e1c0aeb2a282206b9b8d9213b4c6f247964dd7bb4835fb9e5", - "https://esm.sh/v106/json-schema-traverse@1.0.0/denonext/json-schema-traverse.mjs": "c5da8353bc014e49ebbb1a2c0162d29969a14c325da19644e511f96ba670cc45", - "https://esm.sh/v106/uri-js@4.4.1/denonext/uri-js.mjs": "901d462f9db207376b39ec603d841d87e6b9e9568ce97dfaab12aa77d0f99f74" + "https://deno.land/x/yaml_loader@v0.1.0/yaml_loader.ts": "66501a8ae8d0082a802251bcfb998b3b5f7d299ec094e668721f4e19e9f80938" } } diff --git a/src/deps.ts b/src/deps.ts index 47055e1..a34e7b9 100644 --- a/src/deps.ts +++ b/src/deps.ts @@ -1,22 +1,12 @@ import {exec} from "https://deno.land/x/exec@0.0.5/mod.ts" -import {assertEquals, fail} from "https://deno.land/std@0.200.0/testing/asserts.ts" +import {assertEquals} from "https://deno.land/std@0.200.0/testing/asserts.ts" import {YamlLoader} from "https://deno.land/x/yaml_loader@v0.1.0/mod.ts" -import Ajv, {ErrorObject} from "https://esm.sh/v106/ajv@8.12.0" -import addFormats from "https://esm.sh/v106/ajv-formats@2.1.0" - export { - Ajv, - addFormats, assertEquals, exec, - fail, YamlLoader } -export type { - ErrorObject -} - diff --git a/src/m3-instances.test.ts b/src/m3-instances.test.ts index 9c22dfc..1ff4603 100644 --- a/src/m3-instances.test.ts +++ b/src/m3-instances.test.ts @@ -1,46 +1,22 @@ -import {assertEquals, fail} from "./deps.ts" -import { - readFileAsJson -} from "../../repos/lioncore-typescript/src-utils/json.ts" -import { - deserializeLanguage -} from "../../repos/lioncore-typescript/src/m3/deserializer.ts" -import { - SerializationChunk -} from "../../repos/lioncore-typescript/src/serialization.ts" -import { - createJsonValidatorForSchema -} from "./utils/json-validator.ts" -import {fromRoot, pathOfSchema, pathOfSerialization} from "./config.ts" +import {assertEquals} from "./deps.ts" +import {readFileAsJson} from "../../repos/lioncore-typescript/src-utils/json.ts" +import {sortSerialization} from "../../repos/lioncore-typescript/src-utils/serialization-utils.ts" +import {deserializeLanguage} from "../../repos/lioncore-typescript/src/m3/deserializer.ts" +import {SerializationChunk} from "../../repos/lioncore-typescript/src/serialization.ts" +import {fromRoot, pathOfSerialization} from "./config.ts" Deno.test("M3 instances (Deno)", async (tctx) => { - await tctx.step("check whether Java serialization of LIonCore/M3 validates against JSON Schema", async () => { - const serializationJava = await readFileAsJson(fromRoot(pathOfSerialization("m3", "Java"))) - const lioncoreSchema = await readFileAsJson(fromRoot(pathOfSchema("m3"))) - const validator = createJsonValidatorForSchema(lioncoreSchema) - const errors = validator(serializationJava) - if (errors.length > 0) { - const take = 10 - const more = Math.max(errors.length - take, 0) - console.dir([ - ...errors.slice(0, take), - ...(more > 0 ? [`${more} more validation error${more > 1 ? "s" : ""}...`] : []) - ]) - fail("Java serialization of LIonCore/M3 self-definition doesn't validate against JSON Schema") - } - }) - await tctx.step("check whether Java serialization of LIonCore/M3 deserializes in TypeScript impl. (no assertions)", async () => { const serializationJava = await readFileAsJson(fromRoot(pathOfSerialization("m3", "Java"))) /* const deserializationJava = */ deserializeLanguage(serializationJava as SerializationChunk) }) await tctx.step("check whether Java and TypeScript serializations match", async () => { - const serializationJava = await readFileAsJson(fromRoot(pathOfSerialization("m3", "Java"))) - const serializationTypeScript = await readFileAsJson(fromRoot(pathOfSerialization("m3", "TypeScript"))) - assertEquals(serializationJava, serializationTypeScript) + const serializationJava = await readFileAsJson(fromRoot(pathOfSerialization("m3", "Java"))) as SerializationChunk + const serializationTypeScript = await readFileAsJson(fromRoot(pathOfSerialization("m3", "TypeScript"))) as SerializationChunk + assertEquals(sortSerialization(serializationJava), sortSerialization(serializationTypeScript)) }) }) diff --git a/test.sh b/test.sh index b8fbb6c..10ce6fe 100755 --- a/test.sh +++ b/test.sh @@ -2,3 +2,5 @@ deno task run-tests +npx ajv -c ajv-formats --spec=draft2020 --strict=true --allErrors=true --allowUnionTypes=true test -s repos/lioncore-typescript/schemas/lioncore.serialization.schema.json -d repos/lioncore-java/core/src/test/resources/serialization/lioncore.json --valid +