11'use strict' ;
22
3- var validator = require ( 'is-my-json-valid' )
3+ var consolidate = require ( 'json-schema-consolidate' )
4+ , validator = consolidate ( 'jjv' , { allErrors : true , verbose : true } )
5+
6+ // , jjv = require('jjv')()
7+ // , Validator = require('jsonschema').Validator
8+ // , validator = new Validator
49 , assert = require ( 'assert' )
510 , metaSchema = require ( './meta_schema.json' )
611 , request = require ( 'request' )
712 , fs = require ( 'fs' )
813 , path = require ( 'path' ) ;
914
1015
16+ var ONLY = '' ;
17+
18+
1119describe ( 'JSONScript schema' , function ( ) {
1220 describe ( 'Meta-schema' , function ( ) {
1321 it ( 'should be the same as the meta-schema at json-schema.org (needs internet connection)' , function ( done ) {
@@ -27,17 +35,19 @@ describe('JSONScript schema', function() {
2735 loadSchemas ( ) ;
2836
2937 before ( function ( ) {
30- validateSchema = validator ( metaSchema , {
31- verbose : true ,
32- greedy : true
33- } ) ;
38+ validateSchema = validator . compile ( metaSchema ) ;
39+
40+ for ( var name in schemas )
41+ validator . addSchema ( schemas [ name ] , name ) ;
3442 } ) ;
3543
3644
3745 for ( var name in schemas ) testSchema ( name ) ;
3846
3947
4048 function testSchema ( name ) {
49+ if ( ONLY && ONLY != name ) return ;
50+
4151 describe ( name + ' schema' , function ( ) {
4252 var schema ;
4353 var specFile = name . replace ( '.' , '.spec.' ) ;
@@ -50,8 +60,8 @@ describe('JSONScript schema', function() {
5060
5161 it ( 'should be valid' , function ( ) {
5262 assert . equal ( schema . $schema , metaSchema . id ) ;
53- validateSchema ( schema ) ;
54- assert . equal ( validateSchema . errors , null ) ;
63+ var result = validateSchema ( schema ) ;
64+ assert . deepEqual ( result . errors , [ ] ) ;
5565 } ) ;
5666
5767
@@ -60,7 +70,7 @@ describe('JSONScript schema', function() {
6070 var validate ;
6171
6272 before ( function ( ) {
63- validate = getValidator ( schema ) ;
73+ validate = validator . compile ( schema ) ;
6474 } ) ;
6575
6676 it ( 'spec file should be array' , function ( ) {
@@ -70,33 +80,25 @@ describe('JSONScript schema', function() {
7080 if ( ! Array . isArray ( specs [ name ] ) ) return ;
7181
7282 specs [ name ] . forEach ( function ( s , index ) {
73- var schemaStr = s . schema ? objToString ( s . schema , 24 ) + ' :' : '' ;
83+ var schemaStr = s . schema ? objToString ( s . schema , 32 ) + ' :' : '' ;
7484 var itStr = objToString ( s . it , 48 ) ;
7585 var validStr = 'should' + ( s . isValid ? ' ' : ' NOT ' ) + 'be valid' ;
7686
7787 it ( [ schemaStr , itStr , validStr ] . join ( ' ' ) , function ( ) {
7888 assert . notStrictEqual ( s . it , undefined , 'item #' + index + ' should have "it" property' ) ;
7989 assert . equal ( typeof s . isValid , 'boolean' , 'item #' + index + ' should have "isValid" property' ) ;
80- var _validate = s . schema ? getValidator ( s . schema ) : validate ;
81- _validate ( s . it ) ;
82- var assertion = s . isValid ? 'equal' : 'notEqual' ;
83- assert [ assertion ] ( _validate . errors , null ) ;
90+ var _validate = s . schema ? validator . compile ( s . schema ) : validate ;
91+ var result = _validate ( s . it ) ;
92+
93+ var assertion = s . isValid ? 'deepEqual' : 'notDeepEqual' ;
94+ assert [ assertion ] ( result . errors , [ ] ) ;
8495 } ) ;
8596 } ) ;
8697 } ) ;
8798 } ) ;
8899 }
89100
90101
91- function getValidator ( schema ) {
92- return validator ( schema , {
93- schemas : schemas ,
94- verbose : true ,
95- greedy : true
96- } ) ;
97- }
98-
99-
100102 function objToString ( obj , maxLength ) {
101103 var str = JSON . stringify ( obj ) ;
102104 if ( str . length > maxLength + 3 )
0 commit comments