summaryrefslogtreecommitdiff
path: root/extension/src
diff options
context:
space:
mode:
Diffstat (limited to 'extension/src')
-rw-r--r--extension/src/__mocks__/vscode.ts7
-rw-r--r--extension/src/activation/test/environmentSetup.test.ts70
-rw-r--r--extension/src/continueIdeClient.ts4
-rw-r--r--extension/src/terminal/terminalEmulator.ts2
-rw-r--r--extension/src/test-runner/mochaRunner.ts35
-rw-r--r--extension/src/test-runner/runTestOnVSCodeHost.ts (renamed from extension/src/test/runTest.ts)9
-rw-r--r--extension/src/test-suite/environmentSetup.test.ts19
-rw-r--r--extension/src/test-suite/extension.test.ts (renamed from extension/src/test/suite/extension.test.ts)0
-rw-r--r--extension/src/test-suite/util.test.ts (renamed from extension/src/test/suite/util.test.ts)4
-rw-r--r--extension/src/test/suite/index.ts38
10 files changed, 64 insertions, 124 deletions
diff --git a/extension/src/__mocks__/vscode.ts b/extension/src/__mocks__/vscode.ts
deleted file mode 100644
index d415b5a0..00000000
--- a/extension/src/__mocks__/vscode.ts
+++ /dev/null
@@ -1,7 +0,0 @@
-const vscode = {
- window: {
- onDidChangeVisibleTextEditors: jest.fn(),
- },
-};
-
-module.exports = vscode;
diff --git a/extension/src/activation/test/environmentSetup.test.ts b/extension/src/activation/test/environmentSetup.test.ts
deleted file mode 100644
index ca487416..00000000
--- a/extension/src/activation/test/environmentSetup.test.ts
+++ /dev/null
@@ -1,70 +0,0 @@
-const child_process = require("child_process");
-import { platform } from "os";
-import { getPythonPipCommands } from "../environmentSetup";
-
-jest.mock("os");
-jest.mock("child_process");
-
-function mockPythonVersionMappings(mappings: { [pythonCmd: string]: string }) {
- (child_process.exec as jest.Mock).mockImplementation(
- (command: string, options: any) => {
- const pythonCmd = command.split(" ")[0];
- if (pythonCmd in mappings) {
- return Promise.resolve([mappings[pythonCmd], ""]);
- } else {
- return Promise.resolve(["", stubStderr]);
- }
- }
- );
-}
-
-const stubStderr =
- "This is a stub stderr, but will be checked only for existence.";
-describe("getPythonPipCommands", () => {
- describe("on Windows", () => {
- it("should return the correct Python and Pip commands", async () => {
- (platform as jest.Mock).mockReturnValue("win32");
- mockPythonVersionMappings({
- python: "Python 3.8.0",
- });
-
- const [pythonCmd, pipCmd] = await getPythonPipCommands();
-
- expect(pythonCmd).toBe("python");
- expect(pipCmd).toBe("pip");
-
- jest.restoreAllMocks();
- });
- describe("on MacOS", () => {
- (platform as jest.Mock).mockReturnValue("darwin");
- it("should check through all python versions after finding 3.7", async () => {
- mockPythonVersionMappings({
- python: "",
- python3: "Python 3.7.0",
- "python3.11": "Python 3.11.0",
- });
-
- const [pythonCmd, pipCmd] = await getPythonPipCommands();
-
- expect(pythonCmd).toBe("python3.11");
- expect(pipCmd).toBe("pip3.11");
-
- jest.restoreAllMocks();
- });
-
- it("should use python3 if that maps to valid version", async () => {
- mockPythonVersionMappings({
- python: "",
- python3: "Python 3.8.0",
- });
-
- const [pythonCmd, pipCmd] = await getPythonPipCommands();
-
- expect(pythonCmd).toBe("python3");
- expect(pipCmd).toBe("pip3");
-
- jest.restoreAllMocks();
- });
- });
- });
-});
diff --git a/extension/src/continueIdeClient.ts b/extension/src/continueIdeClient.ts
index cb7baaa6..d89093ca 100644
--- a/extension/src/continueIdeClient.ts
+++ b/extension/src/continueIdeClient.ts
@@ -12,7 +12,7 @@ import {
rejectSuggestionCommand,
} from "./suggestions";
import { FileEditWithFullContents } from "../schema/FileEditWithFullContents";
-import fs = require("fs");
+import * as fs from 'fs';
import { WebsocketMessenger } from "./util/messenger";
import { diffManager } from "./diffs";
const os = require("os");
@@ -383,7 +383,7 @@ class IdeProtocolClient {
async getUserSecret(key: string) {
// Check if secret already exists in VS Code settings (global)
let secret = vscode.workspace.getConfiguration("continue").get(key);
- if (typeof secret !== "undefined" && secret !== null) return secret;
+ if (typeof secret !== "undefined" && secret !== null) {return secret;}
// If not, ask user for secret
secret = await vscode.window.showInputBox({
diff --git a/extension/src/terminal/terminalEmulator.ts b/extension/src/terminal/terminalEmulator.ts
index bab59c78..3b90f9f8 100644
--- a/extension/src/terminal/terminalEmulator.ts
+++ b/extension/src/terminal/terminalEmulator.ts
@@ -1,7 +1,7 @@
/* Terminal emulator - commented because node-pty is causing problems. */
import * as vscode from "vscode";
-import os = require("os");
+import * as os from 'os';
import stripAnsi from "strip-ansi";
import { longestCommonSubsequence } from "../util/lcs";
diff --git a/extension/src/test-runner/mochaRunner.ts b/extension/src/test-runner/mochaRunner.ts
new file mode 100644
index 00000000..b964fe5f
--- /dev/null
+++ b/extension/src/test-runner/mochaRunner.ts
@@ -0,0 +1,35 @@
+import * as path from "path";
+import Mocha from "mocha";
+import * as glob from "glob";
+
+export function run() {
+ // Create the mocha test
+ const mocha = new Mocha({
+ ui: "tdd",
+ color: true,
+ });
+
+ // See esbuild.test.mjs for more details
+ // Assumes this file is in out/test-runner/mochaRunner.js
+ const compiledTestSuitesDirectory = path.resolve(__dirname, "../test-suites");
+
+ glob.sync("**/**.test.js", { cwd: compiledTestSuitesDirectory }).forEach((file) => {
+ mocha.addFile(path.resolve(compiledTestSuitesDirectory, file));
+ });
+
+ return new Promise<void>((c, e) => {
+ try {
+ // Run the mocha test
+ mocha.run((failures) => {
+ if (failures > 0) {
+ e(new Error(`${failures} tests failed.`));
+ } else {
+ c();
+ }
+ });
+ } catch (err) {
+ console.error(err);
+ e(err);
+ }
+ });
+}
diff --git a/extension/src/test/runTest.ts b/extension/src/test-runner/runTestOnVSCodeHost.ts
index e810ed5b..2a542ffc 100644
--- a/extension/src/test/runTest.ts
+++ b/extension/src/test-runner/runTestOnVSCodeHost.ts
@@ -1,21 +1,22 @@
-import * as path from "path";
-
import { runTests } from "@vscode/test-electron";
+import * as path from "path";
async function main() {
try {
// The folder containing the Extension Manifest package.json
// Passed to `--extensionDevelopmentPath`
+
+ // Assumes this file is in out/test-runner/runTestOnVSCodeHost.js
const extensionDevelopmentPath = path.resolve(__dirname, "../../");
// The path to test runner
// Passed to --extensionTestsPath
- const extensionTestsPath = path.resolve(__dirname, "./suite/index");
+ const extensionTestsPath = path.resolve(extensionDevelopmentPath, "out/test-runner/mochaRunner");
// Download VS Code, unzip it and run the integration test
await runTests({ extensionDevelopmentPath, extensionTestsPath });
} catch (err) {
- console.error("Failed to run tests");
+ console.error("Failed to run tests", err);
process.exit(1);
}
}
diff --git a/extension/src/test-suite/environmentSetup.test.ts b/extension/src/test-suite/environmentSetup.test.ts
new file mode 100644
index 00000000..7610e70d
--- /dev/null
+++ b/extension/src/test-suite/environmentSetup.test.ts
@@ -0,0 +1,19 @@
+import { test, describe } from "mocha";
+import * as assert from "assert";
+
+import { getContinueServerUrl } from "../bridge";
+import { startContinuePythonServer } from "../activation/environmentSetup";
+import fetch from "node-fetch";
+
+describe("Can start python server", () => {
+ test("Can start python server", async () => {
+ await startContinuePythonServer();
+
+ await new Promise((resolve) => setTimeout(resolve, 50));
+
+ // Check if server is running
+ const serverUrl = getContinueServerUrl();
+ const response = await fetch(`${serverUrl}/health`);
+ assert.equal(response.status, 200);
+ });
+});
diff --git a/extension/src/test/suite/extension.test.ts b/extension/src/test-suite/extension.test.ts
index 890820b2..890820b2 100644
--- a/extension/src/test/suite/extension.test.ts
+++ b/extension/src/test-suite/extension.test.ts
diff --git a/extension/src/test/suite/util.test.ts b/extension/src/test-suite/util.test.ts
index 0ba1473b..2b301b0c 100644
--- a/extension/src/test/suite/util.test.ts
+++ b/extension/src/test-suite/util.test.ts
@@ -1,6 +1,6 @@
import { test, describe } from "mocha";
-import * as assert from "assert";
-import { convertSingleToDoubleQuoteJSON } from "../../util/util";
+import assert from "assert";
+import { convertSingleToDoubleQuoteJSON } from "../util/util";
describe("utils.ts", () => {
test("convertSingleToDoubleQuoteJson", () => {
diff --git a/extension/src/test/suite/index.ts b/extension/src/test/suite/index.ts
deleted file mode 100644
index 772a0152..00000000
--- a/extension/src/test/suite/index.ts
+++ /dev/null
@@ -1,38 +0,0 @@
-import * as path from "path";
-import * as Mocha from "mocha";
-import * as glob from "glob";
-
-export function run(): Promise<void> {
- // Create the mocha test
- const mocha = new Mocha({
- ui: "tdd",
- color: true,
- });
-
- const testsRoot = path.resolve(__dirname, "..");
-
- return new Promise((c, e) => {
- glob("**/**.test.js", { cwd: testsRoot }, (err, files) => {
- if (err) {
- return e(err);
- }
-
- // Add files to the test suite
- files.forEach((f) => mocha.addFile(path.resolve(testsRoot, f)));
-
- try {
- // Run the mocha test
- mocha.run((failures: any) => {
- if (failures > 0) {
- e(new Error(`${failures} tests failed.`));
- } else {
- c();
- }
- });
- } catch (err) {
- console.error(err);
- e(err);
- }
- });
- });
-}