Fix tests when there are no bundled queries
This commit is contained in:
@@ -5,7 +5,7 @@ import type { ModelConfig } from "../config";
|
||||
* Languages that are always supported by the model editor. These languages
|
||||
* do not require a separate config setting to enable them.
|
||||
*/
|
||||
const SUPPORTED_LANGUAGES: QueryLanguage[] = [
|
||||
export const SUPPORTED_LANGUAGES: QueryLanguage[] = [
|
||||
QueryLanguage.Java,
|
||||
QueryLanguage.CSharp,
|
||||
];
|
||||
|
||||
@@ -7,22 +7,20 @@ import type { DatabaseItem } from "../../../../src/databases/local-databases";
|
||||
import { DatabaseKind } from "../../../../src/databases/local-databases";
|
||||
import { dirSync, file } from "tmp-promise";
|
||||
import { QueryResultType } from "../../../../src/query-server/messages";
|
||||
import { fetchExternalApiQueries } from "../../../../src/model-editor/queries";
|
||||
import * as log from "../../../../src/common/logging/notifications";
|
||||
import { RedactableError } from "../../../../src/common/errors";
|
||||
import type { showAndLogExceptionWithTelemetry } from "../../../../src/common/logging";
|
||||
import type { QueryLanguage } from "../../../../src/common/query-language";
|
||||
import { mockedObject, mockedUri } from "../../utils/mocking.helpers";
|
||||
import { Mode } from "../../../../src/model-editor/shared/mode";
|
||||
import { join } from "path";
|
||||
import type { CodeQLCliServer } from "../../../../src/codeql-cli/cli";
|
||||
import type { QueryRunner } from "../../../../src/query-server";
|
||||
import { QueryOutputDir } from "../../../../src/local-queries/query-output-dir";
|
||||
import { SUPPORTED_LANGUAGES } from "../../../../src/model-editor/supported-languages";
|
||||
|
||||
describe("runModelEditorQueries", () => {
|
||||
const language = Object.keys(fetchExternalApiQueries)[
|
||||
Math.floor(Math.random() * Object.keys(fetchExternalApiQueries).length)
|
||||
] as QueryLanguage;
|
||||
const language =
|
||||
SUPPORTED_LANGUAGES[Math.floor(Math.random() * SUPPORTED_LANGUAGES.length)];
|
||||
|
||||
const queryDir = dirSync({ unsafeCleanup: true }).name;
|
||||
|
||||
@@ -33,11 +31,6 @@ describe("runModelEditorQueries", () => {
|
||||
|
||||
const outputDir = new QueryOutputDir(join((await file()).path, "1"));
|
||||
|
||||
const query = fetchExternalApiQueries[language];
|
||||
if (!query) {
|
||||
throw new Error(`No query found for language ${language}`);
|
||||
}
|
||||
|
||||
const options = {
|
||||
cliServer: mockedObject<CodeQLCliServer>({
|
||||
resolveQlpacks: jest.fn().mockResolvedValue({
|
||||
@@ -96,11 +89,6 @@ describe("runModelEditorQueries", () => {
|
||||
it("should run query for random language", async () => {
|
||||
const outputDir = new QueryOutputDir(join((await file()).path, "1"));
|
||||
|
||||
const query = fetchExternalApiQueries[language];
|
||||
if (!query) {
|
||||
throw new Error(`No query found for language ${language}`);
|
||||
}
|
||||
|
||||
const options = {
|
||||
cliServer: mockedObject<CodeQLCliServer>({
|
||||
resolveQlpacks: jest.fn().mockResolvedValue({
|
||||
|
||||
@@ -27,6 +27,15 @@ describe("setUpPack", () => {
|
||||
return { language: lang as QueryLanguage, query };
|
||||
});
|
||||
|
||||
if (languages.length === 0) {
|
||||
// If we currently don't have any bundled queries, skip this test, but ensure there's still at least one test.
|
||||
test("should not have any bundled queries", () => {
|
||||
expect(languages).toHaveLength(0);
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
describe.each(languages)("for language $language", ({ language, query }) => {
|
||||
test("should create the files when not found", async () => {
|
||||
const cliServer = mockedObject<CodeQLCliServer>({
|
||||
|
||||
Reference in New Issue
Block a user