|
| 1 | +const assert = require('assert'); |
| 2 | +const path = require('path'); |
| 3 | +const { mark } = require('fretted-strings'); |
| 4 | + |
| 5 | +function findResponse(responses, commandName) { |
| 6 | + return responses.find(response => response.command === commandName); |
| 7 | +} |
| 8 | + |
| 9 | +async function run(server) { |
| 10 | + const fileFragments = path.resolve(__dirname, '../../project-fixtures/simple-prj/fragments.ts'); |
| 11 | + const fileMain = path.resolve(__dirname, '../../project-fixtures/simple-prj/main.ts'); |
| 12 | + const frets = {}; |
| 13 | + const fileFragmentsContent = ` |
| 14 | + const fragment = gql\` |
| 15 | + fragment MyFragment on Query { |
| 16 | + hello |
| 17 | + } |
| 18 | + \`; |
| 19 | + `; |
| 20 | + const fileMainContent = mark( |
| 21 | + ` |
| 22 | + const query = gql\` |
| 23 | + query MyQuery { |
| 24 | + ...MyFragment |
| 25 | + %%% ^ %%% |
| 26 | + %%% p %%% |
| 27 | + } |
| 28 | + \`; |
| 29 | + `, |
| 30 | + frets, |
| 31 | + ); |
| 32 | + server.send({ |
| 33 | + command: 'open', |
| 34 | + arguments: { file: fileFragments, fileContent: fileFragmentsContent, scriptKindName: 'TS' }, |
| 35 | + }); |
| 36 | + server.send({ command: 'open', arguments: { file: fileMain, fileContent: fileMainContent, scriptKindName: 'TS' } }); |
| 37 | + |
| 38 | + await server.waitEvent('projectLoadingFinish'); |
| 39 | + |
| 40 | + server.send({ |
| 41 | + command: 'definition', |
| 42 | + arguments: { file: fileMain, offset: frets.p.character + 1, line: frets.p.line + 1, prefix: '' }, |
| 43 | + }); |
| 44 | + |
| 45 | + await server.waitResponse('definition'); |
| 46 | + |
| 47 | + server.send({ |
| 48 | + command: 'definitionAndBoundSpan', |
| 49 | + arguments: { file: fileMain, offset: frets.p.character + 1, line: frets.p.line + 1, prefix: '' }, |
| 50 | + }); |
| 51 | + |
| 52 | + await server.waitResponse('definitionAndBoundSpan'); |
| 53 | + |
| 54 | + await server.close(); |
| 55 | + |
| 56 | + const definitionResponse = findResponse(server.responses, 'definition'); |
| 57 | + assert(!!definitionResponse); |
| 58 | + assert(definitionResponse.body.length === 1); |
| 59 | + assert(definitionResponse.body[0].file === fileFragments); |
| 60 | + |
| 61 | + const definitionAndBoundSpanResponse = findResponse(server.responses, 'definitionAndBoundSpan'); |
| 62 | + assert(!!definitionAndBoundSpanResponse); |
| 63 | + assert(definitionAndBoundSpanResponse.body.definitions.length === 1); |
| 64 | + assert(definitionAndBoundSpanResponse.body.definitions[0].file === fileFragments); |
| 65 | +} |
| 66 | + |
| 67 | +module.exports = run; |
0 commit comments