/
pug.js
150 lines (129 loc) Β· 3.57 KB
/
pug.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
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
const assert = require('assert');
const path = require('path');
const fs = require('@parcel/fs');
const {bundle, assertBundleTree, normaliseNewlines} = require('./utils');
describe('pug', function() {
it('should support bundling HTML', async function() {
const b = await bundle(path.join(__dirname, '/integration/pug/index.pug'));
await assertBundleTree(b, {
name: 'index.html',
assets: ['index.pug'],
childBundles: [
{
type: 'png',
assets: ['100x100.png'],
childBundles: []
},
{
type: 'svg',
assets: ['icons.svg'],
childBundles: []
},
{
type: 'css',
assets: ['index.css'],
childBundles: [
{
type: 'map'
}
]
},
{
type: 'js',
assets: ['index.js'],
childBundles: [
{
type: 'map'
}
]
}
]
});
const files = await fs.readdir(path.join(__dirname, '/dist'));
const html = await fs.readFile(path.join(__dirname, '/dist/index.html'));
for (const file of files) {
const ext = file.match(/\.([0-9a-z]+)(?:[?#]|$)/i)[0];
if (file !== 'index.html' && ext !== '.map') {
assert(html.includes(file));
}
}
});
it('should support include and extends files', async function() {
const b = await bundle(
path.join(__dirname, '/integration/pug-include-extends/index.pug')
);
await assertBundleTree(b, {
name: 'index.html',
assets: ['index.pug']
});
const html = normaliseNewlines(
await fs.readFile(path.join(__dirname, '/dist/index.html'), 'utf-8')
);
const expect = normaliseNewlines(
await fs.readFile(
path.join(__dirname, '/integration/pug-include-extends/expect.html'),
'utf-8'
)
);
assert.equal(html, expect, 'Content mismatch');
});
it('should support variables', async function() {
const b = await bundle(
path.join(__dirname, '/integration/pug-var/index.pug')
);
await assertBundleTree(b, {
name: 'index.html',
assets: ['index.pug']
});
const html = await fs.readFile(
path.join(__dirname, '/dist/index.html'),
'utf-8'
);
assert(/src="\/?100x100.*.png"/.test(html));
});
it('should support mixins', async function() {
const b = await bundle(
path.join(__dirname, '/integration/pug-mixins/index.pug')
);
await assertBundleTree(b, {
name: 'index.html',
assets: ['index.pug']
});
const html = await fs.readFile(
path.join(__dirname, '/dist/index.html'),
'utf-8'
);
assert(html.includes('Greetings, Parcel'));
});
it('should support filters', async function() {
const b = await bundle(
path.join(__dirname, '/integration/pug-filters/index.pug')
);
await assertBundleTree(b, {
name: 'index.html',
assets: ['index.pug']
});
const html = await fs.readFile(
path.join(__dirname, '/dist/index.html'),
'utf-8'
);
assert(html.includes('FILTERED: Hello!'));
});
it('should minify HTML in production mode', async function() {
const b = await bundle(
path.join(__dirname, '/integration/pug-minify/index.pug'),
{
production: true
}
);
await assertBundleTree(b, {
name: 'index.html',
assets: ['index.pug']
});
const html = await fs.readFile(
path.join(__dirname, '/dist/index.html'),
'utf-8'
);
assert(html.includes('Minified'));
});
});