-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
general.test.js
50 lines (43 loc) · 1.31 KB
/
general.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const Ajv = require('ajv')
const addFormats = require('ajv-formats')
const semver = require('semver')
const jsonSchemasLibrary = require('../src/index')
const ajv = new Ajv()
addFormats(ajv)
const schemas = Object.keys(jsonSchemasLibrary.user).map(key => {
return [jsonSchemasLibrary.user[key].name, jsonSchemasLibrary.user[key]]
})
describe('All Schema files validation', () => {
test.each(schemas)(
'Should %s contain the VALID schema',
(name, schema) => {
expect(() => ajv.compile(schema.schema)).not.toThrow()
}
)
test.each(schemas)(
'Should %s contain a VALID version semver compatible',
(name, schema) => {
const version = semver.valid(schema.version)
expect(version).not.toEqual(null)
}
)
test.each(schemas)(
'Should %s contain a VALID semver schema Compatibility',
(name, schema) => {
// At least 3 characters (1.x)
expect(schema.schemaCompatibility.length >= 3).toEqual(true)
}
)
test.each(schemas)(
'Should %s contain a VALID name',
(name, schema) => {
// At least 5 characters
expect(schema.name.length >= 5).toEqual(true)
}
)
})
describe('All Schema files validation', () => {
it('Should export a valid library to be consumed by other projects', () => {
expect(jsonSchemasLibrary).toMatchSnapshot()
})
})