init
This commit is contained in:
54
__tests__/cache.test.ts
Normal file
54
__tests__/cache.test.ts
Normal 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
22
__tests__/utils.test.ts
Normal 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('');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user