Skip to content

Commit 36cd225

Browse files
Fix LanguageClientManager unit tests (#1237)
1 parent 02d0726 commit 36cd225

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

test/integration-tests/commands/build.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
import * as vscode from "vscode";
16-
import * as fs from "fs";
16+
import * as fs from "fs/promises";
1717
import * as path from "path";
1818
import { expect } from "chai";
1919
import { waitForNoRunningTasks } from "../../utilities";
@@ -29,6 +29,7 @@ import {
2929
folderInRootWorkspace,
3030
updateSettings,
3131
} from "../utilities/testutilities";
32+
import { pathExists } from "../../../src/utilities/filesystem";
3233

3334
suite("Build Commands", function () {
3435
let folderContext: FolderContext;
@@ -60,8 +61,8 @@ suite("Build Commands", function () {
6061

6162
teardown(async () => {
6263
// Remove the build directory after each test case
63-
if (fs.existsSync(buildPath)) {
64-
fs.rmSync(buildPath, { recursive: true, force: true });
64+
if (await pathExists(buildPath)) {
65+
await fs.rm(buildPath, { recursive: true, force: true });
6566
}
6667
});
6768

@@ -79,12 +80,12 @@ suite("Build Commands", function () {
7980
let result = await vscode.commands.executeCommand(Commands.RUN);
8081
expect(result).to.be.true;
8182

82-
const beforeItemCount = fs.readdirSync(buildPath).length;
83+
const beforeItemCount = (await fs.readdir(buildPath)).length;
8384

8485
result = await vscode.commands.executeCommand(Commands.CLEAN_BUILD);
8586
expect(result).to.be.true;
8687

87-
const afterItemCount = fs.readdirSync(buildPath).length;
88+
const afterItemCount = (await fs.readdir(buildPath)).length;
8889
// This test will run in order after the Swift: Run Build test,
8990
// where .build folder is going to be filled with built artifacts.
9091
// After executing the clean command the build directory is guranteed to have less entry.

test/unit-tests/sourcekit-lsp/LanguageClientManager.test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,11 @@ suite("LanguageClientManager Suite", () => {
190190
test("chooses the correct backgroundIndexing value is auto, swift version if 6.0.0", async () => {
191191
mockedWorkspace.swiftVersion = new Version(6, 0, 0);
192192
mockedConfig.backgroundIndexing = "auto";
193-
new LanguageClientManager(instance(mockedWorkspace));
193+
194+
new LanguageClientManager(instance(mockedWorkspace), languageClientFactoryMock);
194195
await waitForReturnedPromises(languageClientMock.start);
195196

196-
expect(mockedLangClientModule.LanguageClient).to.have.been.calledOnceWith(
197+
expect(languageClientFactoryMock.createLanguageClient).to.have.been.calledOnceWith(
197198
match.string,
198199
match.string,
199200
match.object,
@@ -205,10 +206,10 @@ suite("LanguageClientManager Suite", () => {
205206
mockedWorkspace.swiftVersion = new Version(6, 1, 0);
206207
mockedConfig.backgroundIndexing = "auto";
207208

208-
new LanguageClientManager(instance(mockedWorkspace));
209+
new LanguageClientManager(instance(mockedWorkspace), languageClientFactoryMock);
209210
await waitForReturnedPromises(languageClientMock.start);
210211

211-
expect(mockedLangClientModule.LanguageClient).to.have.been.calledOnceWith(
212+
expect(languageClientFactoryMock.createLanguageClient).to.have.been.calledOnceWith(
212213
match.string,
213214
match.string,
214215
match.object,
@@ -220,10 +221,10 @@ suite("LanguageClientManager Suite", () => {
220221
mockedWorkspace.swiftVersion = new Version(6, 0, 0);
221222
mockedConfig.backgroundIndexing = "on";
222223

223-
new LanguageClientManager(instance(mockedWorkspace));
224+
new LanguageClientManager(instance(mockedWorkspace), languageClientFactoryMock);
224225
await waitForReturnedPromises(languageClientMock.start);
225226

226-
expect(mockedLangClientModule.LanguageClient).to.have.been.calledOnceWith(
227+
expect(languageClientFactoryMock.createLanguageClient).to.have.been.calledOnceWith(
227228
match.string,
228229
match.string,
229230
match.object,

0 commit comments

Comments
 (0)