Skip to content

Commit 0bf98aa

Browse files
committed
Lint
1 parent 6b92383 commit 0bf98aa

File tree

1 file changed

+119
-110
lines changed

1 file changed

+119
-110
lines changed

src/config-utils.test.ts

Lines changed: 119 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -230,63 +230,66 @@ test.serial("load code quality config", async (t) => {
230230
});
231231
});
232232

233-
test.serial("initActionState doesn't throw if there are queries configured in the repository properties", async (t) => {
234-
return await withTmpDir(async (tempDir) => {
235-
const logger = getRunnerLogger(true);
236-
const languages = "javascript";
237-
238-
const codeql = createStubCodeQL({
239-
async betterResolveLanguages() {
240-
return {
241-
extractors: {
242-
javascript: [{ extractor_root: "" }],
243-
},
244-
};
245-
},
246-
});
233+
test.serial(
234+
"initActionState doesn't throw if there are queries configured in the repository properties",
235+
async (t) => {
236+
return await withTmpDir(async (tempDir) => {
237+
const logger = getRunnerLogger(true);
238+
const languages = "javascript";
247239

248-
// This should be ignored and no error should be thrown.
249-
const repositoryProperties = {
250-
"github-codeql-extra-queries": "+foo",
251-
};
240+
const codeql = createStubCodeQL({
241+
async betterResolveLanguages() {
242+
return {
243+
extractors: {
244+
javascript: [{ extractor_root: "" }],
245+
},
246+
};
247+
},
248+
});
252249

253-
// Expected configuration for a CQ-only analysis.
254-
const computedConfig: UserConfig = {
255-
"disable-default-queries": true,
256-
queries: [{ uses: "code-quality" }],
257-
"query-filters": [],
258-
};
250+
// This should be ignored and no error should be thrown.
251+
const repositoryProperties = {
252+
"github-codeql-extra-queries": "+foo",
253+
};
259254

260-
const expectedConfig = createTestConfig({
261-
analysisKinds: [AnalysisKind.CodeQuality],
262-
languages: [KnownLanguage.javascript],
263-
codeQLCmd: codeql.getPath(),
264-
computedConfig,
265-
dbLocation: path.resolve(tempDir, "codeql_databases"),
266-
debugArtifactName: "",
267-
debugDatabaseName: "",
268-
tempDir,
269-
repositoryProperties,
270-
});
255+
// Expected configuration for a CQ-only analysis.
256+
const computedConfig: UserConfig = {
257+
"disable-default-queries": true,
258+
queries: [{ uses: "code-quality" }],
259+
"query-filters": [],
260+
};
271261

272-
await t.notThrowsAsync(async () => {
273-
const config = await configUtils.initConfig(
274-
createFeatures([]),
275-
createTestInitConfigInputs({
276-
analysisKinds: [AnalysisKind.CodeQuality],
277-
languagesInput: languages,
278-
repository: { owner: "github", repo: "example" },
279-
tempDir,
280-
codeql,
281-
repositoryProperties,
282-
logger,
283-
}),
284-
);
262+
const expectedConfig = createTestConfig({
263+
analysisKinds: [AnalysisKind.CodeQuality],
264+
languages: [KnownLanguage.javascript],
265+
codeQLCmd: codeql.getPath(),
266+
computedConfig,
267+
dbLocation: path.resolve(tempDir, "codeql_databases"),
268+
debugArtifactName: "",
269+
debugDatabaseName: "",
270+
tempDir,
271+
repositoryProperties,
272+
});
273+
274+
await t.notThrowsAsync(async () => {
275+
const config = await configUtils.initConfig(
276+
createFeatures([]),
277+
createTestInitConfigInputs({
278+
analysisKinds: [AnalysisKind.CodeQuality],
279+
languagesInput: languages,
280+
repository: { owner: "github", repo: "example" },
281+
tempDir,
282+
codeql,
283+
repositoryProperties,
284+
logger,
285+
}),
286+
);
285287

286-
t.deepEqual(config, expectedConfig);
288+
t.deepEqual(config, expectedConfig);
289+
});
287290
});
288-
});
289-
});
291+
},
292+
);
290293

291294
test.serial("loading a saved config produces the same config", async (t) => {
292295
return await withTmpDir(async (tempDir) => {
@@ -541,18 +544,20 @@ test.serial("load non-empty input", async (t) => {
541544
});
542545
});
543546

544-
test.serial("Using config input and file together, config input should be used.", async (t) => {
545-
return await withTmpDir(async (tempDir) => {
546-
process.env["RUNNER_TEMP"] = tempDir;
547-
process.env["GITHUB_WORKSPACE"] = tempDir;
547+
test.serial(
548+
"Using config input and file together, config input should be used.",
549+
async (t) => {
550+
return await withTmpDir(async (tempDir) => {
551+
process.env["RUNNER_TEMP"] = tempDir;
552+
process.env["GITHUB_WORKSPACE"] = tempDir;
548553

549-
const inputFileContents = `
554+
const inputFileContents = `
550555
name: my config
551556
queries:
552557
- uses: ./foo_file`;
553-
const configFilePath = createConfigFile(inputFileContents, tempDir);
558+
const configFilePath = createConfigFile(inputFileContents, tempDir);
554559

555-
const configInput = `
560+
const configInput = `
556561
name: my config
557562
queries:
558563
- uses: ./foo
@@ -563,37 +568,38 @@ test.serial("Using config input and file together, config input should be used."
563568
- c/d@1.2.3
564569
`;
565570

566-
fs.mkdirSync(path.join(tempDir, "foo"));
571+
fs.mkdirSync(path.join(tempDir, "foo"));
567572

568-
const codeql = createStubCodeQL({
569-
async betterResolveLanguages() {
570-
return {
571-
extractors: {
572-
javascript: [{ extractor_root: "" }],
573-
python: [{ extractor_root: "" }],
574-
},
575-
};
576-
},
577-
});
573+
const codeql = createStubCodeQL({
574+
async betterResolveLanguages() {
575+
return {
576+
extractors: {
577+
javascript: [{ extractor_root: "" }],
578+
python: [{ extractor_root: "" }],
579+
},
580+
};
581+
},
582+
});
578583

579-
// Only JS, python packs will be ignored
580-
const languagesInput = "javascript";
584+
// Only JS, python packs will be ignored
585+
const languagesInput = "javascript";
581586

582-
const config = await configUtils.initConfig(
583-
createFeatures([]),
584-
createTestInitConfigInputs({
585-
languagesInput,
586-
configFile: configFilePath,
587-
configInput,
588-
tempDir,
589-
codeql,
590-
workspacePath: tempDir,
591-
}),
592-
);
587+
const config = await configUtils.initConfig(
588+
createFeatures([]),
589+
createTestInitConfigInputs({
590+
languagesInput,
591+
configFile: configFilePath,
592+
configInput,
593+
tempDir,
594+
codeql,
595+
workspacePath: tempDir,
596+
}),
597+
);
593598

594-
t.deepEqual(config.originalUserInput, yaml.load(configInput));
595-
});
596-
});
599+
t.deepEqual(config.originalUserInput, yaml.load(configInput));
600+
});
601+
},
602+
);
597603

598604
test.serial("API client used when reading remote config", async (t) => {
599605
return await withTmpDir(async (tempDir) => {
@@ -644,32 +650,35 @@ test.serial("API client used when reading remote config", async (t) => {
644650
});
645651
});
646652

647-
test.serial("Remote config handles the case where a directory is provided", async (t) => {
648-
return await withTmpDir(async (tempDir) => {
649-
const dummyResponse = []; // directories are returned as arrays
650-
mockGetContents(dummyResponse);
653+
test.serial(
654+
"Remote config handles the case where a directory is provided",
655+
async (t) => {
656+
return await withTmpDir(async (tempDir) => {
657+
const dummyResponse = []; // directories are returned as arrays
658+
mockGetContents(dummyResponse);
651659

652-
const repoReference = "octo-org/codeql-config/config.yaml@main";
653-
try {
654-
await configUtils.initConfig(
655-
createFeatures([]),
656-
createTestInitConfigInputs({
657-
configFile: repoReference,
658-
tempDir,
659-
workspacePath: tempDir,
660-
}),
661-
);
662-
throw new Error("initConfig did not throw error");
663-
} catch (err) {
664-
t.deepEqual(
665-
err,
666-
new ConfigurationError(
667-
errorMessages.getConfigFileDirectoryGivenMessage(repoReference),
668-
),
669-
);
670-
}
671-
});
672-
});
660+
const repoReference = "octo-org/codeql-config/config.yaml@main";
661+
try {
662+
await configUtils.initConfig(
663+
createFeatures([]),
664+
createTestInitConfigInputs({
665+
configFile: repoReference,
666+
tempDir,
667+
workspacePath: tempDir,
668+
}),
669+
);
670+
throw new Error("initConfig did not throw error");
671+
} catch (err) {
672+
t.deepEqual(
673+
err,
674+
new ConfigurationError(
675+
errorMessages.getConfigFileDirectoryGivenMessage(repoReference),
676+
),
677+
);
678+
}
679+
});
680+
},
681+
);
673682

674683
test.serial("Invalid format of remote config handled correctly", async (t) => {
675684
return await withTmpDir(async (tempDir) => {

0 commit comments

Comments
 (0)