-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathinvalid-css-syntax.test.ts
More file actions
58 lines (51 loc) · 2.05 KB
/
invalid-css-syntax.test.ts
File metadata and controls
58 lines (51 loc) · 2.05 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
54
55
56
57
58
import dedent from 'dedent';
import { describe, expect, test } from 'vite-plus/test';
import { buildStylesImport, buildTSConfigJSON } from '../src/test/builder.js';
import { setupFixture } from './test-util/fixture.js';
import { formatPath, launchTsserver, normalizeDefinitions } from './test-util/tsserver.js';
const tsserver = launchTsserver();
describe.each([{ namedExports: false }, { namedExports: true }])('namedExports: $namedExports', ({ namedExports }) => {
test('resolves Go to Definition on a valid token even when later rules contain invalid syntax', async () => {
const { iff, getLoc, getRange } = await setupFixture({
'tsconfig.json': buildTSConfigJSON({ cmkOptions: { namedExports } }),
'index.ts': dedent`
${buildStylesImport('./a.module.css', { namedExports })}
styles.a_1;
`,
'a.module.css': dedent`
.a_1 { color: red; }
.a_2 {
`,
});
await tsserver.sendUpdateOpen({ openFiles: [{ file: iff.paths['index.ts'] }] });
const res = await tsserver.sendDefinitionAndBoundSpan({
file: iff.paths['index.ts'],
...getLoc('index.ts', 'a_1'),
});
const { start: contextStart, end: contextEnd } = getRange('a.module.css', '.a_1 { color: red; }');
expect(normalizeDefinitions(res.body?.definitions ?? [])).toStrictEqual(
normalizeDefinitions([
{
file: formatPath(iff.paths['a.module.css']),
...getRange('a.module.css', 'a_1'),
contextStart,
contextEnd,
},
]),
);
});
test('reports no syntactic diagnostics for a CSS module with parse errors', async () => {
const { iff } = await setupFixture({
'tsconfig.json': buildTSConfigJSON({ cmkOptions: { namedExports } }),
'a.module.css': dedent`
.a_1 { color: red; }
.a_2 {
`,
});
await tsserver.sendUpdateOpen({ openFiles: [{ file: iff.paths['a.module.css'] }] });
const res = await tsserver.sendSyntacticDiagnosticsSync({
file: iff.paths['a.module.css'],
});
expect(res.body).toStrictEqual([]);
});
});