Skip to content

Instantly share code, notes, and snippets.

@ottomata
Last active September 9, 2019 17:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ottomata/86ccdefe059de5a8bcf0f44c5e9e50c0 to your computer and use it in GitHub Desktop.
Save ottomata/86ccdefe059de5a8bcf0f44c5e9e50c0 to your computer and use it in GitHub Desktop.
function generateSchemaTests(title, majorVersion, schemaInfos) {
it(`All ${title} schemas should have title ${title} `, function() {
schemaInfos.forEach((info) => {
assert.equal(info.schema.title, title);
});
});
it(`All ${title} major version ${majorVersion} schemas should be ${majorVersion}.x.y`, function() {
schemaInfos.forEach((info) => {
assert.equal(semver.coerce(_.get(info.schema, '$id')).major, majorVersion);
});
});
// ... other tests and assertions here
// E.g. it('backwards compatible, etc.')
}
describe('Test Schema Conventions', function() {
let fixture;
before('Copying fixtures to temp directory and declaring tests', async function() {
// Copy the fixtures/ dir into a temp directory that is automatically
// cleaned up after each test.
fixture = testFixture();
await fixture.copy();
const schemaBasePath = fixture.resolve('schemas/');
const schemasByTitleAndMajor = await findSchemasByTitleAndMajor(schemaBasePath);
describe('Each schema should conform', function() {
_.keys(schemasByTitleAndMajor).forEach((title) => {
_.keys(schemasByTitleAndMajor[title]).forEach((majorVersion) => {
generateSchemaTests(
title,
majorVersion,
schemasByTitleAndMajor[title][majorVersion]
);
});
});
});
});
it.skip('This is a required placeholder to allow before() to work', function () { });
});
Test Schema Conventions
- This is a required placeholder to allow before() to work
Each schema should conform
✓ All basic schemas should have title basic
✓ All basic major version 1 schemas should be 1.x.y
✓ All common schemas should have title common
✓ All common major version 1 schemas should be 1.x.y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment