-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathrefactor.test.ts
More file actions
83 lines (70 loc) · 2.74 KB
/
refactor.test.ts
File metadata and controls
83 lines (70 loc) · 2.74 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
import { describe, expect, test } from 'vite-plus/test';
import { createCssModuleFileRefactor } from '../../src/language-service/feature/refactor.js';
import { buildTSConfigJSON } from '../../src/test/builder.js';
import { setupFixture } from '../test-util/fixture.js';
import { launchTsserver } from '../test-util/tsserver.js';
const tsserver = launchTsserver();
describe('Get Applicable Refactors', () => {
test('offers Create CSS Module file for a component file when no paired CSS module exists', async () => {
const { iff } = await setupFixture({
'tsconfig.json': buildTSConfigJSON({ compilerOptions: { jsx: 'react-jsx' } }),
'a.tsx': '',
});
await tsserver.sendUpdateOpen({ openFiles: [{ file: iff.paths['a.tsx'] }] });
const res = await tsserver.sendGetApplicableRefactors({
file: iff.paths['a.tsx'],
line: 1,
offset: 1,
});
expect(res.body).toStrictEqual([createCssModuleFileRefactor]);
});
test('omits Create CSS Module file for a non-component file', async () => {
const { iff } = await setupFixture({
'tsconfig.json': buildTSConfigJSON(),
'a.ts': '',
});
await tsserver.sendUpdateOpen({ openFiles: [{ file: iff.paths['a.ts'] }] });
const res = await tsserver.sendGetApplicableRefactors({
file: iff.paths['a.ts'],
line: 1,
offset: 1,
});
expect(res.body).toStrictEqual([]);
});
test('omits Create CSS Module file when the paired CSS module already exists', async () => {
const { iff } = await setupFixture({
'tsconfig.json': buildTSConfigJSON({ compilerOptions: { jsx: 'react-jsx' } }),
'a.tsx': '',
'a.module.css': '',
});
await tsserver.sendUpdateOpen({ openFiles: [{ file: iff.paths['a.tsx'] }] });
const res = await tsserver.sendGetApplicableRefactors({
file: iff.paths['a.tsx'],
line: 1,
offset: 1,
});
expect(res.body).toStrictEqual([]);
});
});
describe('Get Edits For Refactor', () => {
test('emits an edit that creates a new empty CSS module file paired with the component file', async () => {
const { iff } = await setupFixture({
'tsconfig.json': buildTSConfigJSON({ compilerOptions: { jsx: 'react-jsx' } }),
'a.tsx': '',
});
await tsserver.sendUpdateOpen({ openFiles: [{ file: iff.paths['a.tsx'] }] });
const res = await tsserver.sendGetEditsForRefactor({
refactor: createCssModuleFileRefactor.name,
action: createCssModuleFileRefactor.actions[0].name,
file: iff.paths['a.tsx'],
line: 1,
offset: 1,
});
expect(res.body?.edits).toStrictEqual([
{
fileName: iff.join('a.module.css'),
textChanges: [{ start: { line: 0, offset: 0 }, end: { line: 0, offset: 0 }, newText: '' }],
},
]);
});
});