-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
render-helper.js
56 lines (48 loc) · 1.36 KB
/
render-helper.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
var fs = require('fs');
var path = require('path');
var _files = path.join(__dirname, '_files');
function getContents (testName, ext) {
try {
return fs.readFileSync(path.join(_files, testName + '.' + ext), 'utf8');
} catch (ex) {
return null;
}
}
function getView (testName) {
var view = getContents(testName, 'js');
if (!view) view = getContents(testName, 'cjs');
if (!view) throw new Error('Cannot find view for test "' + testName + '"');
return view;
}
function getPartial (testName) {
try {
return getContents(testName, 'partial');
} catch (error) {
// No big deal. Not all tests need to test partial support.
}
}
// You can put the name of a specific test to run in the TEST environment
// variable (e.g. TEST=backslashes mocha test/render-test.js)
var testToRun = process.env.TEST;
var testNames;
if (testToRun) {
testNames = testToRun.split(',');
} else {
testNames = fs.readdirSync(_files).filter(function (file) {
return (/\.c?js$/).test(file);
}).map(function (file) {
return path.basename(file).replace(/\.c?js$/, '');
});
}
function getTest (testName) {
return {
name: testName,
view: getView(testName),
template: getContents(testName, 'mustache'),
partial: getPartial(testName),
expect: getContents(testName, 'txt')
};
}
exports.getTests = function getTests () {
return testNames.map(getTest);
};