Skip to content

Commit a9c36ea

Browse files
committed
Create new activated-extension test suite
1 parent 81502fe commit a9c36ea

17 files changed

+141
-93
lines changed

extensions/ql-vscode/jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module.exports = {
88
projects: [
99
"<rootDir>/src/view",
1010
"<rootDir>/test/unit-tests",
11+
"<rootDir>/test/vscode-tests/activated-extension",
1112
"<rootDir>/test/vscode-tests/cli-integration",
1213
"<rootDir>/test/vscode-tests/no-workspace",
1314
"<rootDir>/test/vscode-tests/minimal-workspace",

extensions/ql-vscode/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,6 +1330,7 @@
13301330
"test:unit": "cross-env TZ=UTC LANG=en-US jest --projects test/unit-tests",
13311331
"test:view": "jest --projects src/view",
13321332
"integration": "npm-run-all integration:*",
1333+
"integration:activated-extension": "jest --projects test/vscode-tests/activated-extension",
13331334
"integration:no-workspace": "jest --projects test/vscode-tests/no-workspace",
13341335
"integration:minimal-workspace": "jest --projects test/vscode-tests/minimal-workspace",
13351336
"cli-integration": "jest --projects test/vscode-tests/cli-integration",

extensions/ql-vscode/test/vscode-tests/cli-integration/databases/db-panel.test.ts renamed to extensions/ql-vscode/test/vscode-tests/activated-extension/databases/db-panel.test.ts

File renamed without changes.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const path = require("path");
2+
3+
const {
4+
config: baseConfig,
5+
rootDir,
6+
} = require("../jest-runner-vscode.config.base");
7+
8+
/** @type import("jest-runner-vscode").RunnerOptions */
9+
const config = {
10+
...baseConfig,
11+
launchArgs: [
12+
...(baseConfig.launchArgs ?? []),
13+
// explicitly disable extensions that are known to interfere with the CLI integration tests
14+
"--disable-extension",
15+
"eamodio.gitlens",
16+
"--disable-extension",
17+
"github.codespaces",
18+
"--disable-extension",
19+
"github.copilot",
20+
path.resolve(rootDir, "test/data"),
21+
],
22+
extensionTestsEnv: {
23+
...baseConfig.extensionTestsEnv,
24+
INTEGRATION_TEST_MODE: "true",
25+
},
26+
retries: 3,
27+
};
28+
29+
module.exports = config;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type { Config } from "jest";
2+
3+
import baseConfig from "../jest.config.base";
4+
5+
const config: Config = {
6+
...baseConfig,
7+
runner: "<rootDir>/../jest-runner-installed-extensions.ts",
8+
setupFilesAfterEnv: ["<rootDir>/jest.setup.ts"],
9+
};
10+
11+
export default config;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import "../jest.activated-extension.setup";

extensions/ql-vscode/test/vscode-tests/cli-integration/databaseFetcher.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
importArchiveDatabase,
99
promptImportInternetDatabase,
1010
} from "../../../src/databaseFetcher";
11-
import { cleanDatabases, dbLoc, DB_URL, storagePath } from "./global.helper";
11+
import { cleanDatabases, dbLoc, DB_URL, storagePath } from "../global.helper";
1212

1313
jest.setTimeout(60_000);
1414

extensions/ql-vscode/test/vscode-tests/cli-integration/jest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import baseConfig from "../jest.config.base";
44

55
const config: Config = {
66
...baseConfig,
7-
runner: "<rootDir>/jest-runner-cli-integration.ts",
7+
runner: "<rootDir>/../jest-runner-installed-extensions.ts",
88
setupFilesAfterEnv: ["<rootDir>/jest.setup.ts"],
99
};
1010

Lines changed: 3 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,8 @@
1-
import {
2-
mkdirpSync,
3-
existsSync,
4-
createWriteStream,
5-
realpathSync,
6-
} from "fs-extra";
7-
import { dirname } from "path";
8-
import fetch from "node-fetch";
9-
import { DB_URL, dbLoc, setStoragePath, storagePath } from "./global.helper";
10-
import * as tmp from "tmp";
11-
import { CUSTOM_CODEQL_PATH_SETTING } from "../../../src/config";
12-
import { ConfigurationTarget, env, extensions, workspace } from "vscode";
13-
import { beforeEachAction } from "../test-config";
1+
import { workspace } from "vscode";
142

15-
// create an extension storage location
16-
let removeStorage: tmp.DirResult["removeCallback"] | undefined;
17-
18-
beforeAll(async () => {
19-
// Set the CLI version here before activation to ensure we don't accidentally try to download a cli
20-
await beforeEachAction();
21-
await CUSTOM_CODEQL_PATH_SETTING.updateValue(
22-
process.env.CLI_PATH,
23-
ConfigurationTarget.Workspace,
24-
);
25-
26-
// ensure the test database is downloaded
27-
mkdirpSync(dirname(dbLoc));
28-
if (!existsSync(dbLoc)) {
29-
console.log(`Downloading test database to ${dbLoc}`);
30-
31-
await new Promise((resolve, reject) => {
32-
return fetch(DB_URL).then((response) => {
33-
const dest = createWriteStream(dbLoc);
34-
response.body.pipe(dest);
35-
36-
response.body.on("error", reject);
37-
dest.on("error", reject);
38-
dest.on("close", () => {
39-
resolve(dbLoc);
40-
});
41-
});
42-
});
43-
}
44-
45-
// Create the temp directory to be used as extension local storage.
46-
const dir = tmp.dirSync();
47-
let storagePath = realpathSync(dir.name);
48-
if (storagePath.substring(0, 2).match(/[A-Z]:/)) {
49-
storagePath =
50-
storagePath.substring(0, 1).toLocaleLowerCase() +
51-
storagePath.substring(1);
52-
}
53-
setStoragePath(storagePath);
54-
55-
removeStorage = dir.removeCallback;
3+
import "../jest.activated-extension.setup";
564

5+
beforeAll(() => {
576
// check that the codeql folder is found in the workspace
587
const folders = workspace.workspaceFolders;
598
if (!folders) {
@@ -70,30 +19,4 @@ beforeAll(async () => {
7019
);
7120
}
7221
}
73-
74-
// Activate the extension
75-
await extensions.getExtension("GitHub.vscode-codeql")?.activate();
76-
});
77-
78-
beforeEach(async () => {
79-
jest.spyOn(env, "openExternal").mockResolvedValue(false);
80-
81-
await beforeEachAction();
82-
83-
await CUSTOM_CODEQL_PATH_SETTING.updateValue(
84-
process.env.CLI_PATH,
85-
ConfigurationTarget.Workspace,
86-
);
87-
});
88-
89-
// ensure extension is cleaned up.
90-
afterAll(async () => {
91-
// ensure temp directory is cleaned up.
92-
try {
93-
removeStorage?.();
94-
} catch (e) {
95-
// we are exiting anyway so don't worry about it.
96-
// most likely the directory this is a test on Windows and some files are locked.
97-
console.warn(`Failed to remove storage directory '${storagePath}': ${e}`);
98-
}
9922
});

extensions/ql-vscode/test/vscode-tests/cli-integration/new-query.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { describeWithCodeQL } from "../cli";
1111
import { QueryServerClient } from "../../../src/query-server/queryserver-client";
1212
import { extLogger, ProgressReporter } from "../../../src/common";
1313
import { QueryResultType } from "../../../src/pure/new-messages";
14-
import { cleanDatabases, dbLoc, storagePath } from "./global.helper";
14+
import { cleanDatabases, dbLoc, storagePath } from "../global.helper";
1515
import { importArchiveDatabase } from "../../../src/databaseFetcher";
1616

1717
const baseDir = join(__dirname, "../../../test/data");

0 commit comments

Comments
 (0)