-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest.js
88 lines (66 loc) · 2.3 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
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
var assert, ladon;
assert = require('assert');
ladon = require('./ladon');
describe ('ladon', function () {
it ('Should provide a parser', function () {
assert(ladon.parser);
});
it ('Should quote a string', function () {
assert.equal('"test"', ladon.quote('test'));
});
it ('Should render a template with variables', function () {
var filename, rendered, template;
filename = '/home/dan/books/test.txt';
template = 'FULLPATH';
rendered = ladon.render(filename, 10, false, template);
assert.equal(filename, rendered);
template = 'RELDIR/BASENAME.EXT';
rendered = ladon.render(filename, 10, false, template);
assert.equal('books/test.txt', rendered);
template = 'RELPATH RELPATH';
rendered = ladon.render(filename, 10, true, template);
assert.equal('"books/test.txt" "books/test.txt"', rendered);
});
it ('Should return a help string', function () {
assert(ladon.parser.help());
});
it ('Should require at least a glob and command', function (done) {
var showHelp = ladon.parser.showHelp;
ladon.parser.showHelp = function () {};
ladon.run({'_':[]}, function (err) {
ladon.parser.showHelp = showHelp;
assert(err);
done();
});
});
it ('Should run commands', function (done) {
var argv, child_process, glob, tmp = {};
argv = {
processes: 2,
_: ['*.js', 'echo', 'FULLPATH']
};
// Mock globbing
glob = require('glob');
tmp.Glob = glob.Glob;
glob.Glob = function (globString, options, globDone) {
tmp.GlobCalled = true;
globDone(null, ['test.js', 'test2.js']);
return {};
};
// Mock exec
child_process = require('child_process');
tmp.exec = child_process.exec;
child_process.exec = function (cmd, execDone) {
tmp.execCalled = true;
execDone(null, '', '');
};
ladon.run(argv, function (err) {
glob.Glob = tmp.Glob;
child_process.exec = tmp.exec;
if (err) return done(err);
assert(tmp.GlobCalled);
assert(tmp.execCalled);
done();
});
});
});