From c6fdf55ff2627226476e80304c0486afa61eaae5 Mon Sep 17 00:00:00 2001 From: Paul Loyd Date: Sat, 16 Dec 2017 19:58:45 +0300 Subject: [PATCH] Validate generated json schemas in the tests --- declarations/ajv.js | 9 +++++++++ package.json | 1 + tests/run.js | 9 +++++++++ 3 files changed, 19 insertions(+) create mode 100644 declarations/ajv.js diff --git a/declarations/ajv.js b/declarations/ajv.js new file mode 100644 index 0000000..02436ec --- /dev/null +++ b/declarations/ajv.js @@ -0,0 +1,9 @@ +declare module 'ajv' { + declare export default class Ajv { + errors: {message: string}[]; + + constructor(): void; + + validateSchema(schema: mixed): boolean; + } +} diff --git a/package.json b/package.json index dbcd506..dc9550a 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "@babel/preset-env": "^7.0.0-beta.32", "@babel/preset-flow": "^7.0.0-beta.32", "@babel/register": "^7.0.0-beta.32", + "ajv": "^5.5.1", "flow-bin": "^0.60.1", "jasmine": "^2.8.0", "mocha": "^4.0.1", diff --git a/tests/run.js b/tests/run.js index 4812e48..7bd917a 100644 --- a/tests/run.js +++ b/tests/run.js @@ -3,6 +3,7 @@ import * as fs from 'fs'; import * as path from 'path'; import * as yaml from 'yaml-js'; import wu from 'wu'; +import Ajv from 'ajv'; import collect from '../src'; @@ -22,6 +23,14 @@ function run(title) { it('should provide expected types', () => { assert.deepEqual(actual.types, expected); }); + + it('should generate valid JSON schema', () => { + const ajv = new Ajv; + + ajv.validateSchema(actual.schema); + + assert.equal(ajv.errors, null); + }); } function detectCycles(obj: mixed, cycles: Set = new Set, objs: Set = new Set) {