Elffuss BraidHub

kikocis/continue public

e841ee848161 · 2.9 KiBRawPermalink
1import assert from "node:assert";
2import path from "node:path";
3
4import { describe, test } from "mocha";
5import * as vscode from "vscode";
6
7import { VsCodeIdeUtils } from "../../util/ideUtils";
8import { testWorkspacePath } from "../runner/runTestOnVSCodeHost";
9
10const util = require("node:util");
11const asyncExec = util.promisify(require("node:child_process").exec);
12
13/*
14 TODO check uri => path assumptions, will only work in some environments.
15*/
16describe("IDE Utils", () => {
17 const utils = new VsCodeIdeUtils();
18 const testPyPath = path.join(testWorkspacePath, "test.py");
19 const testJsPath = path.join(testWorkspacePath, "test-folder", "test.js");
20
21 test("getWorkspaceDirectories", async () => {
22 const [dir] = utils.getWorkspaceDirectories();
23 assert(dir.toString().endsWith("test-workspace"));
24 });
25
26 test("fileExists", async () => {
27 const exists2 = await utils.fileExists(
28 vscode.Uri.file(path.join(testWorkspacePath, "test.py")),
29 );
30 assert(exists2);
31 });
32
33 test("getOpenFiles", async () => {
34 let openFiles = utils.getOpenFiles();
35 assert(openFiles.length === 0);
36 // await utils.openFile(testPyPath);
37 let document = await vscode.workspace.openTextDocument(testPyPath);
38 await vscode.window.showTextDocument(document, {
39 preview: false,
40 });
41 openFiles = utils.getOpenFiles();
42 assert(openFiles.length === 1);
43 assert(openFiles[0].fsPath === testPyPath);
44
45 document = await vscode.workspace.openTextDocument(testJsPath);
46 await vscode.window.showTextDocument(document, {
47 preview: false,
48 });
49 openFiles = utils.getOpenFiles();
50 assert(openFiles.length === 2);
51 assert(openFiles.find((f) => f.fsPath === testPyPath));
52 assert(openFiles.find((f) => f.fsPath === testJsPath));
53 });
54
55 test("getUniqueId", async () => {
56 const uniqueId = utils.getUniqueId();
57 assert(uniqueId.length === 64);
58 const regex = /^[a-z0-9]+$/;
59 assert(regex.test(uniqueId));
60 });
61
62 test.skip("getTerminalContents", async () => {
63 await new Promise((resolve) => setTimeout(resolve, 1000));
64 const terminal = vscode.window.createTerminal();
65 await new Promise((resolve) => setTimeout(resolve, 1000));
66 terminal.show();
67 await new Promise((resolve) => setTimeout(resolve, 1000));
68 terminal.sendText("echo abcdefg", true);
69 const contents = await utils.getTerminalContents(1);
70 console.log("TERMINAL CONTENTS: ", contents);
71 assert(contents.includes("abcdefg"));
72 terminal.dispose();
73 });
74
75 test("noDiff", async () => {
76 const noDiff = await utils.getDiff(false);
77 assert(noDiff.length === 0);
78 });
79
80 test.skip("getBranch", async () => {
81 const uri = vscode.Uri.file(testWorkspacePath);
82 const branch = await utils.getBranch(uri);
83 assert(typeof branch === "string");
84 const { stdout } = await asyncExec("git rev-parse --abbrev-ref HEAD", {
85 cwd: __dirname,
86 });
87 assert(branch === stdout?.trim());
88 });
89});