-
Notifications
You must be signed in to change notification settings - Fork 26
/
diagnostics-with-update.js
69 lines (62 loc) · 1.98 KB
/
diagnostics-with-update.js
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
const assert = require('assert');
const path = require('path');
const { mark } = require('fretted-strings');
function findResponse(responses, eventName) {
return responses.find(response => response.event === eventName);
}
async function run(server) {
const fileFragments = path.resolve(__dirname, '../../project-fixtures/simple-prj/fragments.ts');
const fileFragmentsContent = `
import gql from 'graphql-tag';
const f = gql\`fragment MyFragment on Query { hello }\`;
`;
const fileMain = path.resolve(__dirname, '../../project-fixtures/simple-prj/main.ts');
const frets = {};
const fileMainContent = mark(
`
import gql from 'graphql-tag';
const q = gql\`query MyQuery { }\`;
%%% \\ ^ %%%
%%% \\ p %%%
`,
frets,
);
server.send({
command: 'open',
arguments: { file: fileFragments, fileContent: fileFragmentsContent, scriptKindName: 'TS' },
});
server.send({ command: 'open', arguments: { file: fileMain, fileContent: fileMainContent, scriptKindName: 'TS' } });
await server.waitEvent('projectLoadingFinish');
server.send({
command: 'updateOpen',
arguments: {
changedFiles: [
{
fileName: fileMain,
textChanges: [
{
newText: '...MyFragment',
start: {
line: frets.p.line + 1,
offset: frets.p.character + 1,
},
end: {
line: frets.p.line + 1,
offset: frets.p.character + 1,
},
},
],
},
],
},
});
await server.waitResponse('updateOpen');
server.send({ command: 'geterr', arguments: { files: [fileMain], delay: 0 } });
await server.waitEvent('semanticDiag');
return server.close().then(() => {
const semanticDiagEvent = findResponse(server.responses, 'semanticDiag');
assert(!!semanticDiagEvent);
assert.equal(semanticDiagEvent.body.diagnostics.length, 0);
});
}
module.exports = run;