tests: refactor install.test.ts to use jest.each

This commit is contained in:
Aneesh Relan 2021-10-09 17:30:06 +05:30
parent 8dfe214356
commit 49a0bad962

View File

@ -69,93 +69,115 @@ function setEnv(
}
describe('Install', () => {
it('Test install on windows', async () => {
setEnv('7.0', 'win32', '', '', '', '');
it.each`
version | extension_csv | ini_values_csv | coverage_driver | tools | output
${'7.0'} | ${''} | ${''} | ${''} | ${''} | ${new RegExp(`initial script.*pwsh win32.ps1 7.0.*${__dirname}`)}
${'7.3'} | ${''} | ${''} | ${''} | ${''} | ${new RegExp(`initial script.*pwsh win32.ps1 7.3.*${__dirname}`)}
${'7.3'} | ${'a, b'} | ${'a=b'} | ${'x'} | ${''} | ${new RegExp(`initial script.*install extensions*set coverage driver.*edit php.ini.*pwsh win32.ps1 7.3.*${__dirname}`)}
`(
'Test install on windows for $version with extensions=$extension_csv, ini_values=$ini_values_csv, coverage_driver=$coverage_driver, tools=$tools',
async ({
version,
extension_csv,
ini_values_csv,
coverage_driver,
tools,
output
}) => {
setEnv(
version,
'win32',
extension_csv,
ini_values_csv,
coverage_driver,
tools
);
let script: string = '' + (await install.run());
expect(script).toContain('initial script');
expect(script).toContain('pwsh win32.ps1 7.0 ' + __dirname);
expect(await install.run()).toMatch(output);
}
);
setEnv('7.3', 'win32', '', '', '', '');
it.each`
version | extension_csv | ini_values_csv | coverage_driver | tools | output
${'7.3'} | ${''} | ${''} | ${''} | ${''} | ${new RegExp(`initial script.*bash linux.sh 7.3`)}
${'latest'} | ${''} | ${''} | ${''} | ${''} | ${new RegExp(`initial script.*bash linux.sh 8.0`)}
${'7.3'} | ${'a, b'} | ${'a=b'} | ${'x'} | ${'phpunit'} | ${new RegExp(`initial script.*add_tool.*install extensions.*set coverage driver.*edit php.ini.*bash linux.sh 7.3`)}
`(
'Test install on linux for $version with extensions=$extension_csv, ini_values=$ini_values_csv, coverage_driver=$coverage_driver, tools=$tools',
async ({
version,
extension_csv,
ini_values_csv,
coverage_driver,
tools,
output
}) => {
setEnv(
version,
'linux',
extension_csv,
ini_values_csv,
coverage_driver,
tools
);
script = '' + (await install.run());
expect(script).toContain('initial script');
expect(script).toContain('pwsh win32.ps1 7.3 ' + __dirname);
expect('' + (await install.run())).toMatch(output);
}
);
setEnv('7.3', 'win32', 'a, b', 'a=b', 'x', '');
it.each`
version | extension_csv | ini_values_csv | coverage_driver | tools | output
${'7.3'} | ${''} | ${''} | ${''} | ${''} | ${new RegExp(`initial script.*bash darwin.sh 7.3 .*${__dirname}`)}
${'7.3'} | ${'a, b'} | ${'a=b'} | ${'x'} | ${''} | ${new RegExp(`initial script.*install extensions.*set coverage driver.*edit php.ini.*bash darwin.sh 7.3 .*${__dirname}`)}
`(
'Test install on darwin for $version with extensions=$extension_csv, ini_values=$ini_values_csv, coverage_driver=$coverage_driver, tools=$tools',
async ({
version,
extension_csv,
ini_values_csv,
coverage_driver,
tools,
output
}) => {
setEnv(
version,
'darwin',
extension_csv,
ini_values_csv,
coverage_driver,
tools
);
script = '' + (await install.run());
expect(script).toContain('initial script');
expect(script).toContain('install extensions');
expect(script).toContain('edit php.ini');
expect(script).toContain('set coverage driver');
expect(script).toContain('pwsh win32.ps1 7.3 ' + __dirname);
});
it('Test install on linux', async () => {
setEnv('7.3', 'linux', '', '', '', '');
let script: string = '' + (await install.run());
expect(script).toContain('initial script');
expect(script).toContain('bash linux.sh 7.3 ');
setEnv('latest', 'linux', '', '', '', '');
script = '' + (await install.run());
expect(script).toContain('initial script');
expect(script).toContain('bash linux.sh 8.0 ');
setEnv('7.3', 'linux', 'a, b', 'a=b', 'x', 'phpunit');
script = '' + (await install.run());
expect(script).toContain('initial script');
expect(script).toContain('install extensions');
expect(script).toContain('edit php.ini');
expect(script).toContain('set coverage driver');
expect(script).toContain('bash linux.sh 7.3');
expect(script).toContain('add_tool');
});
it('Test install on darwin', async () => {
setEnv('7.3', 'darwin', '', '', '', '');
let script: string = '' + (await install.run());
expect(script).toContain('initial script');
expect(script).toContain('bash darwin.sh 7.3 ' + __dirname);
setEnv('7.3', 'darwin', 'a, b', 'a=b', 'x', '');
script = '' + (await install.run());
expect(script).toContain('initial script');
expect(script).toContain('install extensions');
expect(script).toContain('edit php.ini');
expect(script).toContain('set coverage driver');
expect(script).toContain('bash darwin.sh 7.3 ' + __dirname);
});
it('Test malformed version inputs', async () => {
setEnv('7.4.1', 'darwin', '', '', '', '');
let script: string = '' + '' + (await install.run());
expect(script).toContain('initial script');
expect(script).toContain('bash darwin.sh 7.4 ' + __dirname);
setEnv(8.0, 'darwin', '', '', '', '');
script = '' + (await install.run());
expect(script).toContain('initial script');
expect(script).toContain('bash darwin.sh 8.0 ' + __dirname);
setEnv(8, 'darwin', '', '', '', '');
script = '' + (await install.run());
expect(script).toContain('initial script');
expect(script).toContain('bash darwin.sh 8.0 ' + __dirname);
setEnv(8.1, 'darwin', '', '', '', '');
script = '' + (await install.run());
expect(script).toContain('initial script');
expect(script).toContain('bash darwin.sh 8.1 ' + __dirname);
});
expect('' + (await install.run())).toMatch(output);
}
);
it.each`
version | extension_csv | ini_values_csv | coverage_driver | tools | output
${'7.4.1'} | ${''} | ${''} | ${''} | ${''} | ${new RegExp(`initial script.*bash darwin.sh 7.4 .*${__dirname}`)}
${'8.0'} | ${''} | ${''} | ${''} | ${''} | ${new RegExp(`initial script.*bash darwin.sh 8.0 .*${__dirname}`)}
${'8'} | ${''} | ${''} | ${''} | ${''} | ${new RegExp(`initial script.*bash darwin.sh 8.0 .*${__dirname}`)}
${'8.1'} | ${''} | ${''} | ${''} | ${''} | ${new RegExp(`initial script.*bash darwin.sh 8.1 .*${__dirname}`)}
`(
'Test malformed version inputs for $version with extensions=$extension_csv, ini_values=$ini_values_csv, coverage_driver=$coverage_driver, tools=$tools',
async ({
version,
extension_csv,
ini_values_csv,
coverage_driver,
tools,
output
}) => {
setEnv(
version,
'darwin',
extension_csv,
ini_values_csv,
coverage_driver,
tools
);
expect('' + (await install.run())).toMatch(output);
}
);
});