-
Notifications
You must be signed in to change notification settings - Fork 565
/
language-server-extension.spec.ts
112 lines (96 loc) · 3.23 KB
/
language-server-extension.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import { runSnykCLI } from '../util/runSnykCLI';
import { pathToFileURL } from 'url';
import { sleep } from '../../../src/lib/common';
import * as cp from 'child_process';
import * as rpc from 'vscode-jsonrpc/node';
jest.setTimeout(1000 * 60);
describe('Language Server Extension', () => {
it('get ls licenses', async () => {
const result = await runSnykCLI('language-server --licenses -d');
if (result.code != 0) {
console.debug(result.stderr);
console.debug(result.stdout);
}
expect(result.code).toBe(0);
});
it('get ls version', async () => {
const cliResult = await runSnykCLI('-v');
const result = await runSnykCLI('language-server -v -d');
if (result.code != 0) {
console.debug(result.stderr);
console.debug(result.stdout);
}
expect(result.code).toBe(0);
expect(cliResult.code).toBe(0);
expect(result.stdout).not.toEqual(cliResult.stdout);
});
it('run and wait for diagnostics', async () => {
let cmd = '';
if (process.env.TEST_SNYK_COMMAND !== undefined) {
cmd = process.env.TEST_SNYK_COMMAND;
}
const cli = cp.spawn(cmd, ['language-server'], { stdio: 'pipe' }); // Use stdin and stdout for communication:
const connection = rpc.createMessageConnection(
new rpc.StreamMessageReader(cli.stdout),
new rpc.StreamMessageWriter(cli.stdin),
);
await sleep(3000);
// create an RPC endpoint for the process
connection.listen();
await connection.sendRequest('initialize', {
processId: process.pid,
capabilities: {
window: {
workDoneProgress: true,
},
},
clientInfo: {
name: 'FakeIDE',
version: '4.5.6',
},
workspaceFolders: [
{
name: 'workspace',
uri: pathToFileURL('.').href,
},
],
rootUri: null,
initializationOptions: {
activateSnykCodeSecurity: 'false',
activateSnykCodeQuality: 'false',
activateSnykOpenSource: 'true',
activateSnykIac: 'false',
token: process.env.TEST_SNYK_TOKEN,
manageBinariesAutomatically: 'false',
enableTrustedFoldersFeature: 'false',
integrationName: 'MyFakePlugin',
integrationVersion: '1.2.3',
enableTelemetry: 'false',
cliPath: cmd,
},
});
let diagnosticCount = 0;
connection.onNotification(
'textDocument/publishDiagnostics',
(param: string) => {
console.debug('Received notification: ' + param);
diagnosticCount++;
},
);
// eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/no-empty-function
connection.onNotification('window/logMessage', (_: string) => {});
// eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/no-empty-function
connection.onNotification((_: string) => {});
// eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/no-empty-function
connection.onRequest((_: string) => {});
await connection.sendRequest('initialized', {});
for (let i = 0; i < 45; i++) {
console.debug('Waiting for diagnostics...');
if (diagnosticCount > 0) {
break;
}
await sleep(1000);
}
cli.kill(9);
});
});