Skip to content

Commit d429c4a

Browse files
committed
test: locals from script tag, issue #117
1 parent e0bafbe commit d429c4a

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

test/expect/script-locals.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script locals="">
2+
module.exports = {
3+
name: 'Scrum'
4+
}
5+
</script>
6+
7+
<div>My name: Scrum</div>

test/fixtures/script-locals.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script locals>
2+
module.exports = {
3+
name: 'Scrum'
4+
}
5+
</script>
6+
7+
<div>My name: {{name}}</div>

test/test-locals.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const test = require('ava')
2+
3+
const join = require('path').join
4+
const readSync = require('fs').readFileSync
5+
6+
const posthtml = require('posthtml')
7+
const expressions = require('../lib')
8+
9+
const fixture = (file) => {
10+
return readSync(join(__dirname, 'fixtures', `${file}.html`), 'utf8')
11+
}
12+
13+
const expect = (file) => {
14+
return readSync(join(__dirname, 'expect', `${file}.html`), 'utf8')
15+
}
16+
17+
function process (t, name, options, log = false, plugins = [expressions(options)], processOptions = {}) {
18+
return posthtml(plugins)
19+
.process(fixture(name), processOptions)
20+
.then((result) => {
21+
log && console.log(result.html)
22+
23+
return clean(result.html)
24+
})
25+
.then((html) => {
26+
t.is(html, expect(name).trim())
27+
})
28+
}
29+
30+
function clean (html) {
31+
return html.replace(/[^\S\r\n]+$/gm, '').trim()
32+
}
33+
34+
test('Basic', (t) => {
35+
return process(t, 'script-locals')
36+
})

0 commit comments

Comments
 (0)