add error for missing tests folder

pull/164/head
Aaron Trudeau 2022-03-01 01:19:09 -05:00
parent 140183dae2
commit 441ad80ded
No known key found for this signature in database
GPG Key ID: D6874B046ABF9536
4 changed files with 50 additions and 7 deletions

18
dist/index.js generated vendored
View File

@ -382,7 +382,7 @@ const Input = {
return validFolderName.test(folderName);
},
/**
* When in package mode, we need scrape the package's name from its package.json file
* When in package mode, we need to scrape the package's name from its package.json file
*/
getPackageNameFromPackageJson(packagePath) {
const packageJsonPath = `${packagePath}/package.json`;
@ -408,6 +408,14 @@ const Input = {
}
return rawPackageName;
},
/**
* When in package mode, we need to ensure that the Tests folder is present
*/
verifyTestsFolderIsPresent(packagePath) {
if (!fs_1.default.existsSync(`${packagePath}/Tests`)) {
throw new Error(`Invalid projectPath - Cannot find package tests folder at ${packagePath}/Tests`);
}
},
getFromUser() {
// Input variables specified in workflow using "with" prop.
const rawUnityVersion = (0, core_1.getInput)('unityVersion') || 'auto';
@ -422,6 +430,7 @@ const Input = {
const githubToken = (0, core_1.getInput)('githubToken') || '';
const checkName = (0, core_1.getInput)('checkName') || 'Test Results';
const rawPackageMode = (0, core_1.getInput)('packageMode') || 'false';
let packageName = '';
// Validate input
if (!this.testModes.includes(testMode)) {
throw new Error(`Invalid testMode ${testMode}`);
@ -442,8 +451,11 @@ const Input = {
// for input validation
const packageMode = rawPackageMode === 'true';
const projectPath = rawProjectPath.replace(/\/$/, '');
// if in package mode, attempt to get the package's name
const packageName = packageMode ? this.getPackageNameFromPackageJson(projectPath) : '';
// if in package mode, attempt to get the package's name, and ensure tests are present
if (packageMode) {
packageName = this.getPackageNameFromPackageJson(projectPath);
this.verifyTestsFolderIsPresent(projectPath);
}
// Sanitise other input
const artifactsPath = rawArtifactsPath.replace(/\/$/, '');
const useHostNetwork = rawUseHostNetwork === 'true';

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@ -95,4 +95,20 @@ describe('Input', () => {
expect(Input.getPackageNameFromPackageJson('some/path')).toStrictEqual('some-package');
});
});
describe('verifyTestsFolderIsPresent', () => {
it('throws error if tests folder is not present', () => {
mockedFs.existsSync.mockReturnValue(false);
expect(() => Input.verifyTestsFolderIsPresent('some/path')).toThrow(
'Invalid projectPath - Cannot find package tests folder at some/path/Tests',
);
});
it('does not throw if tests folder is present', () => {
mockedFs.existsSync.mockReturnValue(true);
expect(() => Input.verifyTestsFolderIsPresent('some/path')).not.toThrow();
});
});
});

View File

@ -14,7 +14,7 @@ const Input = {
},
/**
* When in package mode, we need scrape the package's name from its package.json file
* When in package mode, we need to scrape the package's name from its package.json file
*/
getPackageNameFromPackageJson(packagePath) {
const packageJsonPath = `${packagePath}/package.json`;
@ -49,6 +49,17 @@ const Input = {
return rawPackageName;
},
/**
* When in package mode, we need to ensure that the Tests folder is present
*/
verifyTestsFolderIsPresent(packagePath) {
if (!fs.existsSync(`${packagePath}/Tests`)) {
throw new Error(
`Invalid projectPath - Cannot find package tests folder at ${packagePath}/Tests`,
);
}
},
getFromUser() {
// Input variables specified in workflow using "with" prop.
const rawUnityVersion = getInput('unityVersion') || 'auto';
@ -63,6 +74,7 @@ const Input = {
const githubToken = getInput('githubToken') || '';
const checkName = getInput('checkName') || 'Test Results';
const rawPackageMode = getInput('packageMode') || 'false';
let packageName = '';
// Validate input
if (!this.testModes.includes(testMode)) {
@ -90,8 +102,11 @@ const Input = {
const packageMode = rawPackageMode === 'true';
const projectPath = rawProjectPath.replace(/\/$/, '');
// if in package mode, attempt to get the package's name
const packageName = packageMode ? this.getPackageNameFromPackageJson(projectPath) : '';
// if in package mode, attempt to get the package's name, and ensure tests are present
if (packageMode) {
packageName = this.getPackageNameFromPackageJson(projectPath);
this.verifyTestsFolderIsPresent(projectPath);
}
// Sanitise other input
const artifactsPath = rawArtifactsPath.replace(/\/$/, '');