import { CompletionItemKind } from "vscode-languageserver/lib/main"; import Completers from "../../classes/Completers"; import NodeCompleter from "../../classes/completers/NodesCompleter"; import UICompleter from "../../classes/completers/UICompleter"; jest.mock("fs"); describe("Initializtion", () => { require("fs").__setMockFiles({ testItems: ["NodesCompleter.js", "NodesCompleter.js.map", "UICompleter.js", "UICompleter.js.map"] }); it("Should import the completers' modules and push them into the completer's array", () => { const expectedCompleters = [ new NodeCompleter, new UICompleter ]; const completers = new Completers(); return completers.init().then(() => { expect(expectedCompleters).toEqual(completers.completers); }); }); }); describe("Updating the completer modules' project paths", () => { it("Should iterate over the completer modules' and update their project path", () => { const expectedProjectPath = 'c:/fake/path/'; const completers = new Completers(); return completers.init().then(() => { completers.setPath(expectedProjectPath); for (const completer of completers.completers) { expect(completer.projectPath).toEqual(expectedProjectPath); } }); }); }); describe("Getting all of the available completions for the project", () => { it("Should iterate over the completer modules' and return a concatenated array of all completion items", () => { const expectedCompletionItems = [ { label: "a", kind: CompletionItemKind.Constant, detail: "Node" }, { label: "b", kind: CompletionItemKind.Constant, detail: "Node" }, { label: "a", kind: CompletionItemKind.Function, detail: "eko_ui_0", documentation: { kind: "markdown", value: "" } }, { label: "b", kind: CompletionItemKind.Function, detail: "eko_ui_1", documentation: { kind: "markdown", value: "" } } ] const completers = new Completers(); return completers.init().then(() => { const completionItems = completers.getItems({ textDocument: { uri: 'some uri' }, position: { line: 0, character: 0 } }); expect(completionItems).toEqual(expectedCompletionItems); }); }); });