-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathinvalid-syntax.test.ts
More file actions
53 lines (52 loc) · 1.58 KB
/
invalid-syntax.test.ts
File metadata and controls
53 lines (52 loc) · 1.58 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
import dedent from 'dedent';
import { describe, expect, test } from 'vite-plus/test';
import { createIFF } from './test-util/fixture.js';
import { formatPath, launchTsserver, normalizeDefinitions } from './test-util/tsserver.js';
describe('handle invalid syntax CSS without crashing', async () => {
const tsserver = launchTsserver();
const iff = await createIFF({
'index.ts': dedent`
import styles from './a.module.css';
styles.a_1;
`,
'a.module.css': dedent`
.a_1 { color: red; }
.a_2 {
`,
'tsconfig.json': dedent`
{
"compilerOptions": {},
"cmkOptions": {
"enabled": true,
"dtsOutDir": "generated"
}
}
`,
});
await tsserver.sendUpdateOpen({
openFiles: [{ file: iff.paths['index.ts'] }],
});
test('can get definition and bound span', async () => {
const res = await tsserver.sendDefinitionAndBoundSpan({
file: iff.paths['index.ts'],
line: 2,
offset: 8,
});
const expected = [
{
file: formatPath(iff.paths['a.module.css']),
start: { line: 1, offset: 2 },
end: { line: 1, offset: 5 },
contextStart: { line: 1, offset: 1 },
contextEnd: { line: 1, offset: 21 },
},
];
expect(normalizeDefinitions(res.body?.definitions ?? [])).toStrictEqual(normalizeDefinitions(expected));
});
test('does not report syntactic diagnostics', async () => {
const res = await tsserver.sendSyntacticDiagnosticsSync({
file: iff.paths['a.module.css'],
});
expect(res.body).toMatchInlineSnapshot(`[]`);
});
});