Skip to content

Commit f874aee

Browse files
committed
Dry hover test cases
1 parent 5e2cd3c commit f874aee

File tree

1 file changed

+33
-65
lines changed

1 file changed

+33
-65
lines changed

server/src/__tests__/server.test.ts

Lines changed: 33 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -955,27 +955,29 @@ describe('server', () => {
955955
})
956956

957957
describe('onHover', () => {
958-
it('responds with documentation for command', async () => {
958+
async function getHoverResult(uri: string, position: LSP.Position) {
959959
const { connection } = await initializeServer()
960960

961961
const onHover = connection.onHover.mock.calls[0][0]
962962

963-
const result = await onHover(
963+
return onHover(
964964
{
965965
textDocument: {
966-
uri: FIXTURE_URI.INSTALL,
967-
},
968-
position: {
969-
// rm
970-
line: 25,
971-
character: 5,
966+
uri,
972967
},
968+
position,
973969
},
974970
{} as any,
975971
{} as any,
976972
)
973+
}
974+
it('responds with documentation for command', async () => {
975+
const result = await getHoverResult(FIXTURE_URI.INSTALL, {
976+
// rm
977+
line: 25,
978+
character: 5,
979+
})
977980

978-
expect(result).toBeDefined()
979981
expect(result).toEqual({
980982
contents: {
981983
kind: 'markdown',
@@ -985,25 +987,11 @@ describe('server', () => {
985987
})
986988

987989
it('responds with function documentation extracted from comments', async () => {
988-
const { connection } = await initializeServer()
989-
990-
const onHover = connection.onHover.mock.calls[0][0]
991-
992-
const result = await onHover(
993-
{
994-
textDocument: {
995-
uri: FIXTURE_URI.COMMENT_DOC,
996-
},
997-
position: {
998-
line: 17,
999-
character: 0,
1000-
},
1001-
},
1002-
{} as any,
1003-
{} as any,
1004-
)
990+
const result = await getHoverResult(FIXTURE_URI.COMMENT_DOC, {
991+
line: 17,
992+
character: 0,
993+
})
1005994

1006-
expect(result).toBeDefined()
1007995
expect(result).toMatchInlineSnapshot(`
1008996
Object {
1009997
"contents": Object {
@@ -1022,25 +1010,11 @@ describe('server', () => {
10221010
})
10231011

10241012
it('displays correct documentation for symbols in file that override path executables', async () => {
1025-
const { connection } = await initializeServer()
1026-
1027-
const onHover = connection.onHover.mock.calls[0][0]
1028-
1029-
const result = await onHover(
1030-
{
1031-
textDocument: {
1032-
uri: FIXTURE_URI.OVERRIDE_SYMBOL,
1033-
},
1034-
position: {
1035-
line: 9,
1036-
character: 1,
1037-
},
1038-
},
1039-
{} as any,
1040-
{} as any,
1041-
)
1013+
const result = await getHoverResult(FIXTURE_URI.OVERRIDE_SYMBOL, {
1014+
line: 9,
1015+
character: 1,
1016+
})
10421017

1043-
expect(result).toBeDefined()
10441018
expect(result).toMatchInlineSnapshot(`
10451019
Object {
10461020
"contents": Object {
@@ -1056,28 +1030,22 @@ describe('server', () => {
10561030
})
10571031

10581032
it('returns executable documentation if the function is not redefined', async () => {
1059-
const { connection } = await initializeServer()
1060-
1061-
const onHover = connection.onHover.mock.calls[0][0]
1062-
1063-
const getHoverResult = (position: LSP.Position) =>
1064-
onHover(
1065-
{
1066-
textDocument: {
1067-
uri: FIXTURE_URI.OVERRIDE_SYMBOL,
1068-
},
1069-
position,
1070-
},
1071-
{} as any,
1072-
{} as any,
1073-
)
1074-
1075-
const result1 = await getHoverResult({ line: 2, character: 1 })
1076-
expect(result1).toBeDefined()
1077-
expect((result1 as any)?.contents.value).toContain('list directory contents')
1033+
const result1 = await getHoverResult(FIXTURE_URI.OVERRIDE_SYMBOL, {
1034+
line: 2,
1035+
character: 1,
1036+
})
1037+
expect(result1).toEqual({
1038+
contents: {
1039+
kind: 'markdown',
1040+
value: expect.stringContaining('list directory contents'),
1041+
},
1042+
})
10781043

10791044
// return null same result if the cursor is on the arguments
1080-
const result2 = await getHoverResult({ line: 2, character: 3 })
1045+
const result2 = await getHoverResult(FIXTURE_URI.OVERRIDE_SYMBOL, {
1046+
line: 2,
1047+
character: 3,
1048+
})
10811049
expect(result2).toBeDefined()
10821050
expect((result2 as any)?.contents.value).toBeUndefined()
10831051
})

0 commit comments

Comments
 (0)