···
+
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';
+
import { waitForExpect } from './util';
+
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
+
const projectPath = path.resolve(__dirname, 'fixture-project');
+
describe('Fragments', () => {
+
const outfileCombinations = path.join(projectPath, 'Combination.ts');
+
beforeAll(async () => {
+
server = new TSServer(projectPath, { debugLog: false });
+
server.sendCommand('open', {
+
file: outfileCombinations,
+
fileContent: '// empty',
+
} satisfies ts.server.protocol.OpenRequestArgs);
+
server.sendCommand('updateOpen', {
+
file: outfileCombinations,
+
fileContent: fs.readFileSync(
+
path.join(projectPath, 'fixtures/Combination.ts'),
+
} satisfies ts.server.protocol.UpdateOpenRequestArgs);
+
server.sendCommand('saveto', {
+
file: outfileCombinations,
+
tmpfile: outfileCombinations,
+
} satisfies ts.server.protocol.SavetoRequestArgs);
+
fs.unlinkSync(outfileCombinations);
+
it('gives semantic-diagnostics with preceding fragments', async () => {
+
await server.waitForResponse(
+
e => e.type === 'event' && e.event === 'semanticDiag'
+
const res = server.responses
+
.find(resp => resp.type === 'event' && resp.event === 'semanticDiag');
+
expect(res?.body.diagnostics).toMatchInlineSnapshot(`
+
"text": "Cannot query field \\"someUnknownField\\" on type \\"Post\\".",
+
"text": "Cannot query field \\"someUnknownField\\" on type \\"Post\\".",
+
"text": "Cannot query field \\"__typenam\\" on type \\"Post\\".",
+
it('gives quick-info with preceding fragments', async () => {
+
file: outfileCombinations,
+
await server.waitForResponse(
+
response.type === 'response' && response.command === 'quickinfo'
+
const res = server.responses
+
.find(resp => resp.type === 'response' && resp.command === 'quickinfo');
+
expect(res).toBeDefined();
+
expect(typeof res?.body).toEqual('object');
+
expect(res?.body.displayString).toEqual(
+
`Query.posts: [Post]\n\nList out all posts`