🎨 fix test-related stuff
This commit is contained in:
parent
d5895fe30c
commit
7c30dff354
11 changed files with 72 additions and 27 deletions
|
|
@ -7,6 +7,8 @@ import glob from "glob";
|
|||
* mochaRunner.js then runs tests using Mocha class
|
||||
*/
|
||||
|
||||
console.log("Bundling tests...");
|
||||
|
||||
// Bundles script to run tests on VSCode host + mocha runner that will be invoked from within VSCode host
|
||||
await esbuild.build({
|
||||
entryPoints: [
|
||||
|
|
@ -17,7 +19,7 @@ await esbuild.build({
|
|||
"src/test/runner/mochaRunner.ts",
|
||||
],
|
||||
bundle: true,
|
||||
outdir: "out/test/runner",
|
||||
outdir: "out",
|
||||
|
||||
external: [
|
||||
"vscode",
|
||||
|
|
@ -44,7 +46,7 @@ await esbuild.build({
|
|||
// Tests can be added anywhere in src folder
|
||||
entryPoints: glob.sync("src/**/*.test.ts"),
|
||||
bundle: true,
|
||||
outdir: "out/test/test-suites",
|
||||
outdir: "out",
|
||||
external: [
|
||||
"vscode",
|
||||
|
||||
|
|
@ -58,4 +60,8 @@ await esbuild.build({
|
|||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
".node": "file",
|
||||
},
|
||||
// To allow import.meta.path for transformers.js
|
||||
// https://github.com/evanw/esbuild/issues/1492#issuecomment-893144483
|
||||
inject: ["./scripts/importMetaUrl.js"],
|
||||
define: { "import.meta.url": "importMetaUrl" },
|
||||
});
|
||||
|
|
|
|||
|
|
@ -456,7 +456,7 @@
|
|||
"rebuild": "electron-rebuild -v 19.1.8 node-pty",
|
||||
"lint": "eslint src --ext ts",
|
||||
"build-test": "npm run esbuild && npm run prepackage && node esbuild.test.mjs",
|
||||
"test": "npm run build-test && node ./out/test/runner/runTestOnVSCodeHost.js",
|
||||
"test": "npm run build-test && node ./out/runTestOnVSCodeHost.js",
|
||||
"prepackage": "node scripts/prepackage.js",
|
||||
"package": "node scripts/package.js",
|
||||
"package:pre-release": "node scripts/package.js --pre-release",
|
||||
|
|
|
|||
|
|
@ -321,7 +321,10 @@ const exe = os === "win32" ? ".exe" : "";
|
|||
await new Promise((resolve, reject) => {
|
||||
ncp(
|
||||
path.join(__dirname, "../../../core/node_modules/sqlite3/build"),
|
||||
path.join(__dirname, "../out/build"),
|
||||
// sqlite will look for the binary at a number of paths relative the current working directory
|
||||
// including build/Release, out/Release, and Release
|
||||
// build/ from the node_module contains Release/...
|
||||
path.join(__dirname, "../out"),
|
||||
(error) => {
|
||||
if (error) {
|
||||
console.warn("[error] Error copying sqlite3 files", error);
|
||||
|
|
@ -334,7 +337,12 @@ const exe = os === "win32" ? ".exe" : "";
|
|||
});
|
||||
|
||||
// Copy node_modules for pre-built binaries
|
||||
const NODE_MODULES_TO_COPY = ["esbuild", "@esbuild", "@lancedb", "@vscode"];
|
||||
const NODE_MODULES_TO_COPY = [
|
||||
"esbuild",
|
||||
"@esbuild",
|
||||
"@lancedb",
|
||||
"@vscode/ripgrep",
|
||||
];
|
||||
fs.mkdirSync("out/node_modules", { recursive: true });
|
||||
|
||||
await Promise.all(
|
||||
|
|
@ -419,7 +427,7 @@ function validateFilesPresent() {
|
|||
// Worker required by jsdom
|
||||
"out/xhr-sync-worker.js",
|
||||
// SQLite3 Node native module
|
||||
"out/build/Release/node_sqlite3.node",
|
||||
"out/Release/node_sqlite3.node",
|
||||
|
||||
// out/node_modules (to be accessed by extension.js)
|
||||
`out/node_modules/@vscode/ripgrep/bin/rg${exe}`,
|
||||
|
|
|
|||
|
|
@ -40,6 +40,15 @@ function showRefactorMigrationMessage(
|
|||
}
|
||||
}
|
||||
|
||||
// Ideally the only global variable
|
||||
// Used in test/test-suites
|
||||
let resolveVsCodeExtension: (value: VsCodeExtension) => void;
|
||||
export let vscodeExtensionPromise: Promise<VsCodeExtension> = new Promise(
|
||||
(resolve) => {
|
||||
resolveVsCodeExtension = resolve;
|
||||
},
|
||||
);
|
||||
|
||||
export async function activateExtension(context: vscode.ExtensionContext) {
|
||||
// Add necessary files
|
||||
getTsConfigPath();
|
||||
|
|
@ -49,7 +58,7 @@ export async function activateExtension(context: vscode.ExtensionContext) {
|
|||
setupInlineTips(context);
|
||||
showRefactorMigrationMessage(context);
|
||||
|
||||
const vscodeExtension = new VsCodeExtension(context);
|
||||
resolveVsCodeExtension(new VsCodeExtension(context));
|
||||
|
||||
migrate("showWelcome_1", () => {
|
||||
vscode.commands.executeCommand(
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ import { TabAutocompleteModel } from "../util/loadAutocompleteModel";
|
|||
import { VsCodeWebviewProtocol } from "../webviewProtocol";
|
||||
|
||||
export class VsCodeExtension {
|
||||
// Currently some of these are public so they can be used in testing (test/test-suites)
|
||||
|
||||
private configHandler: ConfigHandler;
|
||||
private extensionContext: vscode.ExtensionContext;
|
||||
private ide: VsCodeIde;
|
||||
|
|
@ -27,7 +29,7 @@ export class VsCodeExtension {
|
|||
private indexer: CodebaseIndexer;
|
||||
private diffManager: DiffManager;
|
||||
private verticalDiffManager: VerticalPerLineDiffManager;
|
||||
private webviewProtocol: VsCodeWebviewProtocol;
|
||||
webviewProtocol: VsCodeWebviewProtocol;
|
||||
|
||||
constructor(context: vscode.ExtensionContext) {
|
||||
this.diffManager = new DiffManager(context);
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ export function run() {
|
|||
|
||||
// See esbuild.test.mjs for more details
|
||||
// Assumes this file is in out/test/runner/mochaRunner.js
|
||||
const compiledTestSuitesDirectory = path.resolve(__dirname, "../test-suites");
|
||||
const compiledTestSuitesDirectory = path.resolve(__dirname);
|
||||
|
||||
glob
|
||||
.sync("**/**.test.js", { cwd: compiledTestSuitesDirectory })
|
||||
|
|
@ -26,6 +26,10 @@ export function run() {
|
|||
mocha.addFile(path.resolve(compiledTestSuitesDirectory, file));
|
||||
});
|
||||
|
||||
console.log(
|
||||
`Testing files in ${compiledTestSuitesDirectory}: ${mocha.files}`,
|
||||
);
|
||||
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
try {
|
||||
// Run the mocha test
|
||||
|
|
|
|||
|
|
@ -6,15 +6,15 @@ async function main() {
|
|||
// 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, "../../../");
|
||||
// Assumes this file is in out/runTestOnVSCodeHost.js
|
||||
const extensionDevelopmentPath = path.resolve(__dirname, "../");
|
||||
console.log("extensionDevelopmentPath", extensionDevelopmentPath);
|
||||
|
||||
// The path to test runner
|
||||
// Passed to --extensionTestsPath
|
||||
const extensionTestsPath = path.resolve(
|
||||
extensionDevelopmentPath,
|
||||
"out/test/runner/mochaRunner",
|
||||
"out/mochaRunner",
|
||||
);
|
||||
|
||||
const extensionTestsEnv = {};
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
import * as assert from "assert";
|
||||
import { describe, test } from "mocha";
|
||||
import * as vscode from "vscode";
|
||||
|
||||
describe("Extension Test Suite", () => {
|
||||
vscode.window.showInformationMessage("Start all tests.");
|
||||
|
||||
test("Sample test", async () => {
|
||||
assert.strictEqual(-1, [1, 2, 3].indexOf(5));
|
||||
assert.strictEqual(-1, [1, 2, 3].indexOf(0));
|
||||
await new Promise((resolve) => setTimeout(resolve, 10_000));
|
||||
});
|
||||
});
|
||||
21
extensions/vscode/src/test/test-suites/main.test.ts
Normal file
21
extensions/vscode/src/test/test-suites/main.test.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import * as assert from "assert";
|
||||
import { describe, test } from "mocha";
|
||||
import * as vscode from "vscode";
|
||||
import { vscodeExtensionPromise } from "../../activation/activate";
|
||||
|
||||
describe("Extension Test Suite", () => {
|
||||
vscode.window.showInformationMessage("Start all tests.");
|
||||
|
||||
// test("Make sure that nothing breaks after 10 seconds", async () => {
|
||||
// await new Promise((resolve) => setTimeout(resolve, 10_000));
|
||||
// });
|
||||
|
||||
test("Get the default model from webview", async () => {
|
||||
const extension = await vscodeExtensionPromise;
|
||||
const title = await extension.webviewProtocol.request(
|
||||
"getDefaultModelTitle",
|
||||
undefined,
|
||||
);
|
||||
assert.strictEqual(typeof title, "string");
|
||||
});
|
||||
});
|
||||
|
|
@ -57,7 +57,11 @@ export interface IIdeMessenger {
|
|||
}
|
||||
|
||||
export class IdeMessenger implements IIdeMessenger {
|
||||
ide = new MessageIde(this.request);
|
||||
ide: IDE;
|
||||
|
||||
constructor() {
|
||||
this.ide = new MessageIde(this.request.bind(this));
|
||||
}
|
||||
|
||||
private _postToIde(messageType: string, data: any, messageId?: string) {
|
||||
if (typeof vscode === "undefined") {
|
||||
|
|
|
|||
|
|
@ -13,7 +13,11 @@ export function getLocalStorage<T extends keyof LocalStorageTypes>(
|
|||
if (value === null) {
|
||||
return undefined;
|
||||
}
|
||||
return JSON.parse(value);
|
||||
try {
|
||||
return JSON.parse(value);
|
||||
} catch (e) {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export function setLocalStorage<T extends keyof LocalStorageTypes>(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue