Update unit-tests

This commit is contained in:
IvanZosimov 2023-05-05 10:44:54 +02:00
parent 6adeb768ce
commit c5a57b219c
2 changed files with 177 additions and 172 deletions

View File

@ -53,59 +53,59 @@ describe('DotnetCoreInstaller tests', () => {
} }
}, 30000); }, 30000);
// it('Aquires multiple versions of dotnet', async () => { it('Aquires multiple versions of dotnet', async () => {
// const versions = ['2.2.207', '3.1.120']; const versions = ['2.2.207', '3.1.120'];
// for (const version of versions) { for (const version of versions) {
// await getDotnet(version); await getDotnet(version);
// } }
// expect(fs.existsSync(path.join(toolDir, 'sdk', '2.2.207'))).toBe(true); expect(fs.existsSync(path.join(toolDir, 'sdk', '2.2.207'))).toBe(true);
// expect(fs.existsSync(path.join(toolDir, 'sdk', '3.1.120'))).toBe(true); expect(fs.existsSync(path.join(toolDir, 'sdk', '3.1.120'))).toBe(true);
// if (IS_WINDOWS) { if (IS_WINDOWS) {
// expect(fs.existsSync(path.join(toolDir, 'dotnet.exe'))).toBe(true); expect(fs.existsSync(path.join(toolDir, 'dotnet.exe'))).toBe(true);
// } else { } else {
// expect(fs.existsSync(path.join(toolDir, 'dotnet'))).toBe(true); expect(fs.existsSync(path.join(toolDir, 'dotnet'))).toBe(true);
// } }
// expect(process.env.DOTNET_ROOT).toBeDefined(); expect(process.env.DOTNET_ROOT).toBeDefined();
// expect(process.env.PATH).toBeDefined(); expect(process.env.PATH).toBeDefined();
// expect(process.env.DOTNET_ROOT).toBe(toolDir); expect(process.env.DOTNET_ROOT).toBe(toolDir);
// expect(process.env.PATH?.startsWith(toolDir)).toBe(true); expect(process.env.PATH?.startsWith(toolDir)).toBe(true);
// }, 600000); }, 600000);
// it('Acquires version of dotnet if no matching version is installed', async () => { it('Acquires version of dotnet if no matching version is installed', async () => {
// await getDotnet('3.1.201'); await getDotnet('3.1.201');
// expect(fs.existsSync(path.join(toolDir, 'sdk', '3.1.201'))).toBe(true); expect(fs.existsSync(path.join(toolDir, 'sdk', '3.1.201'))).toBe(true);
// if (IS_WINDOWS) { if (IS_WINDOWS) {
// expect(fs.existsSync(path.join(toolDir, 'dotnet.exe'))).toBe(true); expect(fs.existsSync(path.join(toolDir, 'dotnet.exe'))).toBe(true);
// } else { } else {
// expect(fs.existsSync(path.join(toolDir, 'dotnet'))).toBe(true); expect(fs.existsSync(path.join(toolDir, 'dotnet'))).toBe(true);
// } }
// expect(process.env.DOTNET_ROOT).toBeDefined(); expect(process.env.DOTNET_ROOT).toBeDefined();
// expect(process.env.PATH).toBeDefined(); expect(process.env.PATH).toBeDefined();
// expect(process.env.DOTNET_ROOT).toBe(toolDir); expect(process.env.DOTNET_ROOT).toBe(toolDir);
// expect(process.env.PATH?.startsWith(toolDir)).toBe(true); expect(process.env.PATH?.startsWith(toolDir)).toBe(true);
// }, 600000); //This needs some time to download on "slower" internet connections }, 600000); //This needs some time to download on "slower" internet connections
// it('Acquires generic version of dotnet if no matching version is installed', async () => { it('Acquires generic version of dotnet if no matching version is installed', async () => {
// await getDotnet('3.1'); await getDotnet('3.1');
// const directory = fs const directory = fs
// .readdirSync(path.join(toolDir, 'sdk')) .readdirSync(path.join(toolDir, 'sdk'))
// .filter(fn => fn.startsWith('3.1.')); .filter(fn => fn.startsWith('3.1.'));
// expect(directory.length > 0).toBe(true); expect(directory.length > 0).toBe(true);
// if (IS_WINDOWS) { if (IS_WINDOWS) {
// expect(fs.existsSync(path.join(toolDir, 'dotnet.exe'))).toBe(true); expect(fs.existsSync(path.join(toolDir, 'dotnet.exe'))).toBe(true);
// } else { } else {
// expect(fs.existsSync(path.join(toolDir, 'dotnet'))).toBe(true); expect(fs.existsSync(path.join(toolDir, 'dotnet'))).toBe(true);
// } }
// expect(process.env.DOTNET_ROOT).toBeDefined(); expect(process.env.DOTNET_ROOT).toBeDefined();
// expect(process.env.PATH).toBeDefined(); expect(process.env.PATH).toBeDefined();
// expect(process.env.DOTNET_ROOT).toBe(toolDir); expect(process.env.DOTNET_ROOT).toBe(toolDir);
// expect(process.env.PATH?.startsWith(toolDir)).toBe(true); expect(process.env.PATH?.startsWith(toolDir)).toBe(true);
// }, 600000); //This needs some time to download on "slower" internet connections }, 600000); //This needs some time to download on "slower" internet connections
it('Returns string with installed SDK version', async () => { it('Returns string with installed SDK version', async () => {
const version = '6.0.1xx'; const version = '6.0.1xx';
@ -116,139 +116,139 @@ describe('DotnetCoreInstaller tests', () => {
}, 600000); }, 600000);
}); });
// describe('DotnetVersionResolver tests', () => { describe('DotnetVersionResolver tests', () => {
// each([ each([
// '3.1', '3.1',
// '3.x', '3.x',
// '3.1.x', '3.1.x',
// '3.1.*', '3.1.*',
// '3.1.X', '3.1.X',
// '3.1.2', '3.1.2',
// '3.1.0-preview1' '3.1.0-preview1'
// ]).test( ]).test(
// "if valid version: '%s' is supplied, it should return version object with some value", "if valid version: '%s' is supplied, it should return version object with some value",
// async version => { async version => {
// const dotnetVersionResolver = new installer.DotnetVersionResolver( const dotnetVersionResolver = new installer.DotnetVersionResolver(
// version version
// ); );
// const versionObject = await dotnetVersionResolver.createDotNetVersion(); const versionObject = await dotnetVersionResolver.createDotNetVersion();
// expect(!!versionObject.value).toBe(true); expect(!!versionObject.value).toBe(true);
// } }
// ); );
// each([ each([
// '.', '.',
// '..', '..',
// ' . ', ' . ',
// '. ', '. ',
// ' .', ' .',
// ' . . ', ' . . ',
// ' .. ', ' .. ',
// ' . ', ' . ',
// '-1.-1', '-1.-1',
// '-1', '-1',
// '-1.-1.-1', '-1.-1.-1',
// '..3', '..3',
// '1..3', '1..3',
// '1..', '1..',
// '.2.3', '.2.3',
// '.2.x', '.2.x',
// '*.', '*.',
// '1.2.', '1.2.',
// '1.2.-abc', '1.2.-abc',
// 'a.b', 'a.b',
// 'a.b.c', 'a.b.c',
// 'a.b.c-preview', 'a.b.c-preview',
// ' 0 . 1 . 2 ', ' 0 . 1 . 2 ',
// 'invalid' 'invalid'
// ]).test( ]).test(
// "if invalid version: '%s' is supplied, it should throw", "if invalid version: '%s' is supplied, it should throw",
// async version => { async version => {
// const dotnetVersionResolver = new installer.DotnetVersionResolver( const dotnetVersionResolver = new installer.DotnetVersionResolver(
// version version
// ); );
// await expect( await expect(
// async () => await dotnetVersionResolver.createDotNetVersion() async () => await dotnetVersionResolver.createDotNetVersion()
// ).rejects.toThrow(); ).rejects.toThrow();
// } }
// ); );
// each(['3.1', '3.1.x', '3.1.*', '3.1.X', '5.0.1xx']).test( each(['3.1', '3.1.x', '3.1.*', '3.1.X', '5.0.1xx']).test(
// "if version: '%s' that can be resolved to 'channel' option is supplied, it should set type to 'channel' in version object", "if version: '%s' that can be resolved to 'channel' option is supplied, it should set type to 'channel' in version object",
// async version => { async version => {
// const dotnetVersionResolver = new installer.DotnetVersionResolver( const dotnetVersionResolver = new installer.DotnetVersionResolver(
// version version
// ); );
// const versionObject = await dotnetVersionResolver.createDotNetVersion(); const versionObject = await dotnetVersionResolver.createDotNetVersion();
// expect(versionObject.type.toLowerCase().includes('channel')).toBe(true); expect(versionObject.type.toLowerCase().includes('channel')).toBe(true);
// } }
// ); );
// each(['6.0', '6.0.x', '6.0.*', '6.0.X', '6.0.1xx']).test( each(['6.0', '6.0.x', '6.0.*', '6.0.X', '6.0.1xx']).test(
// "if version: '%s' that can be resolved to 'channel' option is supplied and its major tag is >= 6, it should set type to 'channel' and qualityFlag to 'true' in version object", "if version: '%s' that can be resolved to 'channel' option is supplied and its major tag is >= 6, it should set type to 'channel' and qualityFlag to 'true' in version object",
// async version => { async version => {
// const dotnetVersionResolver = new installer.DotnetVersionResolver( const dotnetVersionResolver = new installer.DotnetVersionResolver(
// version version
// ); );
// const versionObject = await dotnetVersionResolver.createDotNetVersion(); const versionObject = await dotnetVersionResolver.createDotNetVersion();
// expect(versionObject.type.toLowerCase().includes('channel')).toBe(true); expect(versionObject.type.toLowerCase().includes('channel')).toBe(true);
// expect(versionObject.qualityFlag).toBe(true); expect(versionObject.qualityFlag).toBe(true);
// } }
// ); );
// each(['3.1.2', '3.1.0-preview1']).test( each(['3.1.2', '3.1.0-preview1']).test(
// "if version: '%s' that can be resolved to 'version' option is supplied, it should set quality flag to 'false' and type to 'version' in version object", "if version: '%s' that can be resolved to 'version' option is supplied, it should set quality flag to 'false' and type to 'version' in version object",
// async version => { async version => {
// const dotnetVersionResolver = new installer.DotnetVersionResolver( const dotnetVersionResolver = new installer.DotnetVersionResolver(
// version version
// ); );
// const versionObject = await dotnetVersionResolver.createDotNetVersion(); const versionObject = await dotnetVersionResolver.createDotNetVersion();
// expect(versionObject.type.toLowerCase().includes('version')).toBe(true); expect(versionObject.type.toLowerCase().includes('version')).toBe(true);
// expect(versionObject.qualityFlag).toBe(false); expect(versionObject.qualityFlag).toBe(false);
// } }
// ); );
// each(['3.1.2', '3.1']).test( each(['3.1.2', '3.1']).test(
// 'it should create proper line arguments for powershell/bash installation scripts', 'it should create proper line arguments for powershell/bash installation scripts',
// async version => { async version => {
// const dotnetVersionResolver = new installer.DotnetVersionResolver( const dotnetVersionResolver = new installer.DotnetVersionResolver(
// version version
// ); );
// const versionObject = await dotnetVersionResolver.createDotNetVersion(); const versionObject = await dotnetVersionResolver.createDotNetVersion();
// const windowsRegEx = new RegExp(/^-[VC]/); const windowsRegEx = new RegExp(/^-[VC]/);
// const nonWindowsRegEx = new RegExp(/^--[vc]/); const nonWindowsRegEx = new RegExp(/^--[vc]/);
// if (IS_WINDOWS) { if (IS_WINDOWS) {
// expect(windowsRegEx.test(versionObject.type)).toBe(true); expect(windowsRegEx.test(versionObject.type)).toBe(true);
// expect(nonWindowsRegEx.test(versionObject.type)).toBe(false); expect(nonWindowsRegEx.test(versionObject.type)).toBe(false);
// } else { } else {
// expect(nonWindowsRegEx.test(versionObject.type)).toBe(true); expect(nonWindowsRegEx.test(versionObject.type)).toBe(true);
// expect(windowsRegEx.test(versionObject.type)).toBe(false); expect(windowsRegEx.test(versionObject.type)).toBe(false);
// } }
// } }
// ); );
// it('Should throw if supplied dotnet version is in A.B.Cxx syntax and the major tag is lower than 5', async () => { it('Should throw if supplied dotnet version is in A.B.Cxx syntax and the major tag is lower than 5', async () => {
// const version = '3.1.1xx'; const version = '3.1.1xx';
// const dotnetVersionResolver = new installer.DotnetVersionResolver(version); const dotnetVersionResolver = new installer.DotnetVersionResolver(version);
// await expect(dotnetVersionResolver.createDotNetVersion()).rejects.toThrow( await expect(dotnetVersionResolver.createDotNetVersion()).rejects.toThrow(
// `'dotnet-version' was supplied in invalid format: ${version}! The A.B.Cxx syntax is available since the .NET 5.0 release.` `'dotnet-version' was supplied in invalid format: ${version}! The A.B.Cxx syntax is available since the .NET 5.0 release.`
// ); );
// }, 600000); }, 600000);
// it('Should resolve version supplied as * to channel type and set value to LTS', async () => { it('Should resolve version supplied as * to channel type and set value to LTS', async () => {
// const version = '*'; const version = '*';
// const dotnetVersionResolver = new installer.DotnetVersionResolver(version); const dotnetVersionResolver = new installer.DotnetVersionResolver(version);
// const versionObject = await dotnetVersionResolver.createDotNetVersion(); const versionObject = await dotnetVersionResolver.createDotNetVersion();
// expect(versionObject.type.toLowerCase().includes('channel')).toBe(true); expect(versionObject.type.toLowerCase().includes('channel')).toBe(true);
// expect(versionObject.value).toBe('LTS'); expect(versionObject.value).toBe('LTS');
// }, 600000); }, 600000);
// }); });
function normalizeFileContents(contents: string): string { function normalizeFileContents(contents: string): string {
return contents return contents

View File

@ -274,15 +274,20 @@ export class DotnetCoreInstaller {
private async getListOfInstalledVersions(): Promise<string[]> { private async getListOfInstalledVersions(): Promise<string[]> {
const installationPath = process.env['DOTNET_INSTALL_DIR']!; const installationPath = process.env['DOTNET_INSTALL_DIR']!;
const versionsOnRunner: string[] = (await readdir( const versionsOnRunner: string[] = (
path.join(installationPath.replace(/'/g, ''), 'sdk') await readdir(path.join(installationPath.replace(/'/g, ''), 'sdk'))
)).filter((el) => semver.valid(el)); ).filter(el => semver.valid(el));
return versionsOnRunner; return versionsOnRunner;
} }
private async outputDotnetVersion(listOfInstalledVersions: string[]): Promise<string> { private async outputDotnetVersion(
const updatedListOfInstalledVersions = await this.getListOfInstalledVersions(); listOfInstalledVersions: string[]
const installedVersion = updatedListOfInstalledVersions.filter((el) => !listOfInstalledVersions.includes(el)) ): Promise<string> {
const updatedListOfInstalledVersions =
await this.getListOfInstalledVersions();
const installedVersion = updatedListOfInstalledVersions.filter(
el => !listOfInstalledVersions.includes(el)
);
return installedVersion[0]; return installedVersion[0];
} }
} }