-
Notifications
You must be signed in to change notification settings - Fork 429
/
hulk.js
66 lines (59 loc) · 2.84 KB
/
hulk.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
var exec = require('child_process').exec
, assert = require('assert')
, fs = require('fs')
, rimraf = require('rimraf')
, path = require('path')
, Hogan = require('../lib/hogan.js');
// help text
exec('node bin/hulk', function (error, stdout, stderr) {
if (error) throw error;
assert(typeof stdout == 'string', 'it should have help text.');
assert(/USAGE/.test(stdout), 'has USAGE text');
assert(/NOTE/.test(stdout), 'has NOTE text about wildcard');
});
// wrapper options: --wrapper amd
exec('node bin/hulk --wrapper amd test/templates/*', function (error, stdout, stderr) {
if (error) throw error;
var define = function (name, dep, template) {
template = template(Hogan);
assert(/list$/.test(name), 'name path ends in list');
assert(dep[0] === 'hogan.js', 'Make sure the "hogan" dependency is passed');
assert(typeof template == 'object', 'defined a templates.list object');
assert(typeof template.r == 'function', 'defined a templates.list.r function');
};
eval(stdout);
});
// wrapper options: --outputdir
exec('node bin/hulk --outputdir dist/foo test/templates/*', function (error, stdout, stderr) {
if (error) throw error;
assert(fs.existsSync('dist/foo'), 'dist/foo directory created');
assert(fs.existsSync('dist/foo/list.js'), 'dist/foo/list.js file created');
rimraf.sync('dist');
});
// templates wildcard
exec('node bin/hulk test/templates/*', function (error, stdout, stderr) {
if (error) throw error;
eval(stdout);
assert(typeof templates == 'object', 'defineed a templates object');
assert(typeof templates.list == 'object', 'defined a templates.list object');
assert(typeof templates.list.r == 'function', 'defined a templates.list.r function');
assert(templates.list.r() == '<ul>\n<li></li>\n<li></li>\n<li></li>\n<li></li>\n<li></li>\n<li></li>\n</ul>');
});
// templates wildcard w/ extension
exec('node bin/hulk test/templates/*.mustache', function (error, stdout, stderr) {
if (error) throw error;
eval(stdout);
assert(typeof templates == 'object', 'defineed a templates object');
assert(typeof templates.list == 'object', 'defined a templates.list object');
assert(typeof templates.list.r == 'function', 'defined a templates.list.r function');
assert(templates.list.r() == '<ul>\n<li></li>\n<li></li>\n<li></li>\n<li></li>\n<li></li>\n<li></li>\n</ul>');
});
// templates single file
exec('node bin/hulk test/templates/list.mustache', function (error, stdout, stderr) {
if (error) throw error;
eval(stdout);
assert(typeof templates == 'object', 'defineed a templates object');
assert(typeof templates.list == 'object', 'defined a templates.list object');
assert(typeof templates.list.r == 'function', 'defined a templates.list.r function');
assert(templates.list.r() == '<ul>\n<li></li>\n<li></li>\n<li></li>\n<li></li>\n<li></li>\n<li></li>\n</ul>');
});