forked from brunch/jade-brunch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
152 lines (122 loc) · 3.67 KB
/
Copy pathtest.js
File metadata and controls
152 lines (122 loc) · 3.67 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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
'use strict';
const expect = require('chai').expect;
const Plugin = require('./');
const jade = require('jade');
const sysPath = require('path');
const fs = require('fs');
describe('Plugin', () => {
let plugin;
beforeEach(() => {
plugin = new Plugin({paths: {root: '.'}});
});
it('should be an object', () => {
expect(plugin).to.be.ok;
});
it('should has #compile method', () => {
expect(plugin.compile).to.be.an.instanceof(Function);
});
it('should compile and produce valid result', () => {
const content = 'doctype html';
const expected = '<!DOCTYPE html>';
return plugin.compile({data: content, path: 'template.jade'}).then(data => {
expect(eval(data)()).to.equal(expected);
}, error => expect(error).not.to.be.ok);
});
it('should compile template string with data', () => {
const expected = '<!DOCTYPE html>' +
'<html lang="en">' +
'<title>Brunch is awesome!</title>' +
'</html>';
const staticContent = 'doctype html' +
'\nhtml(lang="en")' +
'\n title #{title}';
plugin = new Plugin({
paths: {
root: '.'
},
plugins: {
jade: {
locals: {
title: 'Brunch is awesome!'
}
}
}
});
return plugin.compileStatic({data: staticContent, path: 'template.jade'}).then(data => {
expect(data).to.equal(expected);
}, error => expect(error).not.to.be.ok);
});
describe('runtime', () => {
it('should include jade/runtime.js', () => {
expect(plugin.include).to.match(/jade\/runtime\.js$/);
});
it('jade/runtime.js should exist', () => {
expect(fs.existsSync(plugin.include[0])).to.be.ok;
});
});
describe('getDependencies', () => {
it('should output valid deps', done => {
const content = "\
include valid1\n\
include valid1.jade\n\
include ../../test/valid1\n\
include ../../test/valid1.jade\n\
include /valid3\n\
extends valid2\n\
extends valid2.jade\n\
include ../../test/valid2\n\
include ../../test/valid2.jade\n\
extends /valid4\n\
";
const expected = [
sysPath.join('valid1.jade'),
sysPath.join('app', 'valid3.jade'),
sysPath.join('valid2.jade'),
sysPath.join('app', 'valid4.jade'),
];
// progeny now only outputs actually found files by default
fs.mkdirSync('app');
expected.forEach(file => {
fs.writeFileSync(file, 'div');
});
plugin.getDependencies(content, 'template.jade', (error, dependencies) => {
expect(error).not.to.be.ok;
expect(dependencies).to.have.members(expected);
// clean up temp fixture files
expected.forEach(function(file) {
fs.unlinkSync(file);
});
fs.rmdirSync('app');
done();
});
});
});
describe('getDependenciesWithOverride', () => {
it('should output valid deps', done => {
const content = "\
include /valid3\n\
extends /valid4\n\
";
const expected = [
sysPath.join('custom', 'valid3.jade'),
sysPath.join('custom', 'valid4.jade'),
];
// progeny now only outputs actually found files by default
fs.mkdirSync('custom');
expected.forEach(file => {
fs.writeFileSync(file, 'div');
});
plugin = new Plugin({paths: {root: '.'}, plugins: {jade: {basedir: 'custom'}}});
plugin.getDependencies(content, 'template.jade', (error, dependencies) => {
expect(error).not.to.be.ok;
expect(dependencies).to.have.members(expected);
// clean up temp fixture files
expected.forEach(file => {
fs.unlinkSync(file);
});
fs.rmdirSync('custom');
done();
});
});
});
});