Create new activated-extension test suite
This commit is contained in:
@@ -8,6 +8,7 @@ module.exports = {
|
||||
projects: [
|
||||
"<rootDir>/src/view",
|
||||
"<rootDir>/test/unit-tests",
|
||||
"<rootDir>/test/vscode-tests/activated-extension",
|
||||
"<rootDir>/test/vscode-tests/cli-integration",
|
||||
"<rootDir>/test/vscode-tests/no-workspace",
|
||||
"<rootDir>/test/vscode-tests/minimal-workspace",
|
||||
|
||||
@@ -1330,6 +1330,7 @@
|
||||
"test:unit": "cross-env TZ=UTC LANG=en-US jest --projects test/unit-tests",
|
||||
"test:view": "jest --projects src/view",
|
||||
"integration": "npm-run-all integration:*",
|
||||
"integration:activated-extension": "jest --projects test/vscode-tests/activated-extension",
|
||||
"integration:no-workspace": "jest --projects test/vscode-tests/no-workspace",
|
||||
"integration:minimal-workspace": "jest --projects test/vscode-tests/minimal-workspace",
|
||||
"cli-integration": "jest --projects test/vscode-tests/cli-integration",
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
const path = require("path");
|
||||
|
||||
const {
|
||||
config: baseConfig,
|
||||
rootDir,
|
||||
} = require("../jest-runner-vscode.config.base");
|
||||
|
||||
/** @type import("jest-runner-vscode").RunnerOptions */
|
||||
const config = {
|
||||
...baseConfig,
|
||||
launchArgs: [
|
||||
...(baseConfig.launchArgs ?? []),
|
||||
// explicitly disable extensions that are known to interfere with the CLI integration tests
|
||||
"--disable-extension",
|
||||
"eamodio.gitlens",
|
||||
"--disable-extension",
|
||||
"github.codespaces",
|
||||
"--disable-extension",
|
||||
"github.copilot",
|
||||
path.resolve(rootDir, "test/data"),
|
||||
],
|
||||
extensionTestsEnv: {
|
||||
...baseConfig.extensionTestsEnv,
|
||||
INTEGRATION_TEST_MODE: "true",
|
||||
},
|
||||
retries: 3,
|
||||
};
|
||||
|
||||
module.exports = config;
|
||||
@@ -0,0 +1,11 @@
|
||||
import type { Config } from "jest";
|
||||
|
||||
import baseConfig from "../jest.config.base";
|
||||
|
||||
const config: Config = {
|
||||
...baseConfig,
|
||||
runner: "<rootDir>/../jest-runner-installed-extensions.ts",
|
||||
setupFilesAfterEnv: ["<rootDir>/jest.setup.ts"],
|
||||
};
|
||||
|
||||
export default config;
|
||||
@@ -0,0 +1 @@
|
||||
import "../jest.activated-extension.setup";
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
importArchiveDatabase,
|
||||
promptImportInternetDatabase,
|
||||
} from "../../../src/databaseFetcher";
|
||||
import { cleanDatabases, dbLoc, DB_URL, storagePath } from "./global.helper";
|
||||
import { cleanDatabases, dbLoc, DB_URL, storagePath } from "../global.helper";
|
||||
|
||||
jest.setTimeout(60_000);
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import baseConfig from "../jest.config.base";
|
||||
|
||||
const config: Config = {
|
||||
...baseConfig,
|
||||
runner: "<rootDir>/jest-runner-cli-integration.ts",
|
||||
runner: "<rootDir>/../jest-runner-installed-extensions.ts",
|
||||
setupFilesAfterEnv: ["<rootDir>/jest.setup.ts"],
|
||||
};
|
||||
|
||||
|
||||
@@ -1,59 +1,8 @@
|
||||
import {
|
||||
mkdirpSync,
|
||||
existsSync,
|
||||
createWriteStream,
|
||||
realpathSync,
|
||||
} from "fs-extra";
|
||||
import { dirname } from "path";
|
||||
import fetch from "node-fetch";
|
||||
import { DB_URL, dbLoc, setStoragePath, storagePath } from "./global.helper";
|
||||
import * as tmp from "tmp";
|
||||
import { CUSTOM_CODEQL_PATH_SETTING } from "../../../src/config";
|
||||
import { ConfigurationTarget, env, extensions, workspace } from "vscode";
|
||||
import { beforeEachAction } from "../test-config";
|
||||
import { workspace } from "vscode";
|
||||
|
||||
// create an extension storage location
|
||||
let removeStorage: tmp.DirResult["removeCallback"] | undefined;
|
||||
|
||||
beforeAll(async () => {
|
||||
// Set the CLI version here before activation to ensure we don't accidentally try to download a cli
|
||||
await beforeEachAction();
|
||||
await CUSTOM_CODEQL_PATH_SETTING.updateValue(
|
||||
process.env.CLI_PATH,
|
||||
ConfigurationTarget.Workspace,
|
||||
);
|
||||
|
||||
// ensure the test database is downloaded
|
||||
mkdirpSync(dirname(dbLoc));
|
||||
if (!existsSync(dbLoc)) {
|
||||
console.log(`Downloading test database to ${dbLoc}`);
|
||||
|
||||
await new Promise((resolve, reject) => {
|
||||
return fetch(DB_URL).then((response) => {
|
||||
const dest = createWriteStream(dbLoc);
|
||||
response.body.pipe(dest);
|
||||
|
||||
response.body.on("error", reject);
|
||||
dest.on("error", reject);
|
||||
dest.on("close", () => {
|
||||
resolve(dbLoc);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Create the temp directory to be used as extension local storage.
|
||||
const dir = tmp.dirSync();
|
||||
let storagePath = realpathSync(dir.name);
|
||||
if (storagePath.substring(0, 2).match(/[A-Z]:/)) {
|
||||
storagePath =
|
||||
storagePath.substring(0, 1).toLocaleLowerCase() +
|
||||
storagePath.substring(1);
|
||||
}
|
||||
setStoragePath(storagePath);
|
||||
|
||||
removeStorage = dir.removeCallback;
|
||||
import "../jest.activated-extension.setup";
|
||||
|
||||
beforeAll(() => {
|
||||
// check that the codeql folder is found in the workspace
|
||||
const folders = workspace.workspaceFolders;
|
||||
if (!folders) {
|
||||
@@ -70,30 +19,4 @@ beforeAll(async () => {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Activate the extension
|
||||
await extensions.getExtension("GitHub.vscode-codeql")?.activate();
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
jest.spyOn(env, "openExternal").mockResolvedValue(false);
|
||||
|
||||
await beforeEachAction();
|
||||
|
||||
await CUSTOM_CODEQL_PATH_SETTING.updateValue(
|
||||
process.env.CLI_PATH,
|
||||
ConfigurationTarget.Workspace,
|
||||
);
|
||||
});
|
||||
|
||||
// ensure extension is cleaned up.
|
||||
afterAll(async () => {
|
||||
// ensure temp directory is cleaned up.
|
||||
try {
|
||||
removeStorage?.();
|
||||
} catch (e) {
|
||||
// we are exiting anyway so don't worry about it.
|
||||
// most likely the directory this is a test on Windows and some files are locked.
|
||||
console.warn(`Failed to remove storage directory '${storagePath}': ${e}`);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -11,7 +11,7 @@ import { describeWithCodeQL } from "../cli";
|
||||
import { QueryServerClient } from "../../../src/query-server/queryserver-client";
|
||||
import { extLogger, ProgressReporter } from "../../../src/common";
|
||||
import { QueryResultType } from "../../../src/pure/new-messages";
|
||||
import { cleanDatabases, dbLoc, storagePath } from "./global.helper";
|
||||
import { cleanDatabases, dbLoc, storagePath } from "../global.helper";
|
||||
import { importArchiveDatabase } from "../../../src/databaseFetcher";
|
||||
|
||||
const baseDir = join(__dirname, "../../../test/data");
|
||||
|
||||
@@ -17,7 +17,7 @@ import { load, dump } from "js-yaml";
|
||||
|
||||
import { DatabaseItem, DatabaseManager } from "../../../src/databases";
|
||||
import { CodeQLExtensionInterface } from "../../../src/extension";
|
||||
import { cleanDatabases, dbLoc, storagePath } from "./global.helper";
|
||||
import { cleanDatabases, dbLoc, storagePath } from "../global.helper";
|
||||
import { importArchiveDatabase } from "../../../src/databaseFetcher";
|
||||
import { CodeQLCliServer } from "../../../src/cli";
|
||||
import { describeWithCodeQL } from "../cli";
|
||||
|
||||
@@ -28,7 +28,7 @@ import { RemoteQueriesManager } from "../../../../src/remote-queries/remote-quer
|
||||
import {
|
||||
fixWorkspaceReferences,
|
||||
restoreWorkspaceReferences,
|
||||
} from "../global.helper";
|
||||
} from "../../global.helper";
|
||||
import { createMockApp } from "../../../__mocks__/appMock";
|
||||
import { App } from "../../../../src/common/app";
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ import {
|
||||
fixWorkspaceReferences,
|
||||
restoreWorkspaceReferences,
|
||||
storagePath,
|
||||
} from "../global.helper";
|
||||
} from "../../global.helper";
|
||||
import { VariantAnalysisResultsManager } from "../../../../src/remote-queries/variant-analysis-results-manager";
|
||||
import { createMockVariantAnalysis } from "../../../factories/remote-queries/shared/variant-analysis";
|
||||
import * as VariantAnalysisModule from "../../../../src/remote-queries/shared/variant-analysis";
|
||||
|
||||
@@ -9,7 +9,7 @@ import * as fetchModule from "node-fetch";
|
||||
|
||||
import { VariantAnalysisResultsManager } from "../../../../src/remote-queries/variant-analysis-results-manager";
|
||||
import { CodeQLCliServer } from "../../../../src/cli";
|
||||
import { storagePath } from "../global.helper";
|
||||
import { storagePath } from "../../global.helper";
|
||||
import { faker } from "@faker-js/faker";
|
||||
import { createMockVariantAnalysisRepositoryTask } from "../../../factories/remote-queries/shared/variant-analysis-repo-tasks";
|
||||
import {
|
||||
|
||||
@@ -2,11 +2,11 @@ import { join } from "path";
|
||||
import { load, dump } from "js-yaml";
|
||||
import { realpathSync, readFileSync, writeFileSync } from "fs-extra";
|
||||
import { commands } from "vscode";
|
||||
import { DatabaseManager } from "../../../src/databases";
|
||||
import { CodeQLCliServer } from "../../../src/cli";
|
||||
import { removeWorkspaceRefs } from "../../../src/remote-queries/run-remote-query";
|
||||
import { DatabaseManager } from "../../src/databases";
|
||||
import { CodeQLCliServer } from "../../src/cli";
|
||||
import { removeWorkspaceRefs } from "../../src/remote-queries/run-remote-query";
|
||||
|
||||
// This file contains helpers shared between actual tests.
|
||||
// This file contains helpers shared between tests that work with an activated extension.
|
||||
|
||||
export const DB_URL =
|
||||
"https://github.com/github/vscode-codeql/files/5586722/simple-db.zip";
|
||||
@@ -8,9 +8,9 @@ import {
|
||||
downloadAndUnzipVSCode,
|
||||
resolveCliArgsFromVSCodeExecutablePath,
|
||||
} from "@vscode/test-electron";
|
||||
import { ensureCli } from "../ensureCli";
|
||||
import { ensureCli } from "./ensureCli";
|
||||
|
||||
export default class JestRunnerCliIntegration extends VSCodeTestRunner {
|
||||
export default class JestRunnerInstalledExtensions extends VSCodeTestRunner {
|
||||
async runTests(
|
||||
tests: JestRunner.Test[],
|
||||
watcher: JestRunner.TestWatcher,
|
||||
@@ -0,0 +1,82 @@
|
||||
import {
|
||||
mkdirpSync,
|
||||
existsSync,
|
||||
createWriteStream,
|
||||
realpathSync,
|
||||
} from "fs-extra";
|
||||
import { dirname } from "path";
|
||||
import fetch from "node-fetch";
|
||||
import { DB_URL, dbLoc, setStoragePath, storagePath } from "./global.helper";
|
||||
import * as tmp from "tmp";
|
||||
import { CUSTOM_CODEQL_PATH_SETTING } from "../../src/config";
|
||||
import { ConfigurationTarget, env, extensions } from "vscode";
|
||||
import { beforeEachAction } from "./test-config";
|
||||
|
||||
// create an extension storage location
|
||||
let removeStorage: tmp.DirResult["removeCallback"] | undefined;
|
||||
|
||||
beforeAll(async () => {
|
||||
// Set the CLI version here before activation to ensure we don't accidentally try to download a cli
|
||||
await beforeEachAction();
|
||||
await CUSTOM_CODEQL_PATH_SETTING.updateValue(
|
||||
process.env.CLI_PATH,
|
||||
ConfigurationTarget.Workspace,
|
||||
);
|
||||
|
||||
// ensure the test database is downloaded
|
||||
mkdirpSync(dirname(dbLoc));
|
||||
if (!existsSync(dbLoc)) {
|
||||
console.log(`Downloading test database to ${dbLoc}`);
|
||||
|
||||
await new Promise((resolve, reject) => {
|
||||
return fetch(DB_URL).then((response) => {
|
||||
const dest = createWriteStream(dbLoc);
|
||||
response.body.pipe(dest);
|
||||
|
||||
response.body.on("error", reject);
|
||||
dest.on("error", reject);
|
||||
dest.on("close", () => {
|
||||
resolve(dbLoc);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Create the temp directory to be used as extension local storage.
|
||||
const dir = tmp.dirSync();
|
||||
let storagePath = realpathSync(dir.name);
|
||||
if (storagePath.substring(0, 2).match(/[A-Z]:/)) {
|
||||
storagePath =
|
||||
storagePath.substring(0, 1).toLocaleLowerCase() +
|
||||
storagePath.substring(1);
|
||||
}
|
||||
setStoragePath(storagePath);
|
||||
|
||||
removeStorage = dir.removeCallback;
|
||||
|
||||
// Activate the extension
|
||||
await extensions.getExtension("GitHub.vscode-codeql")?.activate();
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
jest.spyOn(env, "openExternal").mockResolvedValue(false);
|
||||
|
||||
await beforeEachAction();
|
||||
|
||||
await CUSTOM_CODEQL_PATH_SETTING.updateValue(
|
||||
process.env.CLI_PATH,
|
||||
ConfigurationTarget.Workspace,
|
||||
);
|
||||
});
|
||||
|
||||
// ensure extension is cleaned up.
|
||||
afterAll(async () => {
|
||||
// ensure temp directory is cleaned up.
|
||||
try {
|
||||
removeStorage?.();
|
||||
} catch (e) {
|
||||
// we are exiting anyway so don't worry about it.
|
||||
// most likely the directory this is a test on Windows and some files are locked.
|
||||
console.warn(`Failed to remove storage directory '${storagePath}': ${e}`);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user