Skip to content

test: run draft-04/06 tests with ajv #169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
language: python
python: "2.7"
install: pip install tox
script: tox
node_js: "6"
install:
- pip install tox
- npm install
script:
- tox
- npm test
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
JSON Schema Test Suite [![Build Status](https://travis-ci.org/json-schema-org/JSON-Schema-Test-Suite.png?branch=develop)](https://travis-ci.org/json-schema-org/JSON-Schema-Test-Suite)
JSON Schema Test Suite [![Build Status](https://travis-ci.org/json-schema-org/JSON-Schema-Test-Suite.svg?branch=master)](https://travis-ci.org/json-schema-org/JSON-Schema-Test-Suite)
======================

This repository contains a set of JSON objects that implementors of JSON Schema
Expand Down Expand Up @@ -165,5 +165,5 @@ Contributing
If you see something missing or incorrect, a pull request is most welcome!

There are some sanity checks in place for testing the test suite. You can run
them with `bin/jsonschema_suite check` or `tox`. They will be run automatically by
them with `bin/jsonschema_suite check && npm test` or `tox && npm test`. They will be run automatically by
[Travis CI](https://travis-ci.org/) as well.
31 changes: 31 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';

var Ajv = require('ajv');
var jsonSchemaTest = require('json-schema-test');
var assert = require('assert');

var refs = {
'http://localhost:1234/integer.json': require('./remotes/integer.json'),
'http://localhost:1234/subSchemas.json': require('./remotes/subSchemas.json'),
'http://localhost:1234/folder/folderInteger.json': require('./remotes/folder/folderInteger.json')
};

runTest(4);
runTest(6);

function runTest(draft) {
var opts = {addUsedSchema: false};
if (draft == 4) opts.meta = false;
var ajv = new Ajv(opts);
ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json'));
if (draft == 4) ajv._opts.defaultMeta = 'http://json-schema.org/draft-04/schema#';
for (var uri in refs) ajv.addSchema(refs[uri], uri);

jsonSchemaTest(ajv, {
description: 'Test suite draft-0' + draft,
suites: {tests: './tests/draft' + draft + '/{**/,}*.json'},
skip: draft == 4 ? ['optional/zeroTerminatedFloats'] : [],
cwd: __dirname,
hideFolder: 'tests/'
});
}
28 changes: 28 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "json-schema-test-suite",
"version": "0.1.0",
"description": "A language agnostic test suite for the JSON Schema specifications",
"main": "index.js",
"scripts": {
"test": "mocha index.js -R spec"
},
"repository": {
"type": "git",
"url": "git+https://github.com/json-schema-org/JSON-Schema-Test-Suite.git"
},
"keywords": [
"json-schema",
"tests"
],
"author": "http://json-schema.org",
"license": "MIT",
"bugs": {
"url": "https://github.com/json-schema-org/JSON-Schema-Test-Suite/issues"
},
"homepage": "https://github.com/json-schema-org/JSON-Schema-Test-Suite#readme",
"devDependencies": {
"ajv": "^5.0.4-beta.0",
"json-schema-test": "^1.3.0",
"mocha": "^3.2.0"
}
}