Skip to content

Commit

Permalink
Fix tests when there are no bundled queries
Browse files Browse the repository at this point in the history
  • Loading branch information
koesie10 committed Feb 1, 2024
1 parent 15c3805 commit 4e967d8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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({
Expand Down Expand Up @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>({
Expand Down

0 comments on commit 4e967d8

Please sign in to comment.