-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
40 lines (32 loc) · 1.07 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
const path = require('path')
const fs = require('fs')
const { h: el } = require('preact')
const { render } = require('preact-render-to-string')
const { parse, generate, evaluate } = require('./index')
const props = Object.freeze({
attributes: {
content: 'I AM CONTENT',
level: 'I AM LEVEL',
}
})
for (const dir of fs.readdirSync('./examples')) {
const [ input, expected ] = [ 'input','expected' ].map(filename =>
fs.readFileSync(path.join('examples', dir, filename)).toString().trim()
)
// Compute HTM-powered element tree.
const inputTree = parse(input)
// Generate string representing the body of a Gutenberg save function.
const generatedCode = generate(inputTree)
// Evaluate that generated code into a usable Preact component.
const saveComponent = evaluate(generatedCode)
// Serialise dummy data.
const actual = render(el(saveComponent, props), {}, {pretty: true})
if (actual === expected) {
console.log(path.join('examples', dir), 'OK')
} else {
console.log(path.join('examples', dir), 'FAIL')
console.log(actual)
console.log(expected)
console.log()
}
}