Coder Social home page Coder Social logo

schematest.js's Introduction

SchemaTest.js

Summary

A quick Javscript library designed for Node.js that can test XML and JSON files against formal Schema and based on the validation status run callbacks.

It uses the Ajv JSON Schema validator for JSON, and the xmllint command line tool for XML (which supports XML Schema and RELAX NG.)

Requirements

  • Node.js, the Javascript runtime.
  • npm, the Node.js package manager.
  • xmllint, a command line tool used to perform XML Schema validation.

Optional dependencies

  • jsdoc, only needed if you want to build the API documentation.

Usage for JSON Validation

let TestJSON = require('schematest').TestJSON;
let testjson = new TestJSON(
{
  baseSchemaUri: 'http://my.test.com/schema',
  testPaths: ['./tests/json'],
  schemaPaths: ['./tests/json/schema'],
  preloadSchema: true,
  onSuccess: function (test, tname, tfile)
  {
    console.log("PASSED", tfile, tname);
  },
  onFailure: function (test, tname, tfile, err)
  {
    console.log("FAILED", tfile, tname, err);
  },
});

let tests =
{
  test1:
  {
    schemaUri: 'document.json',
    files:
    {
      'valid_document.json': true,
      'invalid_document.json': false,
      // More files here.
    },
  },
  // More tests here.
};

testjson.runTests(tests);

Usage for XML Validation

let TestXML = require('schematest').TestXML;
let testxml = new TestXML(
{
  testPaths: ['./tests/xml'],
  schemaPaths: ['./tests/xml/schema'],
  onSuccess: function (test, tname, tfile)
  {
    console.log("PASSED", tfile, tname);
  },
  onFailure: function (test, tname, tfile, err)
  {
    console.log("FAILED", tfile, tname, err);
  },
});

let tests =
{
  test1:
  { // Test using XML Schema (the default).
    schemaFile: 'document.xsd',
    files:
    {
      'valid_document.xml': true,
      'invalid_document.xml': false,
      // More files here.
    },
  },
  test2:
  { // Test using RELAX NG.
    relax: true,
    schemaFile: 'document.rng',
    files:
    {
      'valid_document.xml': true,
      'invalid_document.xml': false,
      // More files here.
    },
  },
  // More tests here.
};

testxml.runTests(tests);

API Documentation

You can build the API documentation using jsdoc, which expects the 'markdown' plugin to be present.

A minimalistic version with default templates can be generated using:

npm run build-docs

Feel free to customize the .jsdoc.json file to your liking first.

Official URLs

This library can be found in two places:

Author

Timothy Totten [email protected]

License

MIT

schematest.js's People

Watchers

Timothy Totten avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.