add error for missing tests folder
parent
140183dae2
commit
441ad80ded
|
@ -382,7 +382,7 @@ const Input = {
|
||||||
return validFolderName.test(folderName);
|
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) {
|
getPackageNameFromPackageJson(packagePath) {
|
||||||
const packageJsonPath = `${packagePath}/package.json`;
|
const packageJsonPath = `${packagePath}/package.json`;
|
||||||
|
@ -408,6 +408,14 @@ const Input = {
|
||||||
}
|
}
|
||||||
return rawPackageName;
|
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() {
|
getFromUser() {
|
||||||
// Input variables specified in workflow using "with" prop.
|
// Input variables specified in workflow using "with" prop.
|
||||||
const rawUnityVersion = (0, core_1.getInput)('unityVersion') || 'auto';
|
const rawUnityVersion = (0, core_1.getInput)('unityVersion') || 'auto';
|
||||||
|
@ -422,6 +430,7 @@ const Input = {
|
||||||
const githubToken = (0, core_1.getInput)('githubToken') || '';
|
const githubToken = (0, core_1.getInput)('githubToken') || '';
|
||||||
const checkName = (0, core_1.getInput)('checkName') || 'Test Results';
|
const checkName = (0, core_1.getInput)('checkName') || 'Test Results';
|
||||||
const rawPackageMode = (0, core_1.getInput)('packageMode') || 'false';
|
const rawPackageMode = (0, core_1.getInput)('packageMode') || 'false';
|
||||||
|
let packageName = '';
|
||||||
// Validate input
|
// Validate input
|
||||||
if (!this.testModes.includes(testMode)) {
|
if (!this.testModes.includes(testMode)) {
|
||||||
throw new Error(`Invalid testMode ${testMode}`);
|
throw new Error(`Invalid testMode ${testMode}`);
|
||||||
|
@ -442,8 +451,11 @@ const Input = {
|
||||||
// for input validation
|
// for input validation
|
||||||
const packageMode = rawPackageMode === 'true';
|
const packageMode = rawPackageMode === 'true';
|
||||||
const projectPath = rawProjectPath.replace(/\/$/, '');
|
const projectPath = rawProjectPath.replace(/\/$/, '');
|
||||||
// if in package mode, attempt to get the package's name
|
// if in package mode, attempt to get the package's name, and ensure tests are present
|
||||||
const packageName = packageMode ? this.getPackageNameFromPackageJson(projectPath) : '';
|
if (packageMode) {
|
||||||
|
packageName = this.getPackageNameFromPackageJson(projectPath);
|
||||||
|
this.verifyTestsFolderIsPresent(projectPath);
|
||||||
|
}
|
||||||
// Sanitise other input
|
// Sanitise other input
|
||||||
const artifactsPath = rawArtifactsPath.replace(/\/$/, '');
|
const artifactsPath = rawArtifactsPath.replace(/\/$/, '');
|
||||||
const useHostNetwork = rawUseHostNetwork === 'true';
|
const useHostNetwork = rawUseHostNetwork === 'true';
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -95,4 +95,20 @@ describe('Input', () => {
|
||||||
expect(Input.getPackageNameFromPackageJson('some/path')).toStrictEqual('some-package');
|
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();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -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) {
|
getPackageNameFromPackageJson(packagePath) {
|
||||||
const packageJsonPath = `${packagePath}/package.json`;
|
const packageJsonPath = `${packagePath}/package.json`;
|
||||||
|
@ -49,6 +49,17 @@ const Input = {
|
||||||
return rawPackageName;
|
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() {
|
getFromUser() {
|
||||||
// Input variables specified in workflow using "with" prop.
|
// Input variables specified in workflow using "with" prop.
|
||||||
const rawUnityVersion = getInput('unityVersion') || 'auto';
|
const rawUnityVersion = getInput('unityVersion') || 'auto';
|
||||||
|
@ -63,6 +74,7 @@ const Input = {
|
||||||
const githubToken = getInput('githubToken') || '';
|
const githubToken = getInput('githubToken') || '';
|
||||||
const checkName = getInput('checkName') || 'Test Results';
|
const checkName = getInput('checkName') || 'Test Results';
|
||||||
const rawPackageMode = getInput('packageMode') || 'false';
|
const rawPackageMode = getInput('packageMode') || 'false';
|
||||||
|
let packageName = '';
|
||||||
|
|
||||||
// Validate input
|
// Validate input
|
||||||
if (!this.testModes.includes(testMode)) {
|
if (!this.testModes.includes(testMode)) {
|
||||||
|
@ -90,8 +102,11 @@ const Input = {
|
||||||
const packageMode = rawPackageMode === 'true';
|
const packageMode = rawPackageMode === 'true';
|
||||||
const projectPath = rawProjectPath.replace(/\/$/, '');
|
const projectPath = rawProjectPath.replace(/\/$/, '');
|
||||||
|
|
||||||
// if in package mode, attempt to get the package's name
|
// if in package mode, attempt to get the package's name, and ensure tests are present
|
||||||
const packageName = packageMode ? this.getPackageNameFromPackageJson(projectPath) : '';
|
if (packageMode) {
|
||||||
|
packageName = this.getPackageNameFromPackageJson(projectPath);
|
||||||
|
this.verifyTestsFolderIsPresent(projectPath);
|
||||||
|
}
|
||||||
|
|
||||||
// Sanitise other input
|
// Sanitise other input
|
||||||
const artifactsPath = rawArtifactsPath.replace(/\/$/, '');
|
const artifactsPath = rawArtifactsPath.replace(/\/$/, '');
|
||||||
|
|
Loading…
Reference in New Issue