ajv/spec/json-schema.spec.js

87 lines
2.7 KiB
JavaScript
Raw Normal View History

2015-05-26 04:11:36 +03:00
'use strict';
var jsonSchemaTest = require('json-schema-test')
, path = require('path');
2015-05-26 04:11:36 +03:00
var Ajv = require(typeof window == 'object' ? 'ajv' : '../lib/ajv')
2015-08-16 02:59:28 +03:00
, ajv = Ajv({ beautify: true })
, verboseAjv = Ajv({ verbose: true, beautify: true })
2015-08-22 01:26:13 +03:00
, fullAjv = Ajv({ allErrors: true, verbose: true, format: 'full', beautify: true, jsonPointers: true });
2015-05-26 04:11:36 +03:00
var remoteRefs = {
2015-06-18 16:59:11 +03:00
// for JSON-Schema-Test-Suite
2015-05-31 15:26:54 +03:00
'http://localhost:1234/integer.json': require('./JSON-Schema-Test-Suite/remotes/integer.json'),
'http://localhost:1234/subSchemas.json': require('./JSON-Schema-Test-Suite/remotes/subSchemas.json'),
2015-06-18 16:59:11 +03:00
'http://localhost:1234/folder/folderInteger.json': require('./JSON-Schema-Test-Suite/remotes/folder/folderInteger.json'),
// for tests
'http://localhost:1234/name.json': require('./remotes/name.json')
};
2015-06-18 19:15:50 +03:00
var remoteRefsWithIds = [ // order is important
require('./remotes/bar.json'),
require('./remotes/foo.json'),
require('./remotes/buu.json'),
require('./remotes/tree.json'),
require('./remotes/node.json'),
require('./remotes/second.json'),
require('./remotes/first.json'),
2015-06-18 19:15:50 +03:00
];
var instances = [ ajv, fullAjv, verboseAjv ];
instances.forEach(addRemoteRefs);
jsonSchemaTest(instances, {
suites: testSuites(),
only: [
// 'type', 'not', 'allOf', 'anyOf', 'oneOf', 'enum',
// 'maximum', 'minimum', 'multipleOf', 'maxLength', 'minLength', 'pattern',
// 'properties', 'patternProperties', 'additionalProperties',
// 'dependencies', 'required',
// 'maxProperties', 'minProperties', 'maxItems', 'minItems',
// 'items', 'additionalItems', 'uniqueItems',
// 'optional/format', 'optional/bignum',
// 'ref', 'refRemote', 'definitions',
// 'schemas/complex', 'schemas/basic', 'schemas/advanced',
],
skip: [
2015-06-24 03:28:40 +03:00
'optional/zeroTerminatedFloats'
],
cwd: __dirname,
hideFolder: 'draft4/'
2015-06-07 23:55:40 +03:00
});
2015-06-06 18:18:52 +03:00
function testSuites() {
if (typeof window == 'object') {
var suites = {
'JSON-Schema tests draft4': require('./JSON-Schema-Test-Suite/tests/draft4/{**/,}*.json', {mode: 'hash'}),
'Advanced schema tests': require('./tests/{**/,}*.json', {mode: 'hash'})
};
for (var suiteName in suites) {
var suite = suites[suiteName];
var suiteArr = [];
for (var testSetName in suite)
suiteArr.push({ name: testSetName, test: suite[testSetName] });
suites[suiteName] = suiteArr;
}
} else {
var suites = {
'JSON-Schema tests draft4': './JSON-Schema-Test-Suite/tests/draft4/{**/,}*.json',
'Advanced schema tests': './tests/{**/,}*.json'
}
}
return suites;
}
function addRemoteRefs(ajv) {
for (var id in remoteRefs) {
ajv.addSchema(remoteRefs[id], id);
}
ajv.addSchema(remoteRefsWithIds);
2015-05-26 04:11:36 +03:00
}