This commit is contained in:
Shivam Mathur
2020-02-13 09:51:54 +05:30
commit 546224a999
26 changed files with 8591 additions and 0 deletions

54
__tests__/cache.test.ts Normal file
View File

@@ -0,0 +1,54 @@
import * as install from '../src/cache';
/**
* Mock cache.ts
*/
jest.mock('../src/cache', () => ({
run: jest.fn().mockImplementation(
async (): Promise<string> => {
const version: string = process.env['php-version'] || '';
const extensions: string = process.env['extensions'] || '';
const key: string = process.env['key'] || '';
const script_path = 'extensions.sh';
return (
'bash ' + script_path + ' "' + extensions + '-' + key + '" ' + version
);
}
)
}));
/**
* Function to set the process.env
*
* @param version
* @param os
* @param extension_csv
* @param ini_values_csv
* @param coverage_driver
*/
function setEnv(
version: string | number,
extensions: string,
key: string
): void {
process.env['php-version'] = version.toString();
process.env['extensions'] = extensions;
process.env['key'] = key;
}
describe('Install', () => {
it('Test Run', async () => {
setEnv('7.0', 'xdebug, pcov', 'cache-v1');
// @ts-ignore
const script: string = await install.run();
expect(script).toContain('bash extensions.sh "xdebug, pcov-cache-v1" 7.0');
});
it('Test Run', async () => {
setEnv('7.4', 'xdebug, zip', 'cache-v2');
// @ts-ignore
const script: string = await install.run();
expect(script).toContain('bash extensions.sh "xdebug, zip-cache-v2" 7.4');
});
});

22
__tests__/utils.test.ts Normal file
View File

@@ -0,0 +1,22 @@
import * as fs from 'fs';
import * as path from 'path';
import * as utils from '../src/utils';
jest.mock('@actions/core', () => ({
getInput: jest.fn().mockImplementation(key => {
return ['cache-extensions'].indexOf(key) !== -1 ? key : '';
})
}));
describe('Utils tests', () => {
it('checking getInput', async () => {
process.env['test'] = 'cache-extensions';
process.env['undefined'] = '';
expect(await utils.getInput('test', false)).toBe('cache-extensions');
expect(await utils.getInput('undefined', false)).toBe('');
expect(await utils.getInput('cache-extensions', false)).toBe(
'cache-extensions'
);
expect(await utils.getInput('DoesNotExist', false)).toBe('');
});
});