/
pug.test.ts
52 lines (48 loc) · 1.47 KB
/
pug.test.ts
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
import { readdirSync, readFileSync } from 'node:fs';
import { resolve } from 'node:path';
import { format } from 'prettier';
import { plugin } from 'src/index';
import { describe, expect, it } from 'vitest';
describe('Pug Tests', () => {
const filenames: string[] = readdirSync(resolve(__dirname), 'utf8');
const ignores: string[] = [
'attrs.pug',
'attrs.js.pug',
'comments.pug',
'escaping-class-attribute.pug',
'filters.coffeescript.pug',
'filters.include.pug',
'inheritance.extend.mixins.pug',
'inline-block-comment.pug',
'inline-tag.pug',
'layout.append.without-block.pug',
'layout.multi.append.prepend.block.pug',
'layout.prepend.without-block.pug',
'mixin.merge.pug',
'tags.self-closing.pug',
'template.pug',
'text.pug',
];
for (const filename of filenames) {
if (filename.endsWith('.formatted.pug')) {
const unformattedFilename: string = filename.replace('.formatted', '');
if (!ignores.includes(unformattedFilename)) {
it(unformattedFilename, () => {
const expected: string = readFileSync(
resolve(__dirname, filename),
'utf8',
);
const code: string = readFileSync(
resolve(__dirname, unformattedFilename),
'utf8',
);
const actual: string = format(code, {
parser: 'pug',
plugins: [plugin],
});
expect(actual).toBe(expected);
});
}
}
}
});