This repository has been archived by the owner on May 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 52
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
169 additions
and
35 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,122 @@ | ||
import * as assert from "assert"; | ||
import * as fs from "fs"; | ||
import * as path from "path"; | ||
import * as os from "os"; | ||
|
||
import { beforeEach, afterEach } from "mocha"; | ||
import * as vscode from "vscode"; | ||
|
||
import { Ruby } from "../../ruby"; | ||
import { Telemetry, TelemetryApi, TelemetryEvent } from "../../telemetry"; | ||
import { TestController } from "../../testController"; | ||
import { ServerState } from "../../status"; | ||
import Client from "../../client"; | ||
|
||
class FakeApi implements TelemetryApi { | ||
public sentEvents: TelemetryEvent[]; | ||
|
||
constructor() { | ||
this.sentEvents = []; | ||
} | ||
|
||
async sendEvent(event: TelemetryEvent): Promise<void> { | ||
this.sentEvents.push(event); | ||
} | ||
} | ||
|
||
suite("Client", () => { | ||
let client: Client; | ||
let testController: TestController; | ||
const managerConfig = vscode.workspace.getConfiguration("rubyLsp"); | ||
const currentManager = managerConfig.get("rubyVersionManager"); | ||
const tmpPath = fs.mkdtempSync(path.join(os.tmpdir(), "ruby-lsp-test-")); | ||
|
||
beforeEach(async () => { | ||
fs.writeFileSync( | ||
`${tmpPath}/Gemfile`, | ||
'source "https://rubygems.org"\ngem "ruby-lsp"\ngem "debug", platforms: :mri', | ||
); | ||
fs.writeFileSync( | ||
`${tmpPath}/Gemfile.lock`, | ||
` | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
debug (1.8.0) | ||
irb (>= 1.5.0) | ||
reline (>= 0.3.1) | ||
io-console (0.6.0) | ||
irb (1.7.4) | ||
reline (>= 0.3.6) | ||
language_server-protocol (3.17.0.3) | ||
prettier_print (1.2.1) | ||
reline (0.3.6) | ||
io-console (~> 0.5) | ||
ruby-lsp (0.4.3) | ||
language_server-protocol (~> 3.17.0) | ||
sorbet-runtime | ||
syntax_tree (>= 6.1.1, < 7) | ||
sorbet-runtime (0.5.10741) | ||
syntax_tree (6.1.1) | ||
prettier_print (>= 1.2.0) | ||
PLATFORMS | ||
arm64-darwin-22 | ||
DEPENDENCIES | ||
debug | ||
ruby-lsp | ||
BUNDLED WITH | ||
2.4.10 | ||
`, | ||
); | ||
}); | ||
|
||
afterEach(async () => { | ||
if (client) { | ||
await client.stop(); | ||
} | ||
|
||
if (testController) { | ||
testController.dispose(); | ||
} | ||
|
||
managerConfig.update("rubyVersionManager", currentManager, true, true); | ||
fs.rmSync(tmpPath, { recursive: true, force: true }); | ||
}); | ||
|
||
test("Starting up the server succeeds", async () => { | ||
// await managerConfig.update("rubyVersionManager", "none", true, true); | ||
const context = { | ||
extensionMode: vscode.ExtensionMode.Test, | ||
subscriptions: [], | ||
workspaceState: { | ||
get: (_name: string) => undefined, | ||
update: (_name: string, _value: any) => Promise.resolve(), | ||
}, | ||
} as unknown as vscode.ExtensionContext; | ||
|
||
const ruby = new Ruby(context, tmpPath); | ||
await ruby.activateRuby(); | ||
|
||
const telemetry = new Telemetry(context, new FakeApi()); | ||
|
||
const testController = new TestController( | ||
context, | ||
tmpPath, | ||
ruby, | ||
telemetry, | ||
); | ||
|
||
const client = new Client( | ||
context, | ||
telemetry, | ||
ruby, | ||
testController, | ||
tmpPath, | ||
); | ||
await client.start(false); | ||
assert.strictEqual(client.state, ServerState.Running); | ||
}).timeout(10000); | ||
}); |