This repository has been archived by the owner on Jan 23, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
test.js
125 lines (106 loc) · 2.41 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
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
/* eslint-env mocha */
'use strict';
const path = require('path');
const assert = require('assert');
const Vinyl = require('vinyl');
const dust = require('.');
afterEach(() => {
dust({
config: {
whitespace: false,
amd: false,
cjs: false
}
});
});
it('should precompile Dust templates', cb => {
const stream = dust();
stream.on('data', file => {
assert.equal(file.relative.replace(/\\/g, '/'), 'fixture/fixture.js');
assert(/fixture/.test(file.contents.toString()));
cb();
});
stream.end(new Vinyl({
base: __dirname,
path: path.join(__dirname, 'fixture/fixture.html'),
contents: Buffer.from('*foo*')
}));
});
it('should support supplying custom name in a callback', cb => {
let i = 0;
const buffer = [];
const stream = dust({
name() {
return 'custom' + ++i;
}
});
stream.on('data', file => {
buffer.push(file.contents.toString());
});
stream.on('end', () => {
assert(buffer.length === 2);
assert(/custom1/.test(buffer[0]));
assert(/custom2/.test(buffer[1]));
cb();
});
stream.write(new Vinyl({
base: __dirname,
path: path.join(__dirname, 'fixture/fixture.html'),
contents: Buffer.from('*foo*')
}));
stream.write(new Vinyl({
base: __dirname,
path: path.join(__dirname, 'fixture/fixture2.html'),
contents: Buffer.from('*foo*')
}));
stream.end();
});
it('should leave whitespace on demand', cb => {
const stream = dust({
config: {
whitespace: true
}
});
stream.on('data', file => {
assert(/\\n/.test(file.contents.toString()));
cb();
});
stream.end(new Vinyl({
base: __dirname,
path: path.join(__dirname, 'fixture/fixture.html'),
contents: Buffer.from('*fo\no*')
}));
});
it('should should support AMD modules', cb => {
const stream = dust({
config: {
amd: true
}
});
stream.on('data', file => {
assert.equal(file.relative.replace(/\\/g, '/'), 'fixture/fixture.js');
assert(/define\("fixture"/.test(file.contents.toString()));
cb();
});
stream.end(new Vinyl({
base: __dirname,
path: path.join(__dirname, 'fixture/fixture.html'),
contents: Buffer.from('*foo*')
}));
});
it('should should support CJS modules', cb => {
const stream = dust({
config: {
cjs: true
}
});
stream.on('data', file => {
assert(/^module\.exports=function/.test(file.contents.toString()));
cb();
});
stream.end(new Vinyl({
base: __dirname,
path: path.join(__dirname, 'fixture/fixture.html'),
contents: Buffer.from('*foo*')
}));
});