Add some more basic tests 🤷‍♂️

This commit is contained in:
Webber 2020-01-27 23:03:29 +01:00 committed by Webber Takken
parent fe2311ef4b
commit 4051832dc0
9 changed files with 217 additions and 1 deletions

View File

@ -0,0 +1,85 @@
import BuildParameters from './build-parameters';
import Platform from './platform';
describe('BuildParameters', () => {
describe('create', () => {
const someParameters = {
unityVersion: 'someVersion',
targetPlatform: 'somePlatform',
projectPath: 'path/to/project',
buildName: 'someBuildName',
buildsPath: 'someBuildsPath',
buildMethod: 'Namespace.Class.Method',
customParameters: '-someParam someValue',
};
it('does not throw', () => {
expect(() => BuildParameters.create(someParameters)).not.toThrow();
});
it('returns the version', () => {
expect(BuildParameters.create(someParameters).version).toStrictEqual(
someParameters.unityVersion,
);
});
it('returns the platform', () => {
expect(BuildParameters.create(someParameters).platform).toStrictEqual(
someParameters.targetPlatform,
);
});
it('returns the project path', () => {
expect(BuildParameters.create(someParameters).projectPath).toStrictEqual(
someParameters.projectPath,
);
});
it('returns the build name', () => {
expect(BuildParameters.create(someParameters).buildName).toStrictEqual(
someParameters.buildName,
);
});
it('returns the build path', () => {
expect(BuildParameters.create(someParameters).buildPath).toStrictEqual(
`${someParameters.buildsPath}/${someParameters.targetPlatform}`,
);
});
describe('build file', () => {
it('returns the build file', () => {
expect(BuildParameters.create(someParameters).buildFile).toStrictEqual(
someParameters.buildName,
);
});
test.each([Platform.types.StandaloneWindows, Platform.types.StandaloneWindows64])(
'appends exe for %s',
targetPlatform => {
expect(
BuildParameters.create({ ...someParameters, targetPlatform }).buildFile,
).toStrictEqual(`${someParameters.buildName}.exe`);
},
);
test.each([Platform.types.Android])('appends apk for %s', targetPlatform => {
expect(
BuildParameters.create({ ...someParameters, targetPlatform }).buildFile,
).toStrictEqual(`${someParameters.buildName}.apk`);
});
});
it('returns the build method', () => {
expect(BuildParameters.create(someParameters).buildMethod).toStrictEqual(
someParameters.buildMethod,
);
});
it('returns the custom parameters', () => {
expect(BuildParameters.create(someParameters).customParameters).toStrictEqual(
someParameters.customParameters,
);
});
});
});

10
src/model/index.test.js Normal file
View File

@ -0,0 +1,10 @@
import * as Index from '.';
describe('Index', () => {
test.each(['Action', 'BuildParameters', 'Cache', 'Docker', 'Input', 'ImageTag', 'Platform'])(
'exports %s',
exportedModule => {
expect(typeof Index[exportedModule]).toStrictEqual('function');
},
);
});

View File

@ -7,12 +7,16 @@ class Input {
// Input variables specified in workflows using "with" prop. // Input variables specified in workflows using "with" prop.
const unityVersion = core.getInput('unityVersion'); const unityVersion = core.getInput('unityVersion');
const targetPlatform = core.getInput('targetPlatform') || Platform.default; const targetPlatform = core.getInput('targetPlatform') || Platform.default;
const projectPath = core.getInput('projectPath') || '.'; const rawProjectPath = core.getInput('projectPath') || '.';
const buildName = core.getInput('buildName') || targetPlatform; const buildName = core.getInput('buildName') || targetPlatform;
const buildsPath = core.getInput('buildsPath') || 'build'; const buildsPath = core.getInput('buildsPath') || 'build';
const buildMethod = core.getInput('buildMethod'); // processed in docker file const buildMethod = core.getInput('buildMethod'); // processed in docker file
const customParameters = core.getInput('customParameters') || ''; const customParameters = core.getInput('customParameters') || '';
// Sanitise input
const projectPath = rawProjectPath.replace(/\/$/, '');
// Return sanitised input
return { return {
unityVersion, unityVersion,
targetPlatform, targetPlatform,

View File

@ -5,5 +5,9 @@ describe('Input', () => {
it('does not throw', () => { it('does not throw', () => {
expect(() => Input.getFromUser()).not.toThrow(); expect(() => Input.getFromUser()).not.toThrow();
}); });
it('returns an object', () => {
expect(typeof Input.getFromUser()).toStrictEqual('object');
});
}); });
}); });

View File

@ -0,0 +1,37 @@
import Platform from './platform';
describe('Platform', () => {
describe('default', () => {
it('does not throw', () => {
expect(() => Platform.default).not.toThrow();
});
it('returns a string', () => {
expect(typeof Platform.default).toStrictEqual('string');
});
it('returns a platform', () => {
expect(Object.values(Platform.types)).toContain(Platform.default);
});
});
describe('isWindows', () => {
it('returns true for windows', () => {
expect(Platform.isWindows(Platform.types.StandaloneWindows64)).toStrictEqual(true);
});
it('returns false for MacOS', () => {
expect(Platform.isWindows(Platform.types.StandaloneOSX)).toStrictEqual(false);
});
});
describe('isAndroid', () => {
it('returns true for Android', () => {
expect(Platform.isAndroid(Platform.types.Android)).toStrictEqual(true);
});
it('returns false for Windows', () => {
expect(Platform.isAndroid(Platform.types.StandaloneWindows64)).toStrictEqual(false);
});
});
});

23
src/model/project.js Normal file
View File

@ -0,0 +1,23 @@
import Unity from './unity';
import Input from './input';
import Action from './action';
class Project {
static get relativePath() {
const { projectPath } = Input.getFromUser();
return `${projectPath}`;
}
static get absolutePath() {
const { workspace } = Action;
return `${workspace}/${this.relativePath}`;
}
static get libraryFolder() {
return `${this.relativePath}/${Unity.libraryFolder}`;
}
}
export default Project;

33
src/model/project.test.js Normal file
View File

@ -0,0 +1,33 @@
import Project from './project';
describe('Platform', () => {
describe('relativePath', () => {
it('does not throw', () => {
expect(() => Project.relativePath).not.toThrow();
});
it('returns a string', () => {
expect(typeof Project.relativePath).toStrictEqual('string');
});
});
describe('absolutePath', () => {
it('does not throw', () => {
expect(() => Project.absolutePath).not.toThrow();
});
it('returns a string', () => {
expect(typeof Project.absolutePath).toStrictEqual('string');
});
});
describe('libraryFolder', () => {
it('does not throw', () => {
expect(() => Project.libraryFolder).not.toThrow();
});
it('returns a string', () => {
expect(typeof Project.libraryFolder).toStrictEqual('string');
});
});
});

7
src/model/unity.js Normal file
View File

@ -0,0 +1,7 @@
class Unity {
static get libraryFolder() {
return 'Library';
}
}
export default Unity;

13
src/model/unity.test.js Normal file
View File

@ -0,0 +1,13 @@
import Unity from './unity';
describe('Unity', () => {
describe('libraryFolder', () => {
it('does not throw', () => {
expect(() => Unity.libraryFolder).not.toThrow();
});
it('returns a string', () => {
expect(typeof Unity.libraryFolder).toStrictEqual('string');
});
});
});