Comparing version 0.5.6 to 0.5.7
{ | ||
"name": "ajv", | ||
"version": "0.5.6", | ||
"version": "0.5.7", | ||
"description": "Another JSON schema Validator", | ||
@@ -32,2 +32,3 @@ "main": "lib/ajv.js", | ||
"js-beautify": "^1.5.6", | ||
"json-schema-test": "0.0.3", | ||
"mocha": "^2.2.5", | ||
@@ -34,0 +35,0 @@ "watch": "^0.16.0" |
'use strict'; | ||
var glob = require('glob') | ||
, path = require('path') | ||
, assert = require('assert'); | ||
var jsonSchemaTest = require('json-schema-test'); | ||
var ONLY_FILES, SKIP_FILES; | ||
ONLY_FILES = [ | ||
// '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_FILES = [ | ||
'optional/zeroTerminatedFloats', | ||
'schemas/complex' | ||
]; | ||
var DEBUG = false; | ||
var Ajv = require('../lib/ajv') | ||
, ajv = Ajv({ beautify: true, _debug: DEBUG }) | ||
, fullAjv = Ajv({ allErrors: true, verbose: true, format: 'full', beautify: true, _debug: DEBUG }); | ||
, ajv = Ajv({ beautify: true, _debug: false }) | ||
, fullAjv = Ajv({ allErrors: true, verbose: true, format: 'full', beautify: true, _debug: false }); | ||
@@ -47,73 +25,38 @@ var remoteRefs = { | ||
for (var id in remoteRefs) { | ||
ajv.addSchema(remoteRefs[id], id); | ||
fullAjv.addSchema(remoteRefs[id], id); | ||
} | ||
addRemoteRefs(); | ||
ajv.addSchema(remoteRefsWithIds); | ||
fullAjv.addSchema(remoteRefsWithIds); | ||
describe('Schema validation tests', function() { | ||
addTests('JSON-Schema tests draft4', './JSON-Schema-Test-Suite/tests/draft4/{**/,}*.json'); | ||
addTests('Advanced schema tests', './tests/{**/,}*.json'); | ||
jsonSchemaTest([ ajv, fullAjv ], { | ||
suites: { | ||
'JSON-Schema tests draft4': './JSON-Schema-Test-Suite/tests/draft4/{**/,}*.json', | ||
'Advanced schema tests': './tests/{**/,}*.json' | ||
}, | ||
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: [ | ||
'optional/zeroTerminatedFloats', | ||
'schemas/complex' | ||
], | ||
cwd: __dirname, | ||
hideFolder: 'draft4/' | ||
}); | ||
function addTests(description, testsPath) { | ||
describe(description, function() { | ||
var files = getTestFiles(testsPath); | ||
function addRemoteRefs() { | ||
for (var id in remoteRefs) { | ||
ajv.addSchema(remoteRefs[id], id); | ||
fullAjv.addSchema(remoteRefs[id], id); | ||
} | ||
files.forEach(function (file) { | ||
var filter = { | ||
skip: SKIP_FILES && SKIP_FILES.indexOf(file.name) >= 0, | ||
only: ONLY_FILES && ONLY_FILES.indexOf(file.name) >= 0 | ||
} | ||
skipOrOnly(filter, describe)(file.name, function() { | ||
var testSets = require(file.path); | ||
testSets.forEach(function (testSet) { | ||
skipOrOnly(testSet, describe)(testSet.description, function() { | ||
var validate, fullValidate; | ||
before(function() { | ||
validate = ajv.compile(testSet.schema); | ||
// console.log('validate', validate.toString()); | ||
// fullValidate = fullAjv.compile(testSet.schema); | ||
}); | ||
testSet.tests.forEach(function (test) { | ||
skipOrOnly(test, it)(test.description, function() { | ||
doTest(validate); | ||
// doTest(fullValidate); | ||
}); | ||
function doTest(validate) { | ||
var valid = validate(test.data); | ||
if (valid !== test.valid) console.log('result', valid, test.valid, validate.errors); | ||
assert.equal(valid, test.valid); | ||
if (valid) assert(validate.errors === null); | ||
else assert(validate.errors.length > 0); | ||
} | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
ajv.addSchema(remoteRefsWithIds); | ||
fullAjv.addSchema(remoteRefsWithIds); | ||
} | ||
function skipOrOnly(filter, func) { | ||
return filter.only ? func.only : filter.skip ? func.skip : func; | ||
} | ||
function getTestFiles(testsPath) { | ||
var files = glob.sync(testsPath, { cwd: __dirname }); | ||
return files.map(function (file) { | ||
var match = file.match(/(\w+\/)\w+\.json/) | ||
var folder = match ? match[1] : ''; | ||
if (folder == 'draft4/') folder = ''; | ||
return { path: file, name: folder + path.basename(file, '.json') }; | ||
}); | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
1
335274
7
152
8998