Skip to content

Commit 6575405

Browse files
add tests
1 parent d585340 commit 6575405

File tree

6 files changed

+81
-8
lines changed

6 files changed

+81
-8
lines changed

lib/config-utils.js

Lines changed: 11 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/config-utils.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/config-utils.test.js

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/config-utils.test.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/config-utils.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,36 @@ test("Invalid format of remote config handled correctly", async t => {
343343
});
344344
});
345345

346+
test("No detected languages", async t => {
347+
return await util.withTmpDir(async tmpDir => {
348+
process.env['RUNNER_TEMP'] = tmpDir;
349+
process.env['GITHUB_WORKSPACE'] = tmpDir;
350+
351+
try {
352+
await configUtils.initConfig();
353+
throw new Error('initConfig did not throw error');
354+
} catch (err) {
355+
t.deepEqual(err, new Error(configUtils.getNoLanguagesError()));
356+
}
357+
});
358+
});
359+
360+
test("Unknown languages", async t => {
361+
return await util.withTmpDir(async tmpDir => {
362+
process.env['RUNNER_TEMP'] = tmpDir;
363+
process.env['GITHUB_WORKSPACE'] = tmpDir;
364+
365+
setInput('languages', 'ruby,english');
366+
367+
try {
368+
await configUtils.initConfig();
369+
throw new Error('initConfig did not throw error');
370+
} catch (err) {
371+
t.deepEqual(err, new Error(configUtils.getUnknownLanguagesError(['ruby', 'english'])));
372+
}
373+
});
374+
});
375+
346376
function doInvalidInputTest(
347377
testName: string,
348378
inputFileContents: string,

src/config-utils.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,15 @@ function getConfigFilePropertyError(configFile: string, property: string, error:
412412
return 'The configuration file "' + configFile + '" is invalid: property "' + property + '" ' + error;
413413
}
414414

415+
export function getNoLanguagesError(): string {
416+
return "Did not detect any languages to analyze. " +
417+
"Please update input in workflow or check that GitHub detects the correct languages in your repository.";
418+
}
419+
420+
export function getUnknownLanguagesError(languages: string[]): string {
421+
return "Did not recognise the following languages: " + languages.join(', ');
422+
}
423+
415424
/**
416425
* Gets the set of languages in the current repository
417426
*/
@@ -484,8 +493,7 @@ async function getLanguages(): Promise<Language[]> {
484493
// If the languages parameter was not given and no languages were
485494
// detected then fail here as this is a workflow configuration error.
486495
if (languages.length === 0) {
487-
throw new Error("Did not detect any languages to analyze. " +
488-
"Please update input in workflow or check that GitHub detects the correct languages in your repository.");
496+
throw new Error(getNoLanguagesError());
489497
}
490498

491499
// Make sure they are supported
@@ -507,7 +515,7 @@ async function getLanguages(): Promise<Language[]> {
507515
}
508516
}
509517
if (unknownLanguages.length > 0) {
510-
throw new Error("Did not recognise the following languages: " + unknownLanguages.join(', '));
518+
throw new Error(getUnknownLanguagesError(unknownLanguages));
511519
}
512520

513521
return checkedLanguages;

0 commit comments

Comments
 (0)