index.test.js
1.1 KB
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
var assert = require('assert');
var fs = require('fs');
var link = require('../');
function testDir (dir) {
fs.readdirSync(dir).forEach(function (name) {
if (!/\.input\.json$/.test(name)) return;
test(name, function () {
var actual = link(JSON.parse(fs.readFileSync(dir + '/' + name, 'utf8')));
expect(actual).toMatchSnapshot();
});
});
}
function testDirError (dir) {
fs.readdirSync(dir).forEach(function (name) {
if (!/\.input\.json$/.test(name)) return;
test(name, function () {
var input = JSON.parse(fs.readFileSync(dir + '/' + name, 'utf8'));
var err;
try {
link(input);
} catch (ex) {
err = {
msg: ex.msg,
code: ex.code,
line: ex.line
};
}
if (!err) throw new Error('Expected error')
expect(err).toMatchSnapshot();
});
});
}
describe('cases from pug', function () {
testDir(__dirname + '/cases');
});
describe('special cases', function () {
testDir(__dirname + '/special-cases');
});
describe('error handling', function () {
testDirError(__dirname + '/errors');
});