Skip to content

Commit

Permalink
Fixing issues with Jest and the new version of LanguageClient
Browse files Browse the repository at this point in the history
  • Loading branch information
vidorteg committed Sep 14, 2024
1 parent d4f3858 commit 62d4265
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ import {
import { LaunchConfigManager, providedHeadlessDebugConfig, providedLaunchDevToolsConfig } from './launchConfigManager';
import { ErrorReporter } from './errorReporter';
import { ErrorCodes } from './common/errorCodes';
import {
LanguageClient,
import type {
LanguageClientOptions,
ServerOptions,
} from 'vscode-languageclient/node';
import {
LanguageClient,
TransportKind,
} from 'vscode-languageclient/node';
import type { installFailed, showOutput } from 'vscode-webhint/dist/src/utils/notifications';
Expand Down
6 changes: 5 additions & 1 deletion test/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { ExtensionContext, Uri} from "vscode";
import TelemetryReporter from "vscode-extension-telemetry";
import { createFakeExtensionContext, createFakeTelemetryReporter, createFakeVSCode, Mocked } from "./helpers/helpers";
import { createFakeExtensionContext, createFakeTelemetryReporter, createFakeVSCode, createFakeLanguageClient, Mocked } from "./helpers/helpers";
import {
buttonCode,
IRemoteTargetJson,
Expand All @@ -14,6 +14,7 @@ import {
} from "../src/utils";

jest.mock("vscode", () => createFakeVSCode(), { virtual: true });
jest.mock("vscode-languageclient/node", () => createFakeLanguageClient(), { virtual: true });

describe("extension", () => {
const fakeRuntimeConfig: Partial<IRuntimeConfig> = {};
Expand Down Expand Up @@ -60,6 +61,9 @@ describe("extension", () => {
};
});

const mockLanguageClient = createFakeLanguageClient()
jest.doMock("vscode-languageclient/node", () => mockLanguageClient, { virtual: true });

// Mock out vscode command registration
const mockVSCode = createFakeVSCode();
commandMock = mockVSCode.commands.registerCommand;
Expand Down
16 changes: 16 additions & 0 deletions test/helpers/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,19 @@ export function getFirstCallback(mock: jest.Mock, callbackArgIndex: number = 0):
{ callback: Function, thisObj: object } {
return { callback: mock.mock.calls[0][callbackArgIndex], thisObj: mock.mock.instances[0] };
}

export function createFakeLanguageClient() {
const createFakeLanguageClient = jest.fn().mockImplementation(() => {
return {
LanguageClient: function LanguageClient() { /* constructor */ }
}
});
const createFakeLTransportKind = jest.fn().mockImplementation(() => {
return {
TransportKind: function TransportKind() { /* constructor */ }
}
});
return { LanguageClient: createFakeLanguageClient,
TransportKind: createFakeLTransportKind
}
}

0 comments on commit 62d4265

Please sign in to comment.