Skip to content

Commit 905e420

Browse files
committed
Add explainshell test case
1 parent 64bd8c1 commit 905e420

File tree

3 files changed

+79
-22
lines changed

3 files changed

+79
-22
lines changed

server/src/__tests__/server.test.ts

Lines changed: 57 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -965,8 +965,7 @@ describe('server', () => {
965965
})
966966

967967
it('displays correct documentation for symbols in file that override path executables', async () => {
968-
const { connection, server } = await initializeServer()
969-
server.register(connection)
968+
const { connection } = await initializeServer()
970969

971970
const onHover = connection.onHover.mock.calls[0][0]
972971

@@ -1000,31 +999,70 @@ describe('server', () => {
1000999
})
10011000

10021001
it('returns executable documentation if the function is not redefined', async () => {
1003-
const { connection, server } = await initializeServer()
1004-
server.register(connection)
1002+
const { connection } = await initializeServer()
10051003

10061004
const onHover = connection.onHover.mock.calls[0][0]
10071005

1008-
const result = await onHover(
1009-
{
1010-
textDocument: {
1011-
uri: FIXTURE_URI.OVERRIDE_SYMBOL,
1006+
const getHoverResult = (position: LSP.Position) =>
1007+
onHover(
1008+
{
1009+
textDocument: {
1010+
uri: FIXTURE_URI.OVERRIDE_SYMBOL,
1011+
},
1012+
position,
10121013
},
1013-
position: {
1014-
line: 2,
1015-
character: 1,
1014+
{} as any,
1015+
{} as any,
1016+
)
1017+
1018+
const result1 = await getHoverResult({ line: 2, character: 1 })
1019+
expect(result1).toBeDefined()
1020+
expect((result1 as any)?.contents.value).toContain('list directory contents')
1021+
1022+
// return null same result if the cursor is on the arguments
1023+
const result2 = await getHoverResult({ line: 2, character: 3 })
1024+
expect(result2).toBeDefined()
1025+
expect((result2 as any)?.contents.value).toBeUndefined()
1026+
})
1027+
1028+
it.skip('returns documentation from explainshell', async () => {
1029+
// Skipped as this requires a running explainshell server
1030+
// docker container run --name explainshell --restart always -p 127.0.0.1:6000:5000 -d spaceinvaderone/explainshell
1031+
1032+
const { connection } = await initializeServer({
1033+
capabilities: {
1034+
workspace: {
1035+
configuration: true,
10161036
},
10171037
},
1018-
{} as any,
1019-
{} as any,
1020-
)
1038+
configurationObject: {
1039+
explainshellEndpoint: 'http://localhost:6000',
1040+
},
1041+
})
1042+
const onHover = connection.onHover.mock.calls[0][0]
10211043

1022-
expect(result).toBeDefined()
1023-
expect((result as any)?.contents.value).toContain('list directory contents')
1024-
})
1044+
const getHoverResult = (position: LSP.Position) =>
1045+
onHover(
1046+
{
1047+
textDocument: {
1048+
uri: FIXTURE_URI.OVERRIDE_SYMBOL,
1049+
},
1050+
position,
1051+
},
1052+
{} as any,
1053+
{} as any,
1054+
)
10251055

1026-
it.skip('returns documentation from explainshell', () => {
1027-
// FIXME
1056+
const result1 = await getHoverResult({ line: 2, character: 1 })
1057+
expect(result1).toBeDefined()
1058+
expect((result1 as any)?.contents.value).toEqual('list directory contents')
1059+
1060+
// return explain shell result for the arguments
1061+
const result2 = await getHoverResult({ line: 2, character: 3 })
1062+
expect(result2).toBeDefined()
1063+
expect((result2 as any)?.contents.value).toEqual(
1064+
'**\\-l** use a long listing format',
1065+
)
10281066
})
10291067
})
10301068

testing/fixtures/override-executable-symbol.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
ls
3+
ls -la
44

55
# override documentation for `ls` symbol
66
ls() {

testing/mocks.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ export function getMockConnection(): jest.Mocked<LSP.Connection> {
99
}
1010

1111
return {
12-
client: {} as any,
12+
client: {
13+
connection: {} as any,
14+
register: jest.fn(),
15+
initialize: jest.fn(),
16+
fillServerCapabilities: jest.fn(),
17+
},
1318
console,
1419
dispose: jest.fn(),
1520
languages: {} as any,
@@ -76,6 +81,20 @@ export function getMockConnection(): jest.Mocked<LSP.Connection> {
7681
showInformationMessage: jest.fn(),
7782
showWarningMessage: jest.fn(),
7883
},
79-
workspace: {} as any,
84+
workspace: {
85+
applyEdit: jest.fn(),
86+
connection: {} as any,
87+
fillServerCapabilities: jest.fn(),
88+
getConfiguration: jest.fn(),
89+
getWorkspaceFolders: jest.fn(),
90+
initialize: jest.fn(),
91+
onDidChangeWorkspaceFolders: jest.fn(),
92+
onDidCreateFiles: jest.fn(),
93+
onDidDeleteFiles: jest.fn(),
94+
onDidRenameFiles: jest.fn(),
95+
onWillCreateFiles: jest.fn(),
96+
onWillDeleteFiles: jest.fn(),
97+
onWillRenameFiles: jest.fn(),
98+
},
8099
}
81100
}

0 commit comments

Comments
 (0)