Refactor install.ts

This commit is contained in:
Shivam Mathur
2020-10-04 17:03:02 +05:30
parent 8cb01730c7
commit f8e867a9ff
5 changed files with 77 additions and 52 deletions

View File

@ -4,7 +4,7 @@ import * as install from '../src/install';
* Mock install.ts
*/
jest.mock('../src/install', () => ({
build: jest.fn().mockImplementation(
getScript: jest.fn().mockImplementation(
async (
filename: string,
version: string,
@ -45,11 +45,19 @@ jest.mock('../src/install', () => ({
switch (os_version) {
case 'darwin':
case 'linux':
script = await install.build(os_version + '.sh', version, os_version);
script = await install.getScript(
os_version + '.sh',
version,
os_version
);
script += 'bash script.sh ' + version + ' ' + __dirname;
break;
case 'win32':
script = await install.build(os_version + '.sh', version, os_version);
script = await install.getScript(
os_version + '.sh',
version,
os_version
);
script += 'pwsh script.ps1 ' + version + ' ' + __dirname;
break;
default:

View File

@ -209,6 +209,15 @@ describe('Utils tests', () => {
);
});
it('checking scriptTool', async () => {
expect(await utils.scriptTool('linux')).toBe('bash');
expect(await utils.scriptTool('darwin')).toBe('bash');
expect(await utils.scriptTool('win32')).toBe('pwsh');
expect(await utils.scriptTool('openbsd')).toContain(
'Platform openbsd is not supported'
);
});
it('checking customPackage', async () => {
const script_path: string = path.join('ext', 'pkg.sh');
expect(await utils.customPackage('pkg', 'ext', '1.2.3', 'linux')).toContain(