ajv/spec/json-schema.spec.js

69 lines
2.4 KiB
JavaScript
Raw Permalink Normal View History

2015-05-26 04:11:36 +03:00
'use strict';
var jsonSchemaTest = require('json-schema-test')
2015-12-27 19:43:56 +03:00
, getAjvInstances = require('./ajv_instances')
, options = require('./ajv_options')
2016-12-03 22:26:30 +03:00
, suite = require('./browser_test_suite')
2016-10-04 23:16:18 +03:00
, after = require('./after_test');
var remoteRefs = {
2016-07-28 02:50:30 +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'),
'http://localhost:1234/folder/folderInteger.json': require('./JSON-Schema-Test-Suite/remotes/folder/folderInteger.json'),
2017-12-02 15:58:13 +03:00
'http://localhost:1234/name.json': require('./JSON-Schema-Test-Suite/remotes/name.json')
};
var SKIP = {
4: ['optional/zeroTerminatedFloats'],
2017-12-02 20:40:01 +03:00
7: [
'optional/content',
'format/idn-email',
'format/idn-hostname',
'format/iri',
'format/iri-reference'
]
};
runTest(getAjvInstances(options, {meta: false, schemaId: 'id'}), 4, typeof window == 'object'
? suite(require('./JSON-Schema-Test-Suite/tests/draft4/{**/,}*.json', {mode: 'list'}))
: './JSON-Schema-Test-Suite/tests/draft4/{**/,}*.json');
runTest(getAjvInstances(options, {meta: false}), 6, typeof window == 'object'
? suite(require('./JSON-Schema-Test-Suite/tests/draft6/{**/,}*.json', {mode: 'list'}))
: './JSON-Schema-Test-Suite/tests/draft6/{**/,}*.json');
runTest(getAjvInstances(options), 7, typeof window == 'object'
? suite(require('./JSON-Schema-Test-Suite/tests/draft7/{**/,}*.json', {mode: 'list'}))
: './JSON-Schema-Test-Suite/tests/draft7/{**/,}*.json');
function runTest(instances, draft, tests) {
2017-03-12 20:27:10 +03:00
instances.forEach(function (ajv) {
2017-12-02 16:12:55 +03:00
switch (draft) {
case 4:
ajv.addMetaSchema(require('../lib/refs/json-schema-draft-04.json'));
ajv._opts.defaultMeta = 'http://json-schema.org/draft-04/schema#';
break;
case 6:
ajv.addMetaSchema(require('../lib/refs/json-schema-draft-06.json'));
ajv._opts.defaultMeta = 'http://json-schema.org/draft-06/schema#';
break;
}
2017-03-12 20:27:10 +03:00
for (var id in remoteRefs) ajv.addSchema(remoteRefs[id], id);
});
jsonSchemaTest(instances, {
description: 'JSON-Schema Test Suite draft-0' + draft + ': ' + instances.length + ' ajv instances with different options',
suites: {tests: tests},
only: [],
skip: SKIP[draft],
assert: require('./chai').assert,
afterError: after.error,
afterEach: after.each,
cwd: __dirname,
hideFolder: 'draft' + draft + '/',
timeout: 120000
});
2015-05-26 04:11:36 +03:00
}