Refactor test scripts and update build configurations
- Added a new esbuild for: - bundling test runners (run tests on vscode + mocha runner) - bundling all tests in the project - Some opinionated renamings / moving test related things around - Changed output directory in tsconfig to avoid overriding the entire out directory - bundles tests also go there Some poking around trying to deprecate jest as it is not used and mocha is more often used for vscode extension testing. Though I assume jest was added to test GUI within extension. This work was started because there are compilation issues with the current setup and neither of the tests are actually working so figured getting one to a working spot is a good start
This commit is contained in:
parent
0fc56305d7
commit
c12be8daf6
16 changed files with 6434 additions and 2988 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import * as esbuild from "esbuild";
|
||||
// esbuild ./src/extension.ts --bundle --outfile=out/extension.js --external:vscode --format=cjs --platform=node
|
||||
|
||||
// Bundles the extension into one file
|
||||
await esbuild.build({
|
||||
entryPoints: ["src/extension.ts"],
|
||||
bundle: true,
|
||||
|
|
@ -9,6 +10,7 @@ await esbuild.build({
|
|||
platform: "node",
|
||||
sourcemap: true,
|
||||
loader: {
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
".node": "file",
|
||||
},
|
||||
});
|
||||
|
|
|
|||
61
extension/esbuild.test.mjs
Normal file
61
extension/esbuild.test.mjs
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
import * as esbuild from "esbuild";
|
||||
import glob from "glob";
|
||||
|
||||
/**
|
||||
* Bundles tests into multiple files, runTestOnVSCodeHost is then run using node runTestOnVSCodeHost.js
|
||||
* It downloads vscode, starts it and passes test file to run - mochaRunner.js
|
||||
* mochaRunner.js then runs tests using Mocha class
|
||||
*/
|
||||
|
||||
// Bundles script to run tests on VSCode host + mocha runner that will be invoked from within VSCode host
|
||||
await esbuild.build({
|
||||
entryPoints: [
|
||||
// Runs mocha runner on VSCode host usig runTests from @vscode/test-electron
|
||||
"src/test-runner/runTestOnVSCodeHost.ts",
|
||||
|
||||
// Runs the bundled tests using Mocha class
|
||||
"src/test-runner/mochaRunner.ts",
|
||||
],
|
||||
bundle: true,
|
||||
outdir: "out/test-runner",
|
||||
|
||||
external: [
|
||||
"vscode",
|
||||
|
||||
// Its important to externalize mocha, otherwise mocha seems to be not initialized properly when running tests
|
||||
// Example warning by esbuild when mocha is not externalized:
|
||||
// [WARNING] "./reporters/parallel-buffered" should be marked as external for use with "require.resolve" [require-resolve-not-external]
|
||||
"mocha",
|
||||
],
|
||||
format: "cjs",
|
||||
platform: "node",
|
||||
sourcemap: true,
|
||||
loader: {
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
".node": "file",
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* Note: Bundling is done to work around import issues, for example with fkill that does not provide cjs module.
|
||||
* Rather than figuring out a combination of tsconfig.json that would work, I decided to bundle tests instead.
|
||||
*/
|
||||
await esbuild.build({
|
||||
// Tests can be added anywhere in src folder
|
||||
entryPoints: glob.sync("src/**/*.test.ts"),
|
||||
bundle: true,
|
||||
outdir: "out/test-suites",
|
||||
external: [
|
||||
"vscode",
|
||||
|
||||
// Its important to externalize mocha, otherwise mocha seems to be not initialized properly when running tests
|
||||
"mocha",
|
||||
],
|
||||
format: "cjs",
|
||||
platform: "node",
|
||||
sourcemap: true,
|
||||
loader: {
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
".node": "file",
|
||||
},
|
||||
});
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
module.exports = {
|
||||
testEnvironment: "node",
|
||||
preset: "ts-jest",
|
||||
};
|
||||
9140
extension/package-lock.json
generated
9140
extension/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -192,17 +192,15 @@
|
|||
"typegen": "node scripts/typegen.js",
|
||||
"clientgen": "rm -rf src/client/ && npx @openapitools/openapi-generator-cli generate -i ../schema/openapi.json -g typescript-fetch -o src/client/ --additional-properties=supportsES6=true,npmVersion=8.19.2,typescriptThreePlus=true",
|
||||
"rebuild": "electron-rebuild -v 19.1.8 node-pty",
|
||||
"pretest": "npm run tsc && npm run lint",
|
||||
"lint": "eslint src --ext ts",
|
||||
"test": "node ./out/test/runTest.js",
|
||||
"jest": "jest --config ./jest.config.js",
|
||||
"build-test": "tsc && node esbuild.test.mjs",
|
||||
"test": "npm run build-test && node ./out/test-runner/runTestOnVSCodeHost.js",
|
||||
"package": "npm install && npm run typegen && npm run clientgen && cd react-app && npm install && npm run build && cd .. && mkdir -p ./build && vsce package --out ./build"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nestjs/common": "^8.4.7",
|
||||
"@openapitools/openapi-generator-cli": "^2.5.2",
|
||||
"@types/glob": "^8.0.0",
|
||||
"@types/jest": "^29.5.2",
|
||||
"@types/mocha": "^10.0.1",
|
||||
"@types/node": "16.x",
|
||||
"@types/node-fetch": "^2.6.2",
|
||||
|
|
@ -216,7 +214,6 @@
|
|||
"esbuild": "^0.17.19",
|
||||
"eslint": "^8.28.0",
|
||||
"glob": "^8.0.3",
|
||||
"jest": "^29.5.0",
|
||||
"json-schema-to-typescript": "^12.0.0",
|
||||
"mocha": "^10.1.0",
|
||||
"ts-jest": "^29.1.1",
|
||||
|
|
|
|||
|
|
@ -1,7 +0,0 @@
|
|||
const vscode = {
|
||||
window: {
|
||||
onDidChangeVisibleTextEditors: jest.fn(),
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = vscode;
|
||||
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -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({
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
|
||||
|
|
|
|||
35
extension/src/test-runner/mochaRunner.ts
Normal file
35
extension/src/test-runner/mochaRunner.ts
Normal file
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
19
extension/src/test-suite/environmentSetup.test.ts
Normal file
19
extension/src/test-suite/environmentSetup.test.ts
Normal file
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
@ -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", () => {
|
||||
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
@ -2,8 +2,15 @@
|
|||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "ES2020",
|
||||
"outDir": "out",
|
||||
"lib": ["ES2020", "dom", "es6", "es5", "dom.iterable", "scripthost"],
|
||||
"outDir": "out/tsc/src",
|
||||
"lib": [
|
||||
"ES2020",
|
||||
"dom",
|
||||
"es6",
|
||||
"es5",
|
||||
"dom.iterable",
|
||||
"scripthost"
|
||||
],
|
||||
"sourceMap": true,
|
||||
"rootDir": "src",
|
||||
"strict": true /* enable all strict type-checking options */,
|
||||
|
|
@ -11,7 +18,10 @@
|
|||
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
||||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
||||
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
||||
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
|
||||
"resolveJsonModule": true /* Enable importing .json files */
|
||||
},
|
||||
"include": ["src/**/*"]
|
||||
}
|
||||
"include": [
|
||||
"src/**/*",
|
||||
]
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue