Validate generated json schemas in the tests

master
Paul Loyd 2017-12-16 19:58:45 +03:00
parent 44e36854f3
commit c6fdf55ff2
3 changed files with 19 additions and 0 deletions

9
declarations/ajv.js Normal file
View File

@ -0,0 +1,9 @@
declare module 'ajv' {
declare export default class Ajv {
errors: {message: string}[];
constructor(): void;
validateSchema(schema: mixed): boolean;
}
}

View File

@ -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",

View File

@ -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<mixed> = new Set, objs: Set<mixed> = new Set) {