···
1
+
import { expect, afterAll, beforeAll, it, describe } from 'vitest';
2
+
import { TSServer } from './server';
3
+
import path from 'node:path';
4
+
import fs from 'node:fs';
5
+
import url from 'node:url';
6
+
import ts from 'typescript/lib/tsserverlibrary';
7
+
import { waitForExpect } from './util';
9
+
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
11
+
const projectPath = path.resolve(__dirname, 'fixture-project');
12
+
describe('Fragments', () => {
13
+
const outfileCombinations = path.join(projectPath, 'Combination.ts');
15
+
let server: TSServer;
16
+
beforeAll(async () => {
17
+
server = new TSServer(projectPath, { debugLog: false });
19
+
server.sendCommand('open', {
20
+
file: outfileCombinations,
21
+
fileContent: '// empty',
22
+
scriptKindName: 'TS',
23
+
} satisfies ts.server.protocol.OpenRequestArgs);
25
+
server.sendCommand('updateOpen', {
28
+
file: outfileCombinations,
29
+
fileContent: fs.readFileSync(
30
+
path.join(projectPath, 'fixtures/Combination.ts'),
35
+
} satisfies ts.server.protocol.UpdateOpenRequestArgs);
37
+
server.sendCommand('saveto', {
38
+
file: outfileCombinations,
39
+
tmpfile: outfileCombinations,
40
+
} satisfies ts.server.protocol.SavetoRequestArgs);
45
+
fs.unlinkSync(outfileCombinations);
49
+
it('gives semantic-diagnostics with preceding fragments', async () => {
50
+
await server.waitForResponse(
51
+
e => e.type === 'event' && e.event === 'semanticDiag'
53
+
const res = server.responses
55
+
.find(resp => resp.type === 'event' && resp.event === 'semanticDiag');
56
+
expect(res?.body.diagnostics).toMatchInlineSnapshot(`
59
+
"category": "error",
69
+
"text": "Cannot query field \\"someUnknownField\\" on type \\"Post\\".",
72
+
"category": "error",
82
+
"text": "Cannot query field \\"someUnknownField\\" on type \\"Post\\".",
85
+
"category": "error",
95
+
"text": "Cannot query field \\"__typenam\\" on type \\"Post\\".",
101
+
it('gives quick-info with preceding fragments', async () => {
105
+
command: 'quickinfo',
107
+
file: outfileCombinations,
113
+
await server.waitForResponse(
115
+
response.type === 'response' && response.command === 'quickinfo'
118
+
const res = server.responses
120
+
.find(resp => resp.type === 'response' && resp.command === 'quickinfo');
122
+
expect(res).toBeDefined();
123
+
expect(typeof res?.body).toEqual('object');
124
+
expect(res?.body.displayString).toEqual(
125
+
`Query.posts: [Post]\n\nList out all posts`