Skip to content

Commit 9fd7ee3

Browse files
add e2e test that validate detached flag is received
Signed-off-by: nkomonen-amazon <nkomonen@amazon.com>
1 parent 43faa56 commit 9fd7ee3

File tree

3 files changed

+89
-1
lines changed

3 files changed

+89
-1
lines changed

client-node-tests/src/integration.test.ts

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import * as vscode from 'vscode';
1010
import * as lsclient from 'vscode-languageclient/node';
1111
import * as proto from 'vscode-languageserver-protocol';
1212
import { MemoryFileSystemProvider } from './memoryFileSystemProvider';
13-
import { vsdiag, DiagnosticProviderMiddleware } from 'vscode-languageclient';
13+
import { vsdiag, DiagnosticProviderMiddleware, LanguageClient } from 'vscode-languageclient';
14+
import { IsDetachedRequest } from './servers/types';
15+
import { afterEach } from 'mocha';
1416

1517
namespace GotNotifiedRequest {
1618
export const method: 'testing/gotNotified' = 'testing/gotNotified';
@@ -1961,6 +1963,58 @@ class CrashClient extends lsclient.LanguageClient {
19611963
}
19621964

19631965
suite('Server tests', () => {
1966+
suite('detached', async function () {
1967+
const detachedServerModule = path.join(__dirname, 'servers', 'detachedServer.js');
1968+
1969+
let client: LanguageClient | undefined;
1970+
1971+
afterEach(async function () {
1972+
await client?.stop();
1973+
});
1974+
1975+
test('servers are NOT detached by default', async () => {
1976+
const serverOptions: lsclient.ServerOptions = {
1977+
module: detachedServerModule,
1978+
transport: lsclient.TransportKind.ipc,
1979+
};
1980+
const client = new lsclient.LanguageClient('test svr', serverOptions, {});
1981+
const res = await client.sendRequest(IsDetachedRequest);
1982+
assert.strictEqual(res, false);
1983+
});
1984+
1985+
[lsclient.TransportKind.stdio, lsclient.TransportKind.ipc, lsclient.TransportKind.pipe].forEach((transport) => {
1986+
test(`server detects it is detached using Node ServerOptions when transport: ${transport}`, async () => {
1987+
const serverOptions: lsclient.ServerOptions = {
1988+
module: detachedServerModule,
1989+
transport,
1990+
options: {
1991+
detached: true
1992+
}
1993+
};
1994+
const client = new lsclient.LanguageClient('test svr', serverOptions, {});
1995+
const res = await client.sendRequest(IsDetachedRequest);
1996+
assert.strictEqual(res, true);
1997+
});
1998+
});
1999+
2000+
[lsclient.TransportKind.stdio, lsclient.TransportKind.pipe].forEach((transport) => {
2001+
test(`server detects it is detached using Executable ServerOptions when transport: ${transport}`, async () => {
2002+
const serverOptions: lsclient.ServerOptions = {
2003+
command: 'node', // making assumption this exists in the PATH of the test environment
2004+
args: [detachedServerModule],
2005+
transport,
2006+
options: {
2007+
detached: true
2008+
}
2009+
};
2010+
const client = new lsclient.LanguageClient('test svr', serverOptions, {});
2011+
const res = await client.sendRequest(IsDetachedRequest);
2012+
assert.strictEqual(res, true);
2013+
});
2014+
});
2015+
2016+
});
2017+
19642018
test('Stop fails if server crashes after shutdown request', async () => {
19652019
const serverOptions: lsclient.ServerOptions = {
19662020
module: path.join(__dirname, './servers/crashOnShutdownServer.js'),
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
/**
7+
* Server that allows the client to request detached status of the server
8+
*/
9+
10+
import { createConnection, ProposedFeatures } from 'vscode-languageserver/node';
11+
import { IsDetachedRequest } from './types';
12+
13+
const connection = createConnection(ProposedFeatures.all);
14+
15+
connection.onRequest(IsDetachedRequest, () => {
16+
return process.argv.includes('--detached');
17+
});
18+
19+
// Initialize the language server connection
20+
connection.onInitialize(() => {
21+
return {
22+
capabilities: {}
23+
};
24+
});
25+
26+
connection.listen();
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { RequestType0 } from 'vscode-languageserver';
7+
8+
export const IsDetachedRequest = new RequestType0('isDetached');

0 commit comments

Comments
 (0)