-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathtest.js
53 lines (50 loc) · 1.26 KB
/
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
51
52
53
var fs = require('fs')
var test = require('tape')
var validator = require('is-my-json-valid')
var parser = require('../')
var testGoodFiles = [
'simple',
'simple-required',
'simple-restrictions',
'simple-enum',
'simple-arrays',
'simple-deep',
'simple-no-title',
'simple-definition',
'simple-no-properties',
'bare-array',
'bare-boolean',
'bare-integer',
'bare-null',
'bare-number',
'bare-string',
'bare-string-enum',
'one-of',
'items-one-of',
'examples',
"default-properties"
]
test('Internal test that invalid JSON schemas are an error', function(t) {
var passed = false
try {
validator({
$schema: 'http://json-schema.org/draft-04/schema#',
title: 'Example Invalid Schema',
type: 'PROPERTY DOES NOT EXIST'
})
} catch (e) {
passed = true
}
t.ok(passed, 'exception is thrown for invalid JSON schema')
t.end()
})
test('All the files parse as expected.', function(t) {
testGoodFiles.forEach(function(file) {
var json = require('./schemas/' + file + '.json')
var markdown = fs.readFileSync('./test/markdown/' + file + '.md', 'utf8')
var parsed = parser(json)
validator(json) // assert that all our testable JSON schema files are valid
t.equal(parsed, markdown, 'markdown file "' + file + '" should match parser output')
})
t.end()
})