2015-05-26 04:11:36 +03:00
|
|
|
'use strict';
|
|
|
|
|
2015-07-24 12:23:40 +03:00
|
|
|
var jsonSchemaTest = require('json-schema-test')
|
|
|
|
, path = require('path');
|
2015-06-12 20:16:54 +03:00
|
|
|
|
2015-05-26 04:11:36 +03:00
|
|
|
|
2015-05-30 01:32:47 +03:00
|
|
|
var Ajv = require('../lib/ajv')
|
2015-06-19 13:39:48 +03:00
|
|
|
, ajv = Ajv({ beautify: true, _debug: false })
|
|
|
|
, fullAjv = Ajv({ allErrors: true, verbose: true, format: 'full', beautify: true, _debug: false });
|
2015-05-26 04:11:36 +03:00
|
|
|
|
2015-05-30 21:11:06 +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-05-30 21:11:06 +03:00
|
|
|
};
|
|
|
|
|
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'),
|
|
|
|
];
|
|
|
|
|
2015-06-19 13:39:48 +03:00
|
|
|
addRemoteRefs();
|
|
|
|
|
|
|
|
|
|
|
|
jsonSchemaTest([ ajv, fullAjv ], {
|
2015-07-24 12:23:40 +03:00
|
|
|
suites: testSuites(),
|
2015-06-19 13:39:48 +03:00
|
|
|
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'
|
2015-06-19 13:39:48 +03:00
|
|
|
],
|
|
|
|
cwd: __dirname,
|
|
|
|
hideFolder: 'draft4/'
|
2015-06-07 23:55:40 +03:00
|
|
|
});
|
2015-06-06 18:18:52 +03:00
|
|
|
|
|
|
|
|
2015-07-24 12:23:40 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-19 13:39:48 +03:00
|
|
|
function addRemoteRefs() {
|
|
|
|
for (var id in remoteRefs) {
|
|
|
|
ajv.addSchema(remoteRefs[id], id);
|
|
|
|
fullAjv.addSchema(remoteRefs[id], id);
|
|
|
|
}
|
2015-06-18 22:48:35 +03:00
|
|
|
|
2015-06-19 13:39:48 +03:00
|
|
|
ajv.addSchema(remoteRefsWithIds);
|
|
|
|
fullAjv.addSchema(remoteRefsWithIds);
|
2015-05-26 04:11:36 +03:00
|
|
|
}
|