From 8cf52e3bac364d0c724cec55bbe0c91636b8f6b8 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Mon, 7 Sep 2020 19:57:57 +0100 Subject: [PATCH 1/2] add types, update dependencies, typo in readme --- .gitignore | 2 ++ README.md | 2 +- index.d.ts | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 13 +++++---- 4 files changed, 89 insertions(+), 7 deletions(-) create mode 100644 index.d.ts diff --git a/.gitignore b/.gitignore index b2ff1e0..4703292 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,5 @@ build/Release node_modules .DS_Store + +package-lock.json diff --git a/README.md b/README.md index 2d1171c..7aa2052 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ function afterEachFunc(result) { // Pass option log == false to prevent default error logging - // If result.passed is false the test will fails after this function returns + // If result.passed is false the test will fail after this function returns } ``` diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..2d89333 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,79 @@ +declare function jsonSchemaTest( + validators: jsonSchemaTest.Validator[], + opts: jsonSchemaTest.Options +): void; + +declare namespace jsonSchemaTest { + type ValidationError = any; + + type Schema = Record | boolean; + + interface Validator { + validate( + schema: Schema, + data: unknown + ): boolean | Promise; + errors?: ValidationError[] | null; + } + + interface Options { + description?: string; + suites: Record; + async?: boolean; + asyncValid?: "data"; + afterEach?: (res: TestResult) => void; + afterError?: (res: TestResult) => void; // res.passed === false + log?: boolean; // pass false to prevent logging + only?: true | string[]; // names of TestSuite or filenames or true to perform only these tests + skip?: true | string[]; // skip all or some tests + cwd?: string; // working dir, pass __dirname to use paths relative to the module + hideFolder?: string; + timeout?: number; + assert?: Assert; + } + + type Suites = SuitesPath | TestSuite[] | TestSuitePath[]; + + type SuitesPath = string; // glob pattern + + interface TestSuite { + name: string; + test: TestGroup[]; + } + + interface TestSuitePath { + name: string; + path: string; + } + + interface TestGroup { + description: string; + schema?: Schema | string; + schemas?: (Schema | string)[]; + tests: Test[]; + } + + interface Test { + description: string; + data: unknown; + valid?: boolean; + error?: string; + } + + interface TestResult { + validator: Validator; + schema: Schema; + data: unknown; + valid: boolean; // validation result + expected: boolean; // expected validation result + errors: ValidationError[] | null; // validation errors if valid === false + passed: boolean; // true if valid == expected + } + + interface Assert { + (ok: boolean): void; + equal: (x: unknown, y: unknown) => void; + } +} + +export = jsonSchemaTest; diff --git a/package.json b/package.json index d6474de..3e80ff8 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "test-pass": "mocha spec/*.pass.js -R spec", "test-fail": "mocha spec/*.fail.js -R spec | grep ' 0 passing' | grep -q '0'", "test-spec": "npm run test-pass && npm run test-fail", - "test": "nyc npm run test-spec" + "test": "nyc npm run test-spec && tsc index.d.ts" }, "repository": { "type": "git", @@ -28,11 +28,12 @@ "glob": "^5.0.10" }, "devDependencies": { - "ajv": "^4.9.0", - "coveralls": "^2.11.15", - "mocha": "^3.2.0", - "nyc": "^10.0.0", - "pre-commit": "^1.1.3" + "ajv": "^6.12.4", + "coveralls": "^3.0.1", + "mocha": "^8.0.1", + "nyc": "^15.0.0", + "pre-commit": "^1.1.3", + "typescript": "^4.0.2" }, "nyc": { "exclude": [ From 9fd813b7b36cd61b4d0bf19067c7ce419ef32ac7 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Mon, 7 Sep 2020 19:59:48 +0100 Subject: [PATCH 2/2] 2.1.0 --- .travis.yml | 5 +++-- package.json | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index c5cea94..23c47e1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ language: node_js node_js: - - "4" - - "6" + - 10 + - 12 + - 14 after_script: - coveralls < coverage/lcov.info diff --git a/package.json b/package.json index 3e80ff8..be8a308 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "json-schema-test", - "version": "2.0.0", + "version": "2.1.0", "description": "Testing JSON schemas against sample data", "main": "index.js", "scripts": {