Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KetanReddy committed Oct 3, 2024
1 parent 23786fd commit e8ffabd
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions cli/src/plugins/__tests__/LSPAssetsPlugin.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { PlayerLanguageService } from "@player-tools/json-language-service";
import { vi, test, expect, describe, beforeEach } from "vitest";
import { LSPAssetsPlugin } from "../LSPAssetsPlugin";

describe("LSPAssetPlugin tests", () => {
const mockSetAssetTypes = vi.fn();
const mockSetAssetTypesFromModule = vi.fn();

const mockLSP: PlayerLanguageService = {
setAssetTypes: mockSetAssetTypes,
setAssetTypesFromModule: mockSetAssetTypesFromModule,
} as unknown as PlayerLanguageService;

beforeEach(() => {
mockSetAssetTypes.mockClear();
mockSetAssetTypesFromModule.mockClear();
});

test("It should load assets from the filesystem by default (legacy)", async () => {
const testPlugin = new LSPAssetsPlugin({ path: "some/path" });
await testPlugin.onCreateLanguageService(mockLSP, false);

expect(mockSetAssetTypes).toHaveBeenCalledWith(["some/path"]);
expect(mockSetAssetTypesFromModule).not.toHaveBeenCalled();
});

test("It should load assets from the filesystem ", async () => {
const testPlugin = new LSPAssetsPlugin({
path: "some/path",
type: "manifest",
});
await testPlugin.onCreateLanguageService(mockLSP, false);

expect(mockSetAssetTypes).toHaveBeenCalledWith(["some/path"]);
expect(mockSetAssetTypesFromModule).not.toHaveBeenCalled();
});

test("It should load assets from a module", async () => {
const testPlugin = new LSPAssetsPlugin({
manifest: { pluginName: "test", capabilities: {} },
type: "module",
});
await testPlugin.onCreateLanguageService(mockLSP, false);

expect(mockSetAssetTypesFromModule).toHaveBeenCalledWith([
{
pluginName: "test",
capabilities: {},
},
]);
expect(mockSetAssetTypes).not.toHaveBeenCalled();
});

test("It should load assets from a mixed config", async () => {
const testPlugin = new LSPAssetsPlugin([
{ manifest: { pluginName: "test", capabilities: {} }, type: "module" },
{ path: "some/path", type: "manifest" },
]);
await testPlugin.onCreateLanguageService(mockLSP, false);

expect(mockSetAssetTypesFromModule).toHaveBeenCalledWith([
{
pluginName: "test",
capabilities: {},
},
]);
expect(mockSetAssetTypes).toHaveBeenCalledWith(["some/path"]);
});
});

0 comments on commit e8ffabd

Please sign in to comment.