-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
112 lines (92 loc) · 2.54 KB
/
index.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
var vm = require('vm')
var co = require('co')
var mkdirp = require('mkdirp')
var assert = require('assert')
var resolve = require('component-resolver')
var Builder = require('component-builder')
var join = require('path').join
var runtime = require('..').runtime
var options = {
install: true
}
var output = '<html><head></head><body></body></html>'
function fixture(name) {
return join(__dirname, 'fixtures', name)
}
function build(nodes, options) {
return new Builder.scripts(nodes, options)
.use('scripts', Builder.plugins.js())
.use('jade', require('..')(options))
}
describe('jade', function () {
var tree
var js = Builder.scripts.require
it('should install', co(function* () {
tree = yield* resolve(fixture('jade'), options)
}))
it('should build', co(function* () {
js += yield build(tree).end();
}))
it('should execute', function () {
var ctx = vm.createContext()
vm.runInContext(js, ctx)
vm.runInContext('if (require("jade")() !== "'
+ output + '") throw new Error()', ctx)
})
})
describe('jade-runtime', function () {
var tree
var js = Builder.scripts.require
it('should install', co(function* () {
tree = yield* resolve(fixture('jade-runtime'), options)
}))
it('should build', co(function* () {
js += runtime
js += yield build(tree, {
runtime: true
}).end();
}))
it('should execute', function () {
var ctx = vm.createContext()
vm.runInContext(js, ctx)
vm.runInContext('if (require("jade-runtime")() !== "'
+ output + '") throw new Error()', ctx)
})
})
describe('local', function () {
var tree
var js = Builder.scripts.require
it('should install', co(function* () {
tree = yield* resolve(fixture('local'), options)
}))
it('should build', co(function* () {
js += runtime
js += yield build(tree, {
runtime: true
}).end();
}))
it('should execute', function () {
var ctx = vm.createContext()
vm.runInContext(js, ctx)
vm.runInContext('if (require("./lib/home")() !== "'
+ output + '") throw new Error()', ctx)
})
})
describe('jade-string', function () {
var tree
var js = Builder.scripts.require
it('should install', co(function* () {
tree = yield* resolve(fixture('jade'), options)
}))
it('should build', co(function* () {
js += yield build(tree, {
string: true
}).end();
}))
it('should execute', function () {
var ctx = vm.createContext()
vm.runInContext(js, ctx)
vm.runInContext('if (require("jade") !== "'
+ output + '") throw new Error()', ctx)
})
})