Remove calls to fail

Instead of calling `fail`, we can just let the error be caught by Jest,
which will automatically fail the tests. For other instances where we're
calling `fail` in case an error was not thrown, we will instead use
`.rejects.toThrow`.
This commit is contained in:
Koen Vlaswinkel
2022-11-24 10:15:47 +01:00
parent 614785fb7a
commit 1a10fd35f1
13 changed files with 279 additions and 385 deletions

View File

@@ -29,35 +29,27 @@ describe("Databases", () => {
jest.spyOn(window, "showInformationMessage").mockResolvedValue(undefined);
beforeEach(async () => {
try {
inputBoxStub.mockReset().mockResolvedValue(undefined);
progressCallback.mockReset();
inputBoxStub.mockReset().mockResolvedValue(undefined);
progressCallback.mockReset();
const extension = await extensions
.getExtension<CodeQLExtensionInterface | Record<string, never>>(
"GitHub.vscode-codeql",
)!
.activate();
if ("databaseManager" in extension) {
databaseManager = extension.databaseManager;
} else {
throw new Error(
"Extension not initialized. Make sure cli is downloaded and installed properly.",
);
}
await cleanDatabases(databaseManager);
} catch (e) {
fail(e as Error);
const extension = await extensions
.getExtension<CodeQLExtensionInterface | Record<string, never>>(
"GitHub.vscode-codeql",
)!
.activate();
if ("databaseManager" in extension) {
databaseManager = extension.databaseManager;
} else {
throw new Error(
"Extension not initialized. Make sure cli is downloaded and installed properly.",
);
}
await cleanDatabases(databaseManager);
});
afterEach(async () => {
try {
await cleanDatabases(databaseManager);
} catch (e) {
fail(e as Error);
}
await cleanDatabases(databaseManager);
});
it("should add a database from a folder", async () => {

View File

@@ -26,22 +26,18 @@ beforeAll(async () => {
if (!fs.existsSync(dbLoc)) {
console.log(`Downloading test database to ${dbLoc}`);
try {
await new Promise((resolve, reject) => {
return fetch(DB_URL).then((response) => {
const dest = fs.createWriteStream(dbLoc);
response.body.pipe(dest);
await new Promise((resolve, reject) => {
return fetch(DB_URL).then((response) => {
const dest = fs.createWriteStream(dbLoc);
response.body.pipe(dest);
response.body.on("error", reject);
dest.on("error", reject);
dest.on("close", () => {
resolve(dbLoc);
});
response.body.on("error", reject);
dest.on("error", reject);
dest.on("close", () => {
resolve(dbLoc);
});
});
} catch (e) {
fail("Failed to download test database: " + e);
}
});
}
// Create the temp directory to be used as extension local storage.
@@ -59,14 +55,14 @@ beforeAll(async () => {
// check that the codeql folder is found in the workspace
const folders = workspace.workspaceFolders;
if (!folders) {
fail(
'\n\n\nNo workspace folders found.\nYou will need a local copy of the codeql repo.\nMake sure you specify the path to it in launch.json.\nIt should be something along the lines of "${workspaceRoot}/../codeql" depending on where you have your local copy of the codeql repo.\n\n\n',
throw new Error(
'No workspace folders found.\nYou will need a local copy of the codeql repo.\nMake sure you specify the path to it in launch.json.\nIt should be something along the lines of "${workspaceRoot}/../codeql" depending on where you have your local copy of the codeql repo.',
);
} else {
const codeqlFolder = folders.find((folder) => folder.name === "codeql");
if (!codeqlFolder) {
fail(
'\n\n\nNo workspace folders found.\nYou will need a local copy of the codeql repo.\nMake sure you specify the path to it in launch.json.\nIt should be something along the lines of "${workspaceRoot}/../codeql" depending on where you have your local copy of the codeql repo.\n\n\n',
throw new Error(
'No workspace folders found.\nYou will need a local copy of the codeql repo.\nMake sure you specify the path to it in launch.json.\nIt should be something along the lines of "${workspaceRoot}/../codeql" depending on where you have your local copy of the codeql repo.\n\n\n',
);
}
}

View File

@@ -9,7 +9,6 @@ import * as cli from "../../cli";
import { CellValue } from "../../pure/bqrs-cli-types";
import { extensions } from "vscode";
import { CodeQLExtensionInterface } from "../../extension";
import { fail } from "assert";
import { describeWithCodeQL } from "../cli";
import { QueryServerClient } from "../../legacy-query-server/queryserver-client";
import { logger, ProgressReporter } from "../../logging";
@@ -112,43 +111,39 @@ describeWithCodeQL()("using the legacy query server", () => {
let cliServer: cli.CodeQLCliServer;
beforeAll(async () => {
try {
const extension = await extensions
.getExtension<CodeQLExtensionInterface | Record<string, never>>(
"GitHub.vscode-codeql",
)!
.activate();
if ("cliServer" in extension) {
cliServer = extension.cliServer;
cliServer.quiet = true;
const extension = await extensions
.getExtension<CodeQLExtensionInterface | Record<string, never>>(
"GitHub.vscode-codeql",
)!
.activate();
if ("cliServer" in extension) {
cliServer = extension.cliServer;
cliServer.quiet = true;
qs = new QueryServerClient(
{
codeQlPath:
(await extension.distributionManager.getCodeQlPathWithoutVersionCheck()) ||
"",
debug: false,
cacheSize: 0,
numThreads: 1,
saveCache: false,
timeoutSecs: 0,
},
cliServer,
{
contextStoragePath: tmpDir.name,
logger,
},
(task) =>
task(nullProgressReporter, new CancellationTokenSource().token),
);
await qs.startQueryServer();
} else {
throw new Error(
"Extension not initialized. Make sure cli is downloaded and installed properly.",
);
}
} catch (e) {
fail(e as Error);
qs = new QueryServerClient(
{
codeQlPath:
(await extension.distributionManager.getCodeQlPathWithoutVersionCheck()) ||
"",
debug: false,
cacheSize: 0,
numThreads: 1,
saveCache: false,
timeoutSecs: 0,
},
cliServer,
{
contextStoragePath: tmpDir.name,
logger,
},
(task) =>
task(nullProgressReporter, new CancellationTokenSource().token),
);
await qs.startQueryServer();
} else {
throw new Error(
"Extension not initialized. Make sure cli is downloaded and installed properly.",
);
}
});

View File

@@ -7,7 +7,6 @@ import * as cli from "../../cli";
import { CellValue } from "../../pure/bqrs-cli-types";
import { extensions, Uri } from "vscode";
import { CodeQLExtensionInterface } from "../../extension";
import { fail } from "assert";
import { describeWithCodeQL } from "../cli";
import { QueryServerClient } from "../../query-server/queryserver-client";
import { logger, ProgressReporter } from "../../logging";
@@ -113,67 +112,61 @@ describeWithCodeQL()("using the new query server", () => {
let cliServer: cli.CodeQLCliServer;
let db: string;
beforeAll(async () => {
try {
const extension = await extensions
.getExtension<CodeQLExtensionInterface | Record<string, never>>(
"GitHub.vscode-codeql",
)!
.activate();
if ("cliServer" in extension && "databaseManager" in extension) {
cliServer = extension.cliServer;
const extension = await extensions
.getExtension<CodeQLExtensionInterface | Record<string, never>>(
"GitHub.vscode-codeql",
)!
.activate();
if ("cliServer" in extension && "databaseManager" in extension) {
cliServer = extension.cliServer;
cliServer.quiet = true;
if (
!(await cliServer.cliConstraints.supportsNewQueryServerForTests())
) {
testContext.ctx.skip();
}
qs = new QueryServerClient(
{
codeQlPath:
(await extension.distributionManager.getCodeQlPathWithoutVersionCheck()) ||
"",
debug: false,
cacheSize: 0,
numThreads: 1,
saveCache: false,
timeoutSecs: 0,
},
cliServer,
{
contextStoragePath: tmpDir.name,
logger,
},
(task) =>
task(nullProgressReporter, new CancellationTokenSource().token),
);
await qs.startQueryServer();
// Unlike the old query sevre the new one wants a database and the empty direcrtory is not valid.
// Add a database, but make sure the database manager is empty first
await cleanDatabases(extension.databaseManager);
const uri = Uri.file(dbLoc);
const maybeDbItem = await importArchiveDatabase(
uri.toString(true),
extension.databaseManager,
storagePath,
() => {
/**ignore progress */
},
token,
);
if (!maybeDbItem) {
throw new Error("Could not import database");
}
db = maybeDbItem.databaseUri.fsPath;
} else {
throw new Error(
"Extension not initialized. Make sure cli is downloaded and installed properly.",
);
cliServer.quiet = true;
if (!(await cliServer.cliConstraints.supportsNewQueryServerForTests())) {
testContext.ctx.skip();
}
} catch (e) {
fail(e as Error);
qs = new QueryServerClient(
{
codeQlPath:
(await extension.distributionManager.getCodeQlPathWithoutVersionCheck()) ||
"",
debug: false,
cacheSize: 0,
numThreads: 1,
saveCache: false,
timeoutSecs: 0,
},
cliServer,
{
contextStoragePath: tmpDir.name,
logger,
},
(task) =>
task(nullProgressReporter, new CancellationTokenSource().token),
);
await qs.startQueryServer();
// Unlike the old query sevre the new one wants a database and the empty direcrtory is not valid.
// Add a database, but make sure the database manager is empty first
await cleanDatabases(extension.databaseManager);
const uri = Uri.file(dbLoc);
const maybeDbItem = await importArchiveDatabase(
uri.toString(true),
extension.databaseManager,
storagePath,
() => {
/**ignore progress */
},
token,
);
if (!maybeDbItem) {
throw new Error("Could not import database");
}
db = maybeDbItem.databaseUri.fsPath;
} else {
throw new Error(
"Extension not initialized. Make sure cli is downloaded and installed properly.",
);
}
});

View File

@@ -1,4 +1,3 @@
import { fail } from "assert";
import {
CancellationToken,
commands,
@@ -40,103 +39,85 @@ describeWithCodeQL()("Queries", () => {
let qlFile: string;
beforeEach(async () => {
try {
const extension = await extensions
.getExtension<CodeQLExtensionInterface | Record<string, never>>(
"GitHub.vscode-codeql",
)!
.activate();
if ("databaseManager" in extension) {
databaseManager = extension.databaseManager;
cli = extension.cliServer;
qs = extension.qs;
cli.quiet = true;
ctx = extension.ctx;
qlpackFile = `${ctx.storageUri?.fsPath}/quick-queries/qlpack.yml`;
qlpackLockFile = `${ctx.storageUri?.fsPath}/quick-queries/codeql-pack.lock.yml`;
oldQlpackLockFile = `${ctx.storageUri?.fsPath}/quick-queries/qlpack.lock.yml`;
qlFile = `${ctx.storageUri?.fsPath}/quick-queries/quick-query.ql`;
} else {
throw new Error(
"Extension not initialized. Make sure cli is downloaded and installed properly.",
);
}
// Ensure we are starting from a clean slate.
safeDel(qlFile);
safeDel(qlpackFile);
progress.mockReset();
token = {} as CancellationToken;
// Add a database, but make sure the database manager is empty first
await cleanDatabases(databaseManager);
const uri = Uri.file(dbLoc);
const maybeDbItem = await importArchiveDatabase(
uri.toString(true),
databaseManager,
storagePath,
progress,
token,
cli,
const extension = await extensions
.getExtension<CodeQLExtensionInterface | Record<string, never>>(
"GitHub.vscode-codeql",
)!
.activate();
if ("databaseManager" in extension) {
databaseManager = extension.databaseManager;
cli = extension.cliServer;
qs = extension.qs;
cli.quiet = true;
ctx = extension.ctx;
qlpackFile = `${ctx.storageUri?.fsPath}/quick-queries/qlpack.yml`;
qlpackLockFile = `${ctx.storageUri?.fsPath}/quick-queries/codeql-pack.lock.yml`;
oldQlpackLockFile = `${ctx.storageUri?.fsPath}/quick-queries/qlpack.lock.yml`;
qlFile = `${ctx.storageUri?.fsPath}/quick-queries/quick-query.ql`;
} else {
throw new Error(
"Extension not initialized. Make sure cli is downloaded and installed properly.",
);
if (!maybeDbItem) {
throw new Error("Could not import database");
}
dbItem = maybeDbItem;
} catch (e) {
fail(e as Error);
}
// Ensure we are starting from a clean slate.
safeDel(qlFile);
safeDel(qlpackFile);
progress.mockReset();
token = {} as CancellationToken;
// Add a database, but make sure the database manager is empty first
await cleanDatabases(databaseManager);
const uri = Uri.file(dbLoc);
const maybeDbItem = await importArchiveDatabase(
uri.toString(true),
databaseManager,
storagePath,
progress,
token,
cli,
);
if (!maybeDbItem) {
throw new Error("Could not import database");
}
dbItem = maybeDbItem;
});
afterEach(async () => {
try {
safeDel(qlpackFile);
safeDel(qlFile);
await cleanDatabases(databaseManager);
} catch (e) {
fail(e as Error);
}
safeDel(qlpackFile);
safeDel(qlFile);
await cleanDatabases(databaseManager);
});
it("should run a query", async () => {
try {
const queryPath = path.join(__dirname, "data", "simple-query.ql");
const result = qs.compileAndRunQueryAgainstDatabase(
dbItem,
await mockInitialQueryInfo(queryPath),
path.join(tmpDir.name, "mock-storage-path"),
progress,
token,
);
const queryPath = path.join(__dirname, "data", "simple-query.ql");
const result = qs.compileAndRunQueryAgainstDatabase(
dbItem,
await mockInitialQueryInfo(queryPath),
path.join(tmpDir.name, "mock-storage-path"),
progress,
token,
);
// just check that the query was successful
expect((await result).successful).toBe(true);
} catch (e) {
console.error("Test Failed");
fail(e as Error);
}
// just check that the query was successful
expect((await result).successful).toBe(true);
});
// Asserts a fix for bug https://github.com/github/vscode-codeql/issues/733
it("should restart the database and run a query", async () => {
try {
await commands.executeCommand("codeQL.restartQueryServer");
const queryPath = path.join(__dirname, "data", "simple-query.ql");
const result = await qs.compileAndRunQueryAgainstDatabase(
dbItem,
await mockInitialQueryInfo(queryPath),
path.join(tmpDir.name, "mock-storage-path"),
progress,
token,
);
await commands.executeCommand("codeQL.restartQueryServer");
const queryPath = path.join(__dirname, "data", "simple-query.ql");
const result = await qs.compileAndRunQueryAgainstDatabase(
dbItem,
await mockInitialQueryInfo(queryPath),
path.join(tmpDir.name, "mock-storage-path"),
progress,
token,
);
expect(result.successful).toBe(true);
} catch (e) {
console.error("Test Failed");
fail(e as Error);
}
expect(result.successful).toBe(true);
});
it("should create a quick query", async () => {

View File

@@ -344,12 +344,7 @@ describe("Remote queries", () => {
cancellationTokenSource.cancel();
try {
await promise;
fail("should have thrown");
} catch (e) {
expect(e).toBeInstanceOf(UserCancellationException);
}
await expect(promise).rejects.toThrow(UserCancellationException);
});
});

View File

@@ -88,26 +88,22 @@ describe("Variant Analysis Manager", () => {
scannedRepos,
});
try {
const extension = await extensions
.getExtension<CodeQLExtensionInterface | Record<string, never>>(
"GitHub.vscode-codeql",
)!
.activate();
cli = extension.cliServer;
variantAnalysisResultsManager = new VariantAnalysisResultsManager(
cli,
logger,
);
variantAnalysisManager = new VariantAnalysisManager(
extension.ctx,
cli,
storagePath,
variantAnalysisResultsManager,
);
} catch (e) {
fail(e as Error);
}
const extension = await extensions
.getExtension<CodeQLExtensionInterface | Record<string, never>>(
"GitHub.vscode-codeql",
)!
.activate();
cli = extension.cliServer;
variantAnalysisResultsManager = new VariantAnalysisResultsManager(
cli,
logger,
);
variantAnalysisManager = new VariantAnalysisManager(
extension.ctx,
cli,
storagePath,
variantAnalysisResultsManager,
);
});
describe("runVariantAnalysis", () => {
@@ -260,12 +256,7 @@ describe("Variant Analysis Manager", () => {
cancellationTokenSource.cancel();
try {
await promise;
fail("should have thrown");
} catch (e) {
expect(e).toBeInstanceOf(UserCancellationException);
}
await expect(promise).rejects.toThrow(UserCancellationException);
});
});
@@ -566,16 +557,13 @@ describe("Variant Analysis Manager", () => {
new Error("Failed to download"),
);
try {
await variantAnalysisManager.autoDownloadVariantAnalysisResult(
await expect(
variantAnalysisManager.autoDownloadVariantAnalysisResult(
scannedRepos[0],
variantAnalysis,
cancellationTokenSource.token,
);
fail("Expected an error to be thrown");
} catch (e: any) {
// we can ignore this error, we expect this
}
),
).rejects.toThrow();
expect(outputJsonStub).not.toHaveBeenCalled();
});
@@ -585,16 +573,13 @@ describe("Variant Analysis Manager", () => {
new Error("Failed to download"),
);
try {
await variantAnalysisManager.autoDownloadVariantAnalysisResult(
await expect(
variantAnalysisManager.autoDownloadVariantAnalysisResult(
scannedRepos[0],
variantAnalysis,
cancellationTokenSource.token,
);
fail("Expected an error to be thrown");
} catch (e) {
// we can ignore this error, we expect this
}
),
).rejects.toThrow();
expect(outputJsonStub).not.toHaveBeenCalled();
@@ -630,16 +615,13 @@ describe("Variant Analysis Manager", () => {
new Error("Failed to download"),
);
try {
await variantAnalysisManager.autoDownloadVariantAnalysisResult(
await expect(
variantAnalysisManager.autoDownloadVariantAnalysisResult(
scannedRepos[0],
variantAnalysis,
cancellationTokenSource.token,
);
fail("Expected an error to be thrown");
} catch (e) {
// we can ignore this error, we expect this
}
),
).rejects.toThrow();
expect(outputJsonStub).not.toHaveBeenCalled();

View File

@@ -60,16 +60,12 @@ describe("Variant Analysis Monitor", () => {
variantAnalysis = createMockVariantAnalysis({});
try {
extension = await extensions
.getExtension<CodeQLExtensionInterface | Record<string, never>>(
"GitHub.vscode-codeql",
)!
.activate();
variantAnalysisMonitor = new VariantAnalysisMonitor(extension.ctx);
} catch (e) {
fail(e as Error);
}
extension = await extensions
.getExtension<CodeQLExtensionInterface | Record<string, never>>(
"GitHub.vscode-codeql",
)!
.activate();
variantAnalysisMonitor = new VariantAnalysisMonitor(extension.ctx);
variantAnalysisManager = extension.variantAnalysisManager;
mockGetDownloadResult = jest

View File

@@ -27,20 +27,16 @@ describe(VariantAnalysisResultsManager.name, () => {
variantAnalysisId = faker.datatype.number();
try {
const extension = await extensions
.getExtension<CodeQLExtensionInterface | Record<string, never>>(
"GitHub.vscode-codeql",
)!
.activate();
cli = extension.cliServer;
variantAnalysisResultsManager = new VariantAnalysisResultsManager(
cli,
logger,
);
} catch (e) {
fail(e as Error);
}
const extension = await extensions
.getExtension<CodeQLExtensionInterface | Record<string, never>>(
"GitHub.vscode-codeql",
)!
.activate();
cli = extension.cliServer;
variantAnalysisResultsManager = new VariantAnalysisResultsManager(
cli,
logger,
);
});
describe("download", () => {
@@ -90,18 +86,14 @@ describe(VariantAnalysisResultsManager.name, () => {
const dummyRepoTask = createMockVariantAnalysisRepositoryTask();
delete dummyRepoTask.artifactUrl;
try {
await variantAnalysisResultsManager.download(
await expect(
variantAnalysisResultsManager.download(
mockCredentials,
variantAnalysisId,
dummyRepoTask,
variantAnalysisStoragePath,
);
fail("Expected an error to be thrown");
} catch (e: any) {
expect(e.message).toBe("Missing artifact URL");
}
),
).rejects.toThrow("Missing artifact URL");
});
});

View File

@@ -56,15 +56,11 @@ describe("Variant Analysis Submission Integration", () => {
executeCommandSpy.mockRestore();
showErrorMessageSpy.mockReset().mockResolvedValue(undefined);
try {
await extensions
.getExtension<CodeQLExtensionInterface | Record<string, never>>(
"GitHub.vscode-codeql",
)!
.activate();
} catch (e) {
fail(e as Error);
}
await extensions
.getExtension<CodeQLExtensionInterface | Record<string, never>>(
"GitHub.vscode-codeql",
)!
.activate();
});
describe("Successful scenario", () => {

View File

@@ -12,7 +12,6 @@ import {
} from "../../helpers";
import { resolveQueries } from "../../contextual/queryResolver";
import { KeyType } from "../../contextual/keyType";
import { fail } from "assert";
jest.setTimeout(60_000);
@@ -88,31 +87,24 @@ describe("Use cli", () => {
itWithCodeQL()(
"should resolve printAST queries for supported languages",
async () => {
try {
for (const lang of supportedLanguages) {
if (lang === "go") {
// The codeql-go submodule is not available in the integration tests.
return;
}
console.log(`resolving printAST queries for ${lang}`);
const pack = await getQlPackForDbscheme(
cli,
languageToDbScheme[lang],
);
expect(pack.dbschemePack).toEqual(expect.arrayContaining([lang]));
if (pack.dbschemePackIsLibraryPack) {
expect(pack.queryPack).toEqual(expect.arrayContaining([lang]));
}
const result = await resolveQueries(cli, pack, KeyType.PrintAstQuery);
// It doesn't matter what the name or path of the query is, only
// that we have found exactly one query.
expect(result.length).toBe(1);
for (const lang of supportedLanguages) {
if (lang === "go") {
// The codeql-go submodule is not available in the integration tests.
return;
}
} catch (e) {
fail(e as Error);
console.log(`resolving printAST queries for ${lang}`);
const pack = await getQlPackForDbscheme(cli, languageToDbScheme[lang]);
expect(pack.dbschemePack).toEqual(expect.arrayContaining([lang]));
if (pack.dbschemePackIsLibraryPack) {
expect(pack.queryPack).toEqual(expect.arrayContaining([lang]));
}
const result = await resolveQueries(cli, pack, KeyType.PrintAstQuery);
// It doesn't matter what the name or path of the query is, only
// that we have found exactly one query.
expect(result.length).toBe(1);
}
},
);

View File

@@ -1,7 +1,5 @@
import { fail } from "assert";
import { commands, Selection, window, workspace } from "vscode";
import * as path from "path";
import * as assert from "assert";
import { tmpDir } from "../../helpers";
import * as fs from "fs-extra";
@@ -12,44 +10,37 @@ jest.setTimeout(20_000);
*/
describe("SourceMap", () => {
it("should jump to QL code", async () => {
try {
const root = workspace.workspaceFolders![0].uri.fsPath;
const srcFiles = {
summary: path.join(root, "log-summary", "evaluator-log.summary"),
summaryMap: path.join(root, "log-summary", "evaluator-log.summary.map"),
};
// We need to modify the source map so that its paths point to the actual location of the
// workspace root on this machine. We'll copy the summary and its source map to a temp
// directory, modify the source map their, and open that summary.
const tempFiles = await copyFilesToTempDirectory(srcFiles);
const root = workspace.workspaceFolders![0].uri.fsPath;
const srcFiles = {
summary: path.join(root, "log-summary", "evaluator-log.summary"),
summaryMap: path.join(root, "log-summary", "evaluator-log.summary.map"),
};
// We need to modify the source map so that its paths point to the actual location of the
// workspace root on this machine. We'll copy the summary and its source map to a temp
// directory, modify the source map their, and open that summary.
const tempFiles = await copyFilesToTempDirectory(srcFiles);
// The checked-in sourcemap has placeholders of the form `${root}`, which we need to replace
// with the actual root directory.
const mapText = await fs.readFile(tempFiles.summaryMap, "utf-8");
// Always use forward slashes, since they work everywhere.
const slashRoot = root.replaceAll("\\", "/");
const newMapText = mapText.replaceAll("${root}", slashRoot);
await fs.writeFile(tempFiles.summaryMap, newMapText);
// The checked-in sourcemap has placeholders of the form `${root}`, which we need to replace
// with the actual root directory.
const mapText = await fs.readFile(tempFiles.summaryMap, "utf-8");
// Always use forward slashes, since they work everywhere.
const slashRoot = root.replaceAll("\\", "/");
const newMapText = mapText.replaceAll("${root}", slashRoot);
await fs.writeFile(tempFiles.summaryMap, newMapText);
const summaryDocument = await workspace.openTextDocument(
tempFiles.summary,
);
assert(summaryDocument.languageId === "ql-summary");
const summaryEditor = await window.showTextDocument(summaryDocument);
summaryEditor.selection = new Selection(356, 10, 356, 10);
await commands.executeCommand("codeQL.gotoQL");
const summaryDocument = await workspace.openTextDocument(tempFiles.summary);
expect(summaryDocument.languageId).toBe("ql-summary");
const summaryEditor = await window.showTextDocument(summaryDocument);
summaryEditor.selection = new Selection(356, 10, 356, 10);
await commands.executeCommand("codeQL.gotoQL");
const newEditor = window.activeTextEditor;
expect(newEditor).toBeDefined();
const newDocument = newEditor!.document;
expect(path.basename(newDocument.fileName)).toBe("Namespace.qll");
const newSelection = newEditor!.selection;
expect(newSelection.start.line).toBe(60);
expect(newSelection.start.character).toBe(2);
} catch (e) {
console.error("Test Failed");
fail(e as Error);
}
const newEditor = window.activeTextEditor;
expect(newEditor).toBeDefined();
const newDocument = newEditor!.document;
expect(path.basename(newDocument.fileName)).toBe("Namespace.qll");
const newSelection = newEditor!.selection;
expect(newSelection.start.line).toBe(60);
expect(newSelection.start.character).toBe(2);
});
async function copyFilesToTempDirectory<T extends Record<string, string>>(

View File

@@ -5,13 +5,6 @@ import { jestTestConfigHelper } from "./test-config";
/**/
};
function fail(reason = "fail was called in a test.") {
throw new Error(reason);
}
// Jest doesn't seem to define this function anymore, but it's in the types, so should be valid.
(global as any).fail = fail;
export default async function setupEnv() {
await jestTestConfigHelper();
}