forked from node-swig/swig-templates
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtemplates.test.js
executable file
·67 lines (58 loc) · 1.72 KB
/
templates.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
const fs = require('fs');
const path = require('path');
const file = require('file');
const swig = require('../lib/swig');
const expect = require('expect.js');
const _ = require('lodash');
function isTest (f) {
return /\.test\.html$/.test(f);
}
function isExpectation (f) {
return /\.expectation\.html$/.test(f);
}
describe('Templates', function () {
const casefiles = [];
const locals = {
alpha: 'Nachos',
first: 'Tacos',
second: 'Burritos',
includefile: './includes.html',
bar: ['a', 'b', 'c']
};
let tests;
let expectations;
let cases;
file.walkSync(path.resolve(__dirname, 'cases'), function (start, dirs, files) {
_.each(files, function (f) {
return casefiles.push(path.resolve(start + '/' + f));
});
});
tests = _.filter(casefiles, isTest);
expectations = _.filter(casefiles, isExpectation);
cases = _.groupBy(tests.concat(expectations), function (f) {
return f.split('.')[0];
});
_.each(cases, function (files, c) {
const test = _.find(files, isTest);
const expectation = fs.readFileSync(_.find(files, isExpectation), 'utf8');
it(c, function () {
expect(swig.compileFile(test)(locals)).to.equal(expectation);
});
});
it('throw if circular extends are found', function () {
expect(function () {
swig.compileFile(
path.resolve(__dirname, 'cases-error/circular.test.html')
)();
}).to.throwError(/Illegal circular extends of ".*/);
});
it('throw with filename reporting', function () {
expect(function () {
swig.compileFile(
path.resolve(__dirname, 'cases-error/report-filename.test.html')
)();
}).to.throwError(
/in file .*tests\/cases-error\/report-filename-partial\.html/
);
});
});