-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathcompletion.test.ts
More file actions
97 lines (95 loc) · 2.89 KB
/
completion.test.ts
File metadata and controls
97 lines (95 loc) · 2.89 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
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
import { join } from '@css-modules-kit/core';
import dedent from 'dedent';
import { describe, expect, test } from 'vite-plus/test';
import { createIFF } from '../test-util/fixture.js';
import { launchTsserver, normalizeCompletionEntry } from '../test-util/tsserver.js';
const reactDtsPath = join(require.resolve('@types/react/package.json'), '../index.d.ts');
describe('Completion', async () => {
const tsserver = launchTsserver();
const iff = await createIFF({
'a.tsx': dedent`
styles;
const jsx = <div className />;
`,
'b.tsx': dedent`
import styles from './b.module.css';
const jsx = <div className />;
`,
'a.module.css': '',
'b.module.css': '',
// Generated files should be excluded from import statement suggestions
'generated/generated.module.css.d.ts': dedent`
const styles: {};
export default styles;
`,
'tsconfig.json': dedent`
{
"compilerOptions": {
"jsx": "react-jsx",
"types": ["${reactDtsPath}"]
},
"cmkOptions": {
"enabled": true,
"dtsOutDir": "generated"
}
}
`,
});
await tsserver.sendUpdateOpen({
openFiles: [{ file: iff.paths['tsconfig.json'] }],
});
await tsserver.sendConfigure({
preferences: {
includeCompletionsForModuleExports: true,
includeCompletionsWithSnippetText: true,
includeCompletionsWithInsertText: true,
jsxAttributeCompletionStyle: 'auto',
quotePreference: 'single',
},
});
test.each([
{
name: 'styles',
entryName: 'styles',
file: iff.paths['a.tsx'],
line: 1,
offset: 7,
expected: [
{ name: 'styles', sortText: '0', source: './a.module.css' },
{ name: 'styles', sortText: '16', source: './b.module.css' },
],
},
{
name: "className with `quotePreference: 'double'`",
entryName: 'className',
quotePreference: 'double' as const,
file: iff.paths['a.tsx'],
line: 2,
offset: 27,
expected: [{ name: 'className', insertText: 'className={$1}', sortText: expect.anything() }],
},
{
name: "className with `quotePreference: 'single'`",
entryName: 'className',
quotePreference: 'single' as const,
file: iff.paths['b.tsx'],
line: 2,
offset: 27,
expected: [{ name: 'className', insertText: 'className={$1}', sortText: expect.anything() }],
},
])('Completions for $name', async ({ entryName, quotePreference, file, line, offset, expected }) => {
await tsserver.sendConfigure({
preferences: {
quotePreference: quotePreference ?? 'auto',
},
});
const res = await tsserver.sendCompletionInfo({
file,
line,
offset,
});
expect(normalizeCompletionEntry(res.body?.entries.filter((entry) => entry.name === entryName) ?? [])).toStrictEqual(
normalizeCompletionEntry(expected),
);
});
});