-
Notifications
You must be signed in to change notification settings - Fork 175
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
4 changed files
with
160 additions
and
34 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
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,123 @@ | ||
/* eslint-disable no-process-env */ | ||
import assert from "assert"; | ||
import path from "path"; | ||
|
||
import * as vscode from "vscode"; | ||
import { State, WorkDoneProgress } from "vscode-languageclient/node"; | ||
import sinon from "sinon"; | ||
|
||
import { ManagerIdentifier, Ruby } from "../../ruby"; | ||
import Client from "../../client"; | ||
import { WorkspaceChannel } from "../../workspaceChannel"; | ||
import * as common from "../../common"; | ||
|
||
import { FAKE_TELEMETRY, FakeLogger } from "./fakeTelemetry"; | ||
|
||
suite("Launch integrations", () => { | ||
const workspacePath = path.dirname( | ||
path.dirname(path.dirname(path.dirname(__dirname))), | ||
); | ||
const workspaceUri = vscode.Uri.file(workspacePath); | ||
const workspaceFolder: vscode.WorkspaceFolder = { | ||
uri: workspaceUri, | ||
name: path.basename(workspaceUri.fsPath), | ||
index: 0, | ||
}; | ||
|
||
const context = { | ||
extensionMode: vscode.ExtensionMode.Test, | ||
subscriptions: [], | ||
workspaceState: { | ||
get: (_name: string) => undefined, | ||
update: (_name: string, _value: any) => Promise.resolve(), | ||
}, | ||
extensionUri: vscode.Uri.joinPath(workspaceUri, "vscode"), | ||
} as unknown as vscode.ExtensionContext; | ||
const fakeLogger = new FakeLogger(); | ||
const outputChannel = new WorkspaceChannel("fake", fakeLogger as any); | ||
|
||
async function createClient() { | ||
const ruby = new Ruby( | ||
context, | ||
workspaceFolder, | ||
outputChannel, | ||
FAKE_TELEMETRY, | ||
); | ||
|
||
if (process.env.CI) { | ||
await ruby.activateRuby({ identifier: ManagerIdentifier.None }); | ||
|
||
try { | ||
await common.asyncExec("gem install ruby-lsp", { | ||
cwd: workspacePath, | ||
env: ruby.env, | ||
}); | ||
} catch (error: any) { | ||
assert.fail(`Failed to install ruby-lsp: ${error.message}`); | ||
} | ||
} else { | ||
await ruby.activateRuby(); | ||
} | ||
|
||
const client = new Client( | ||
context, | ||
FAKE_TELEMETRY, | ||
ruby, | ||
() => {}, | ||
workspaceFolder, | ||
outputChannel, | ||
new Map<string, string>(), | ||
); | ||
|
||
client.clientOptions.initializationFailedHandler = (error) => { | ||
assert.fail( | ||
`Failed to start server ${error.message}\n${fakeLogger.receivedMessages}`, | ||
); | ||
}; | ||
|
||
return client; | ||
} | ||
|
||
async function startClient(client: Client) { | ||
try { | ||
await client.start(); | ||
} catch (error: any) { | ||
assert.fail( | ||
`Failed to start server ${error.message}\n${fakeLogger.receivedMessages}`, | ||
); | ||
} | ||
assert.strictEqual(client.state, State.Running); | ||
|
||
// Wait for composing the bundle and indexing to finish. We don't _need_ the codebase to be indexed for these tests, | ||
// but trying to stop the server in the middle of composing the bundle may timeout, so this makes the tests more | ||
// robust | ||
return new Promise<Client>((resolve) => { | ||
client.onProgress( | ||
WorkDoneProgress.type, | ||
"indexing-progress", | ||
(value: any) => { | ||
if (value.kind === "end") { | ||
resolve(client); | ||
} | ||
}, | ||
); | ||
}); | ||
} | ||
|
||
test("with launcher mode enabled", async () => { | ||
const featureStub = sinon.stub(common, "featureEnabled").returns(true); | ||
const client = await createClient(); | ||
featureStub.restore(); | ||
|
||
await startClient(client); | ||
|
||
try { | ||
await client.stop(); | ||
await client.dispose(); | ||
} catch (error: any) { | ||
assert.fail( | ||
`Failed to stop server: ${error.message}\n${fakeLogger.receivedMessages}`, | ||
); | ||
} | ||
}).timeout(120000); | ||
}); |