add tests
This commit is contained in:
parent
d5853409b4
commit
657540584e
6 changed files with 81 additions and 8 deletions
14
lib/config-utils.js
generated
14
lib/config-utils.js
generated
|
|
@ -287,6 +287,15 @@ exports.getConfigFileDirectoryGivenMessage = getConfigFileDirectoryGivenMessage;
|
||||||
function getConfigFilePropertyError(configFile, property, error) {
|
function getConfigFilePropertyError(configFile, property, error) {
|
||||||
return 'The configuration file "' + configFile + '" is invalid: property "' + property + '" ' + error;
|
return 'The configuration file "' + configFile + '" is invalid: property "' + property + '" ' + error;
|
||||||
}
|
}
|
||||||
|
function getNoLanguagesError() {
|
||||||
|
return "Did not detect any languages to analyze. " +
|
||||||
|
"Please update input in workflow or check that GitHub detects the correct languages in your repository.";
|
||||||
|
}
|
||||||
|
exports.getNoLanguagesError = getNoLanguagesError;
|
||||||
|
function getUnknownLanguagesError(languages) {
|
||||||
|
return "Did not recognise the following languages: " + languages.join(', ');
|
||||||
|
}
|
||||||
|
exports.getUnknownLanguagesError = getUnknownLanguagesError;
|
||||||
/**
|
/**
|
||||||
* Gets the set of languages in the current repository
|
* Gets the set of languages in the current repository
|
||||||
*/
|
*/
|
||||||
|
|
@ -354,8 +363,7 @@ async function getLanguages() {
|
||||||
// If the languages parameter was not given and no languages were
|
// If the languages parameter was not given and no languages were
|
||||||
// detected then fail here as this is a workflow configuration error.
|
// detected then fail here as this is a workflow configuration error.
|
||||||
if (languages.length === 0) {
|
if (languages.length === 0) {
|
||||||
throw new Error("Did not detect any languages to analyze. " +
|
throw new Error(getNoLanguagesError());
|
||||||
"Please update input in workflow or check that GitHub detects the correct languages in your repository.");
|
|
||||||
}
|
}
|
||||||
// Make sure they are supported
|
// Make sure they are supported
|
||||||
const checkedLanguages = [];
|
const checkedLanguages = [];
|
||||||
|
|
@ -376,7 +384,7 @@ async function getLanguages() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (unknownLanguages.length > 0) {
|
if (unknownLanguages.length > 0) {
|
||||||
throw new Error("Did not recognise the following languages: " + unknownLanguages.join(', '));
|
throw new Error(getUnknownLanguagesError(unknownLanguages));
|
||||||
}
|
}
|
||||||
return checkedLanguages;
|
return checkedLanguages;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
27
lib/config-utils.test.js
generated
27
lib/config-utils.test.js
generated
|
|
@ -303,6 +303,33 @@ ava_1.default("Invalid format of remote config handled correctly", async (t) =>
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
ava_1.default("No detected languages", async (t) => {
|
||||||
|
return await util.withTmpDir(async (tmpDir) => {
|
||||||
|
process.env['RUNNER_TEMP'] = tmpDir;
|
||||||
|
process.env['GITHUB_WORKSPACE'] = tmpDir;
|
||||||
|
try {
|
||||||
|
await configUtils.initConfig();
|
||||||
|
throw new Error('initConfig did not throw error');
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
t.deepEqual(err, new Error(configUtils.getNoLanguagesError()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
ava_1.default("Unknown languages", async (t) => {
|
||||||
|
return await util.withTmpDir(async (tmpDir) => {
|
||||||
|
process.env['RUNNER_TEMP'] = tmpDir;
|
||||||
|
process.env['GITHUB_WORKSPACE'] = tmpDir;
|
||||||
|
setInput('languages', 'ruby,english');
|
||||||
|
try {
|
||||||
|
await configUtils.initConfig();
|
||||||
|
throw new Error('initConfig did not throw error');
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
t.deepEqual(err, new Error(configUtils.getUnknownLanguagesError(['ruby', 'english'])));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
function doInvalidInputTest(testName, inputFileContents, expectedErrorMessageGenerator) {
|
function doInvalidInputTest(testName, inputFileContents, expectedErrorMessageGenerator) {
|
||||||
ava_1.default("load invalid input - " + testName, async (t) => {
|
ava_1.default("load invalid input - " + testName, async (t) => {
|
||||||
return await util.withTmpDir(async (tmpDir) => {
|
return await util.withTmpDir(async (tmpDir) => {
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -343,6 +343,36 @@ test("Invalid format of remote config handled correctly", async t => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("No detected languages", async t => {
|
||||||
|
return await util.withTmpDir(async tmpDir => {
|
||||||
|
process.env['RUNNER_TEMP'] = tmpDir;
|
||||||
|
process.env['GITHUB_WORKSPACE'] = tmpDir;
|
||||||
|
|
||||||
|
try {
|
||||||
|
await configUtils.initConfig();
|
||||||
|
throw new Error('initConfig did not throw error');
|
||||||
|
} catch (err) {
|
||||||
|
t.deepEqual(err, new Error(configUtils.getNoLanguagesError()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("Unknown languages", async t => {
|
||||||
|
return await util.withTmpDir(async tmpDir => {
|
||||||
|
process.env['RUNNER_TEMP'] = tmpDir;
|
||||||
|
process.env['GITHUB_WORKSPACE'] = tmpDir;
|
||||||
|
|
||||||
|
setInput('languages', 'ruby,english');
|
||||||
|
|
||||||
|
try {
|
||||||
|
await configUtils.initConfig();
|
||||||
|
throw new Error('initConfig did not throw error');
|
||||||
|
} catch (err) {
|
||||||
|
t.deepEqual(err, new Error(configUtils.getUnknownLanguagesError(['ruby', 'english'])));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
function doInvalidInputTest(
|
function doInvalidInputTest(
|
||||||
testName: string,
|
testName: string,
|
||||||
inputFileContents: string,
|
inputFileContents: string,
|
||||||
|
|
|
||||||
|
|
@ -412,6 +412,15 @@ function getConfigFilePropertyError(configFile: string, property: string, error:
|
||||||
return 'The configuration file "' + configFile + '" is invalid: property "' + property + '" ' + error;
|
return 'The configuration file "' + configFile + '" is invalid: property "' + property + '" ' + error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getNoLanguagesError(): string {
|
||||||
|
return "Did not detect any languages to analyze. " +
|
||||||
|
"Please update input in workflow or check that GitHub detects the correct languages in your repository.";
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getUnknownLanguagesError(languages: string[]): string {
|
||||||
|
return "Did not recognise the following languages: " + languages.join(', ');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the set of languages in the current repository
|
* Gets the set of languages in the current repository
|
||||||
*/
|
*/
|
||||||
|
|
@ -484,8 +493,7 @@ async function getLanguages(): Promise<Language[]> {
|
||||||
// If the languages parameter was not given and no languages were
|
// If the languages parameter was not given and no languages were
|
||||||
// detected then fail here as this is a workflow configuration error.
|
// detected then fail here as this is a workflow configuration error.
|
||||||
if (languages.length === 0) {
|
if (languages.length === 0) {
|
||||||
throw new Error("Did not detect any languages to analyze. " +
|
throw new Error(getNoLanguagesError());
|
||||||
"Please update input in workflow or check that GitHub detects the correct languages in your repository.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure they are supported
|
// Make sure they are supported
|
||||||
|
|
@ -507,7 +515,7 @@ async function getLanguages(): Promise<Language[]> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (unknownLanguages.length > 0) {
|
if (unknownLanguages.length > 0) {
|
||||||
throw new Error("Did not recognise the following languages: " + unknownLanguages.join(', '));
|
throw new Error(getUnknownLanguagesError(unknownLanguages));
|
||||||
}
|
}
|
||||||
|
|
||||||
return checkedLanguages;
|
return checkedLanguages;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue