diff --git a/packages/format/package.json b/packages/format/package.json index e89b8cc0..2defc53b 100644 --- a/packages/format/package.json +++ b/packages/format/package.json @@ -22,8 +22,12 @@ "yaml": "^2.3.4" }, "devDependencies": { + "@hyperjump/browser": "^1.2.0", + "@hyperjump/json-schema": "^1.11.0", "chalk": "^4.1.0", + "cli-highlight": "^2.1.11", "concurrently": "^8.2.2", + "indent-string": "^4.0.0", "nodemon": "^3.0.2", "ts-node": "^10.9.2", "typescript": "^5.3.3", diff --git a/packages/tests/schemas/examples.test.ts b/packages/format/src/schemas/examples.test.ts similarity index 94% rename from packages/tests/schemas/examples.test.ts rename to packages/format/src/schemas/examples.test.ts index 36c6c7a5..de01410e 100644 --- a/packages/tests/schemas/examples.test.ts +++ b/packages/format/src/schemas/examples.test.ts @@ -1,11 +1,11 @@ import { expect, describe, it } from "vitest"; -import type { JSONSchema } from "@ethdebug/format"; - -import schemas, { schemaExtensions } from "../src/schemas.js"; +import { schemaExtensions } from "../../test/extensions"; +import { schemas } from "."; +import type { JSONSchema } from "../describe"; // loads schemas into global hyperjump json schema validator -import "../src/loadSchemas.js"; +import "../../test/hyperjump"; const idsOfSchemasAllowedToOmitExamples = new Set([ "schema:ethdebug/format/type", diff --git a/packages/tests/schemas/validity.test.ts b/packages/format/src/schemas/validity.test.ts similarity index 55% rename from packages/tests/schemas/validity.test.ts rename to packages/format/src/schemas/validity.test.ts index 28b9ff44..d006a3fb 100644 --- a/packages/tests/schemas/validity.test.ts +++ b/packages/format/src/schemas/validity.test.ts @@ -1,14 +1,28 @@ import { describe, it } from "vitest"; import { + type OutputUnit, validate, InvalidSchemaError, } from "@hyperjump/json-schema/draft-2020-12"; -import schemas from "../src/schemas.js"; -import printErrors from "../src/printErrors.js"; +import { schemas } from "."; // loads schemas into global hyperjump json schema validator -import "../src/loadSchemas.js"; +import "../../test/hyperjump"; + +const printErrors = (output: OutputUnit): string => output.errors! + .map((error) => { + if (!error.valid && !error.keyword.endsWith("#validate")) { + return `${ + error.instanceLocation + } fails schema constraint ${ + error.absoluteKeywordLocation + }`; + } + }) + .filter((message): message is string => !!message) + .map(message => ` - ${message}`) + .join("\n"); describe("Valid schemas", () => { for (const [id, schema] of Object.entries(schemas)) { diff --git a/packages/tests/src/schemas.ts b/packages/format/test/extensions.ts similarity index 97% rename from packages/tests/src/schemas.ts rename to packages/format/test/extensions.ts index 8dbbd597..5cba4df4 100644 --- a/packages/tests/src/schemas.ts +++ b/packages/format/test/extensions.ts @@ -1,4 +1,4 @@ -import { schemas } from "@ethdebug/format"; +import { schemas } from "../src"; export const schemaExtensions: { [schemaId: string]: { @@ -81,5 +81,3 @@ export const schemaExtensions: { extends: new Set(["schema:ethdebug/format/type/complex"]) }, } - -export default schemas; diff --git a/packages/tests/src/loadSchemas.ts b/packages/format/test/hyperjump.ts similarity index 93% rename from packages/tests/src/loadSchemas.ts rename to packages/format/test/hyperjump.ts index 2520d3f8..304dfd8b 100644 --- a/packages/tests/src/loadSchemas.ts +++ b/packages/format/test/hyperjump.ts @@ -4,18 +4,19 @@ import { validate, setMetaSchemaOutputFormat, } from "@hyperjump/json-schema/draft-2020-12"; +// @ts-ignore import { BASIC } from "@hyperjump/json-schema/experimental"; import { bundle } from "@hyperjump/json-schema/bundle"; -import YAML from "yaml"; +import * as YAML from "yaml"; import indentString from "indent-string"; import { highlight } from "cli-highlight"; import { describeSchema, type DescribeSchemaOptions -} from "@ethdebug/format"; +} from "../src/describe"; -import schemas from "./schemas.js"; +import { schemas } from "../src/schemas"; const main = () => { setMetaSchemaOutputFormat(BASIC); diff --git a/packages/format/vitest.d.ts b/packages/format/vitest.d.ts index f904581d..6b4b8f40 100644 --- a/packages/format/vitest.d.ts +++ b/packages/format/vitest.d.ts @@ -1,6 +1,9 @@ import "vitest"; +import type { DescribeSchemaOptions } from "./src/describe"; interface CustomMatchers { + toValidate(schemaOptions: DescribeSchemaOptions): R; + toSatisfy(received: any): R; toSatisfyAll(values: readonly any[]): R; } diff --git a/packages/tests/.gitignore b/packages/tests/.gitignore deleted file mode 100644 index 3c3629e6..00000000 --- a/packages/tests/.gitignore +++ /dev/null @@ -1 +0,0 @@ -node_modules diff --git a/packages/tests/package.json b/packages/tests/package.json deleted file mode 100644 index 6027b08d..00000000 --- a/packages/tests/package.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "@ethdebug/format-tests", - "version": "0.1.0-0", - "description": "Test harness for validating ethdebug/format schemas", - "main": "index.js", - "type": "module", - "license": "MIT", - "private": true, - "scripts": { - "test": "vitest" - }, - "devDependencies": { - "@ethdebug/format": "^0.1.0-0", - "@hyperjump/browser": "^1.2.0", - "@hyperjump/json-schema": "^1.11.0", - "cli-highlight": "^2.1.11", - "indent-string": "^5.0.0", - "typescript": "^5.3.3", - "vitest": "^3.0.5" - } -} diff --git a/packages/tests/src/printErrors.ts b/packages/tests/src/printErrors.ts deleted file mode 100644 index cac713c5..00000000 --- a/packages/tests/src/printErrors.ts +++ /dev/null @@ -1,17 +0,0 @@ -import type { OutputUnit } from "@hyperjump/json-schema/draft-2020-12"; - -const printErrors = (output: OutputUnit): string => output.errors! - .map((error) => { - if (!error.valid && !error.keyword.endsWith("#validate")) { - return `${ - error.instanceLocation - } fails schema constraint ${ - error.absoluteKeywordLocation - }`; - } - }) - .filter((message): message is string => !!message) - .map(message => ` - ${message}`) - .join("\n"); - -export default printErrors; diff --git a/packages/tests/tsconfig.json b/packages/tests/tsconfig.json deleted file mode 100644 index 0650fde9..00000000 --- a/packages/tests/tsconfig.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "compilerOptions": { - "rootDir": "./", - "outDir": "./dist/", - } -} diff --git a/packages/tests/typings.d.ts b/packages/tests/typings.d.ts deleted file mode 100644 index 9cd644f2..00000000 --- a/packages/tests/typings.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -import type { DescribeSchemaOptions } from "@ethdebug/format"; - -import "vitest"; - -interface CustomMatchers { - toValidate(schemaOptions: DescribeSchemaOptions): R; -} - -declare module "vitest" { - interface Assertion extends CustomMatchers {} - - interface AsymmetricMatchersContaining extends CustomMatchers {} -} diff --git a/packages/tests/vitest.config.ts b/packages/tests/vitest.config.ts deleted file mode 100644 index 6abfe8d2..00000000 --- a/packages/tests/vitest.config.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { defineProject } from "vitest/config"; - -export default defineProject({ - test: { - } -}); diff --git a/yarn.lock b/yarn.lock index d7055ab7..343f68ac 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8151,11 +8151,6 @@ indent-string@^4.0.0: resolved "https://registry.npmjs.org/indent-string/-/indent-string-4.0.0.tgz" integrity sha512-EdDDZu4A2OyIK7Lr/2zG+w5jmbuk1DVBnEwREQvBzspBJkCEbRa8GxU1lghYcaGJCnRWibjDXlq779X1/y5xwg== -indent-string@^5.0.0: - version "5.0.0" - resolved "https://registry.npmjs.org/indent-string/-/indent-string-5.0.0.tgz" - integrity sha512-m6FAo/spmsW2Ab2fU35JTYwtOKa2yAwXSwgjSv1TJzh4Mh7mC3lzAOVLBprb72XsTrgkEIsl7YrFNAiDiRhIGg== - infima@0.2.0-alpha.43: version "0.2.0-alpha.43" resolved "https://registry.npmjs.org/infima/-/infima-0.2.0-alpha.43.tgz"