Skip to content

Commit 51aed54

Browse files
committed
finish coverage for locateCommand
1 parent 0bab7cb commit 51aed54

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

packages/graphql-language-service-server/src/MessageProcessor.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,12 +894,14 @@ export class MessageProcessor {
894894
);
895895
}
896896
}
897+
897898
if (locateCommand && result && result?.printedName) {
898899
const locateResult = this._getCustomLocateResult(
899900
project,
900901
result,
901902
locateCommand,
902903
);
904+
903905
if (locateResult) {
904906
return locateResult;
905907
}

packages/graphql-language-service-server/src/__tests__/MessageProcessor.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ describe('MessageProcessor', () => {
122122
): Promise<DefinitionQueryResult> {
123123
return {
124124
queryRange: [new Range(position, position)],
125+
printedName: 'example',
125126
definitions: [
126127
{
127128
position,
@@ -486,6 +487,21 @@ describe('MessageProcessor', () => {
486487
expect(customResult3.range.start.character).toEqual(2);
487488
expect(customResult3.range.end.line).toEqual(4);
488489
expect(customResult3.range.end.character).toEqual(4);
490+
const oldGetProject = messageProcessor._graphQLCache.getProjectForFile;
491+
492+
messageProcessor._graphQLCache.getProjectForFile = jest.fn(() => ({
493+
schema: project.schema,
494+
documents: project.documents,
495+
dirpath: project.dirpath,
496+
extensions: {
497+
languageService: { locateCommand: () => 'foo:3:4' },
498+
},
499+
}));
500+
const result2 = await messageProcessor.handleDefinitionRequest(test);
501+
expect(result2[0].range.start.line).toBe(3);
502+
expect(result2[0].range.end.line).toBe(4);
503+
expect(result2[0].range.end.character).toBe(0);
504+
messageProcessor._graphQLCache.getProjectForFile = oldGetProject;
489505
});
490506
it('runs hover requests', async () => {
491507
const validQuery = `

packages/graphql-language-service-server/src/__tests__/__utils__/MockProject.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ const modules = [
3333
'js-tokens',
3434
'escape-string-regexp',
3535
'jest-worker',
36+
'jiti',
37+
'cosmiconfig',
38+
'minimatch',
39+
'tslib',
3640
];
3741
const defaultMocks = modules.reduce((acc, module) => {
3842
acc[`node_modules/${module}`] = mockfs.load(`node_modules/${module}`);

0 commit comments

Comments
 (0)