forked from 0no-co/GraphQLSP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphqlsp.test.ts
210 lines (189 loc) · 5.47 KB
/
graphqlsp.test.ts
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import { expect, afterAll, beforeAll, it, describe } from 'vitest';
import { TSServer } from './server';
import path from 'node:path';
import fs from 'node:fs';
import url from 'node:url';
import ts from 'typescript/lib/tsserverlibrary';
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
const projectPath = path.resolve(__dirname, 'fixture-project');
let server: TSServer;
describe('simple', () => {
const testFile = path.join(projectPath, 'simple.ts');
const generatedFile = path.join(projectPath, 'simple.generated.ts');
const baseGeneratedFile = path.join(
projectPath,
'__generated__/baseGraphQLSP.ts'
);
beforeAll(async () => {
server = new TSServer(projectPath, { debugLog: false });
const fixtureFileContent = fs.readFileSync(
path.resolve(testFile, '../fixtures/simple.ts'),
'utf-8'
);
server.sendCommand('open', {
file: testFile,
fileContent: '// empty',
scriptKindName: 'TS',
} satisfies ts.server.protocol.OpenRequestArgs);
server.sendCommand('updateOpen', {
openFiles: [{ file: testFile, fileContent: fixtureFileContent }],
} satisfies ts.server.protocol.UpdateOpenRequestArgs);
server.sendCommand('saveto', {
file: testFile,
tmpfile: testFile,
} satisfies ts.server.protocol.SavetoRequestArgs);
await server.waitForResponse(
response => response.type === 'event' && response.event === 'setTypings'
);
});
afterAll(() => {
try {
fs.unlinkSync(testFile);
fs.unlinkSync(generatedFile);
fs.unlinkSync(baseGeneratedFile);
} catch {}
server.close();
});
it('Proposes suggestions for a selection-set', async () => {
server.send({
seq: 8,
type: 'request',
command: 'completionInfo',
arguments: {
file: testFile,
line: 7,
offset: 7,
includeExternalModuleExports: true,
includeInsertTextCompletions: true,
triggerKind: 1,
},
});
await server.waitForResponse(
response =>
response.type === 'response' && response.command === 'completionInfo'
);
const res = server.responses
.reverse()
.find(
resp => resp.type === 'response' && resp.command === 'completionInfo'
);
expect(res).toBeDefined();
expect(typeof res?.body.entries).toEqual('object');
const defaultAttrs = { kind: 'var', kindModifiers: 'declare' };
expect(res?.body.entries).toEqual([
{
...defaultAttrs,
name: 'id',
sortText: '0id',
labelDetails: { detail: ' ID!' },
},
{
...defaultAttrs,
name: 'content',
sortText: '2content',
labelDetails: { detail: ' String!' },
},
{
...defaultAttrs,
name: '__typename',
sortText: '3__typename',
labelDetails: {
detail: ' String!',
description: 'The name of the current Object type at runtime.',
},
},
]);
}, 7500);
it('Gives quick-info when hovering start (#15)', async () => {
server.send({
seq: 9,
type: 'request',
command: 'quickinfo',
arguments: {
file: testFile,
line: 5,
offset: 5,
},
});
await server.waitForResponse(
response =>
response.type === 'response' && response.command === 'quickinfo'
);
const res = server.responses
.reverse()
.find(resp => resp.type === 'response' && resp.command === 'quickinfo');
expect(res).toBeDefined();
expect(typeof res?.body).toEqual('object');
expect(res?.body.documentation).toEqual(
`Query.posts: [Post]\n\nList out all posts`
);
}, 7500);
it('Handles empty line (#190)', async () => {
server.send({
seq: 10,
type: 'request',
command: 'completionInfo',
arguments: {
file: testFile,
line: 14,
offset: 3,
includeExternalModuleExports: true,
includeInsertTextCompletions: true,
triggerKind: 1,
},
});
await server.waitForResponse(
response =>
response.type === 'response' && response.command === 'completionInfo'
);
const res = server.responses
.reverse()
.find(
resp => resp.type === 'response' && resp.command === 'completionInfo'
);
expect(res).toBeDefined();
expect(typeof res?.body.entries).toEqual('object');
const defaultAttrs = { kind: 'var', kindModifiers: 'declare' };
expect(res?.body.entries).toEqual([
{
...defaultAttrs,
name: 'post',
sortText: '0post',
labelDetails: { detail: ' Post' },
},
{
...defaultAttrs,
name: 'posts',
sortText: '1posts',
labelDetails: { detail: ' [Post]', description: 'List out all posts' },
},
{
...defaultAttrs,
name: '__typename',
sortText: '2__typename',
labelDetails: {
detail: ' String!',
description: 'The name of the current Object type at runtime.',
},
},
{
...defaultAttrs,
name: '__schema',
sortText: '3__schema',
labelDetails: {
detail: ' __Schema!',
description: 'Access the current type schema of this server.',
},
},
{
...defaultAttrs,
name: '__type',
sortText: '4__type',
labelDetails: {
detail: ' __Type',
description: 'Request the type information of a single type.',
},
},
]);
}, 7500);
});