-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-suite-runner.js
53 lines (47 loc) · 1.47 KB
/
test-suite-runner.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
const debug = require('debug')(__filename.split('/').slice(-1).join())
const test = require('tape')
const { TestCase } = require('./schema-for-tests')
const { mapper } = require('.')
const fs = require('fs')
const jsonic = require('jsonic')
const tm = mapper()
tm.add(TestCase)
const text = fs.readFileSync('test-suite.psdad')
const tests = [...tm.parse(text)]
/* to manually add some in js syntax...
tests.push([
new TestCase({
template: 'Hello, [string name].',
document: 'Hello, Sandro.',
json: '{\n "name": "Sandro"\n}'
})
])
*/
const str = tm.stringify(tests)
fs.appendFileSync('test-suite-echo.psdad', str)
let counter = 0
for (const testCase of tests) {
counter++
console.error('test case %d, %o', counter, testCase)
test('ts' + counter, t => {
const m = mapper()
console.log('template=%o', testCase.template)
m.add(Object, testCase.template)
const out = m.parse(testCase.document)
const sfile = `out-suite/t${counter}-schema.js`
const dfile = `out-suite/t${counter}-data.psdad`
fs.writeFileSync(sfile, `
class X {}
X.definition = ${JSON.stringify(testCase.template)}
module.exports = {X}
`)
fs.writeFileSync(dfile, testCase.document)
t.comment(`RUN: check --schema ${sfile} ${dfile}`)
const expected = jsonic(testCase.json)
const o2 = Object.assign({}, out[0])
delete o2._forwardTo // why is this here? wtf.
t.deepEqual(o2, expected)
t.end()
})
}
if (counter === 0) console.error('no tests recognized in suite')