-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more subtype schema tests, improve test README, minor improvements
- Loading branch information
Showing
8 changed files
with
135 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const fs = require('fs'); | ||
const $RefParser = require("@apidevtools/json-schema-ref-parser"); | ||
const { checkJsonSchema, getAjv, isObject, normalizeString } = require('./testHelpers'); | ||
|
||
test("File subtype-schemas.json", async () => { | ||
let schema; | ||
let fileContent; | ||
try { | ||
fileContent = fs.readFileSync('../meta/subtype-schemas.json'); | ||
schema = JSON.parse(fileContent); | ||
} catch(err) { | ||
console.error("The file for subtypes is invalid and can't be read:"); | ||
console.error(err); | ||
expect(err).toBeUndefined(); | ||
} | ||
|
||
expect(isObject(schema)).toBeTruthy(); | ||
expect(isObject(schema.definitions)).toBeTruthy(); | ||
|
||
// lint: Check whether the file is correctly JSON formatted | ||
expect(normalizeString(JSON.stringify(schema, null, 4))).toEqual(normalizeString(fileContent.toString())); | ||
|
||
// Is JSON Schema valid? | ||
checkJsonSchema(await getAjv(), schema); | ||
|
||
// is everything dereferencable? | ||
let subtypes = await $RefParser.dereference(schema, { dereference: { circular: "ignore" } }); | ||
expect(isObject(subtypes)).toBeTruthy(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const $RefParser = require("@apidevtools/json-schema-ref-parser"); | ||
const { checkDescription, checkSpelling, isObject } = require('./testHelpers'); | ||
|
||
// I'd like to run the tests for each subtype individually instead of in a loop, | ||
// but jest doesn't support that, so you need to figure out yourself what is broken. | ||
// The console.log in afterAll ensures we have a hint of which process was checked last | ||
|
||
// Load and dereference schemas | ||
let subtypes = {}; | ||
let lastTest = null; | ||
let testsCompleted = 0; | ||
beforeAll(async () => { | ||
subtypes = await $RefParser.dereference('../meta/subtype-schemas.json', { dereference: { circular: "ignore" } }); | ||
return subtypes; | ||
}); | ||
|
||
afterAll(async () => { | ||
if (testsCompleted != Object.keys(subtypes.definitions).length) { | ||
console.log('The schema the test has likely failed for: ' + lastTest); | ||
} | ||
}); | ||
|
||
test("Schemas in subtype-schemas.json", () => { | ||
// Each schema must contain at least a type, subtype, title and description | ||
for(let name in subtypes.definitions) { | ||
let schema = subtypes.definitions[name]; | ||
lastTest = name; | ||
|
||
// Schema is object | ||
expect(isObject(schema)).toBeTruthy(); | ||
|
||
// Type is array with an element or a stirng | ||
expect((Array.isArray(schema.type) && schema.type.length > 0) || typeof schema.type === 'string').toBeTruthy(); | ||
|
||
// Subtype is a string | ||
expect(typeof schema.subtype === 'string').toBeTruthy(); | ||
|
||
// Check title | ||
expect(typeof schema.title === 'string').toBeTruthy(); | ||
// lint: Summary should be short | ||
expect(schema.title.length).toBeLessThan(60); | ||
// lint: Summary should not end with a dot | ||
expect(/[^\.]$/.test(schema.title)).toBeTruthy(); | ||
checkSpelling(schema.title, schema); | ||
|
||
// Check description | ||
expect(typeof schema.description).toBe('string'); | ||
// lint: Description should be longer than a summary | ||
expect(schema.description.length).toBeGreaterThan(60); | ||
checkDescription(schema.description, schema); | ||
|
||
testsCompleted++; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters