-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathrefactor.test.ts
More file actions
71 lines (70 loc) · 1.87 KB
/
refactor.test.ts
File metadata and controls
71 lines (70 loc) · 1.87 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
import dedent from 'dedent';
import { describe, expect, test } from 'vite-plus/test';
import { createCssModuleFileRefactor } from '../../src/language-service/feature/refactor.js';
import { createIFF } from '../test-util/fixture.js';
import { launchTsserver } from '../test-util/tsserver.js';
describe('Refactor', async () => {
const tsserver = launchTsserver();
const iff = await createIFF({
'a.tsx': '',
'b.ts': '',
'tsconfig.json': dedent`
{
"compilerOptions": { "jsx": "react-jsx" },
"cmkOptions": {
"enabled": true,
"dtsOutDir": "generated"
}
}
`,
});
await tsserver.sendUpdateOpen({
openFiles: [{ file: iff.paths['a.tsx'] }],
});
test.each([
{
name: 'a.tsx',
file: iff.paths['a.tsx'],
line: 1,
offset: 1,
expected: [createCssModuleFileRefactor],
},
{
name: 'b.ts',
file: iff.paths['b.ts'],
line: 1,
offset: 1,
expected: [],
},
])('Get Applicable Refactors for $name', async ({ file, line, offset, expected }) => {
const res = await tsserver.sendGetApplicableRefactors({
file,
line,
offset,
});
expect(res.body).toStrictEqual(expected);
});
test.each([
{
name: 'a.tsx',
file: iff.paths['a.tsx'],
line: 1,
offset: 1,
expected: [
{
fileName: iff.join('a.module.css'),
textChanges: [{ start: { line: 0, offset: 0 }, end: { line: 0, offset: 0 }, newText: '' }],
},
],
},
])('Get Edits For Refactor for $name', async ({ file, line, offset, expected }) => {
const res = await tsserver.sendGetEditsForRefactor({
refactor: createCssModuleFileRefactor.name,
action: createCssModuleFileRefactor.actions[0].name,
file,
line,
offset,
});
expect(res.body?.edits).toStrictEqual(expected);
});
});