/
syntax-errors.test.ts
37 lines (34 loc) · 1.07 KB
/
syntax-errors.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
import { 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('Syntax-Errors', () => {
it('should not format if attributes is not closed', () => {
const code: string = readFileSync(
resolve(__dirname, 'attributes-not-closed.pug'),
'utf8',
);
expect(() => {
format(code, { parser: 'pug', plugins: [plugin] });
}).toThrow();
});
it('should not format if pipeless script tag has syntax error', () => {
const code: string = readFileSync(
resolve(__dirname, 'pipeless-script-tag.pug'),
'utf8',
);
expect(() => {
format(code, { parser: 'pug', plugins: [plugin] });
}).toThrow();
});
it('should format non-JS script without syntax error', () => {
const code: string = readFileSync(
resolve(__dirname, 'scripts-with-non-js-contents.pug'),
'utf8',
);
expect(() => {
format(code, { parser: 'pug', plugins: [plugin] });
}).not.toThrow();
});
});