-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
623 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
174 changes: 174 additions & 0 deletions
174
apps/nxls-e2e/src/document-links/named-input-link-completion-default.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
import { readFileSync } from 'fs'; | ||
import { join } from 'path'; | ||
import { Position } from 'vscode-languageserver'; | ||
import { URI } from 'vscode-uri'; | ||
import { NxlsWrapper } from '../nxls-wrapper'; | ||
import { e2eCwd, modifyJsonFile, newWorkspace, uniq } from '../utils'; | ||
|
||
let nxlsWrapper: NxlsWrapper; | ||
const workspaceName = uniq('workspace'); | ||
|
||
const projectJsonPath = join( | ||
e2eCwd, | ||
workspaceName, | ||
'apps', | ||
workspaceName, | ||
'project.json' | ||
); | ||
|
||
describe('namedInput link completion - default', () => { | ||
beforeAll(async () => { | ||
newWorkspace({ | ||
name: workspaceName, | ||
options: { | ||
preset: 'next', | ||
}, | ||
}); | ||
nxlsWrapper = new NxlsWrapper(true); | ||
await nxlsWrapper.startNxls(join(e2eCwd, workspaceName)); | ||
|
||
nxlsWrapper.sendNotification({ | ||
method: 'textDocument/didOpen', | ||
params: { | ||
textDocument: { | ||
uri: URI.file(projectJsonPath).toString(), | ||
languageId: 'JSON', | ||
version: 1, | ||
text: readFileSync(projectJsonPath, 'utf-8'), | ||
}, | ||
}, | ||
}); | ||
}); | ||
afterAll(async () => { | ||
await nxlsWrapper.stopNxls(); | ||
}); | ||
describe('named input links', () => { | ||
it('should return correct target link for input if it is a namedInput in nx.json', async () => { | ||
modifyJsonFile(projectJsonPath, (data) => ({ | ||
...data, | ||
targets: { | ||
build: { | ||
inputs: ['default'], | ||
}, | ||
}, | ||
})); | ||
|
||
nxlsWrapper.sendNotification({ | ||
method: 'textDocument/didChange', | ||
params: { | ||
textDocument: { | ||
uri: URI.file(projectJsonPath).toString(), | ||
languageId: 'JSON', | ||
version: 2, | ||
}, | ||
contentChanges: [ | ||
{ | ||
text: readFileSync(projectJsonPath, 'utf-8'), | ||
}, | ||
], | ||
}, | ||
}); | ||
|
||
const linkResponse = await nxlsWrapper.sendRequest({ | ||
method: 'textDocument/documentLink', | ||
params: { | ||
textDocument: { | ||
uri: URI.file(projectJsonPath).toString(), | ||
}, | ||
position: Position.create(0, 1), | ||
}, | ||
}); | ||
|
||
const defaultLine = | ||
readFileSync(join(e2eCwd, workspaceName, 'nx.json'), 'utf-8') | ||
.split('\n') | ||
.findIndex((line) => line.includes('"default":')) + 1; | ||
|
||
const targetLink = (linkResponse.result as any[])[0].target; | ||
expect(targetLink).toMatch(new RegExp(`#${defaultLine}$`)); | ||
expect(decodeURI(targetLink)).toContain(join(workspaceName, 'nx.json')); | ||
}); | ||
|
||
it('should not return target link for input if it is not a namedInput in nx.json', async () => { | ||
modifyJsonFile(projectJsonPath, (data) => ({ | ||
...data, | ||
targets: { | ||
build: { | ||
inputs: ['src/file.js', 'other'], | ||
}, | ||
}, | ||
})); | ||
|
||
nxlsWrapper.sendNotification({ | ||
method: 'textDocument/didChange', | ||
params: { | ||
textDocument: { | ||
uri: URI.file(projectJsonPath).toString(), | ||
languageId: 'JSON', | ||
version: 2, | ||
}, | ||
contentChanges: [ | ||
{ | ||
text: readFileSync(projectJsonPath, 'utf-8'), | ||
}, | ||
], | ||
}, | ||
}); | ||
|
||
const linkResponse = await nxlsWrapper.sendRequest({ | ||
method: 'textDocument/documentLink', | ||
params: { | ||
textDocument: { | ||
uri: URI.file(projectJsonPath).toString(), | ||
}, | ||
position: Position.create(0, 1), | ||
}, | ||
}); | ||
|
||
const targetLinks = linkResponse.result as any[]; | ||
expect(targetLinks.length).toBe(0); | ||
}); | ||
|
||
it('should return correct target link for named input within nx.json', async () => { | ||
const nxJsonPath = join(e2eCwd, workspaceName, 'nx.json'); | ||
modifyJsonFile(nxJsonPath, (data) => ({ | ||
...data, | ||
namedInputs: { | ||
default: ['one', 'two'], | ||
one: ['src/file.js'], | ||
}, | ||
})); | ||
|
||
nxlsWrapper.sendNotification({ | ||
method: 'textDocument/didOpen', | ||
params: { | ||
textDocument: { | ||
uri: URI.file(nxJsonPath).toString(), | ||
languageId: 'JSON', | ||
version: 0, | ||
text: readFileSync(nxJsonPath, 'utf-8'), | ||
}, | ||
}, | ||
}); | ||
|
||
const linkResponse = await nxlsWrapper.sendRequest({ | ||
method: 'textDocument/documentLink', | ||
params: { | ||
textDocument: { | ||
uri: URI.file(nxJsonPath).toString(), | ||
}, | ||
position: Position.create(0, 1), | ||
}, | ||
}); | ||
|
||
const oneLine = | ||
readFileSync(nxJsonPath, 'utf-8') | ||
.split('\n') | ||
.findIndex((line) => line.includes('"one": [')) + 1; | ||
|
||
const targetLink = (linkResponse.result as any[])[0].target; | ||
expect(targetLink).toMatch(new RegExp(`#${oneLine}$`)); | ||
expect(decodeURI(targetLink)).toContain(join(workspaceName, 'nx.json')); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.