-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathtest-locals.js
48 lines (37 loc) · 1.22 KB
/
test-locals.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
const test = require('ava')
const join = require('path').join
const readSync = require('fs').readFileSync
const posthtml = require('posthtml')
const expressions = require('../lib')
const fixture = (file) => {
return readSync(join(__dirname, 'fixtures', `${file}.html`), 'utf8')
}
const expect = (file) => {
return readSync(join(__dirname, 'expect', `${file}.html`), 'utf8')
}
function process (t, name, options, log = false, plugins = [expressions(options)], processOptions = {}) {
return posthtml(plugins)
.process(fixture(name), processOptions)
.then((result) => {
log && console.log(result.html)
return clean(result.html)
})
.then((html) => {
t.is(html, expect(name).trim())
})
}
function clean (html) {
return html.replace(/[^\S\r\n]+$/gm, '').trim()
}
test('Basic', (t) => {
return process(t, 'script-locals')
})
test('Global Locals - setting global locals', (t) => {
return process(t, 'script-locals-global', { locals: { displayAge: true } })
})
test('Global Locals - no global locals informed', (t) => {
return process(t, 'script-locals-global-not-informed')
})
test('Remove script locals', (t) => {
return process(t, 'script-locals-remove', { removeScriptLocals: true })
})