Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolai Laevskii committed May 30, 2023
1 parent 89b480a commit 427804d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
4 changes: 2 additions & 2 deletions __tests__/installer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,14 +283,14 @@ describe('installer tests', () => {
describe('addToPath() tests', () => {
it(`should export DOTNET_ROOT env.var with value from DOTNET_INSTALL_DIR env.var`, async () => {
process.env['DOTNET_INSTALL_DIR'] = 'fictitious/dotnet/install/dir';
installer.DotnetCoreInstaller.addToPath();
installer.DotnetInstallDir.addToPath();
const dotnet_root = process.env['DOTNET_ROOT'];
expect(dotnet_root).toBe(process.env['DOTNET_INSTALL_DIR']);
});

it(`should export value from DOTNET_INSTALL_DIR env.var to the PATH`, async () => {
process.env['DOTNET_INSTALL_DIR'] = 'fictitious/dotnet/install/dir';
installer.DotnetCoreInstaller.addToPath();
installer.DotnetInstallDir.addToPath();
const path = process.env['PATH'];
expect(path).toContain(process.env['DOTNET_INSTALL_DIR']);
});
Expand Down
15 changes: 6 additions & 9 deletions __tests__/setup-dotnet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import semver from 'semver';
import * as auth from '../src/authutil';

import * as setup from '../src/setup-dotnet';
import {DotnetCoreInstaller} from '../src/installer';
import {DotnetCoreInstaller, DotnetInstallDir} from '../src/installer';

describe('setup-dotnet tests', () => {
const inputs = {} as any;
Expand All @@ -25,17 +25,19 @@ describe('setup-dotnet tests', () => {
DotnetCoreInstaller.prototype,
'installDotnet'
);
const addToPathSpy = jest.spyOn(DotnetCoreInstaller, 'addToPath');

const configAuthenticationSpy = jest.spyOn(auth, 'configAuthentication');
const addToPathOriginal = DotnetInstallDir.addToPath;

describe('run() tests', () => {
beforeEach(() => {
DotnetInstallDir.addToPath = jest.fn();
getMultilineInputSpy.mockImplementation(input => inputs[input as string]);
getInputSpy.mockImplementation(input => inputs[input as string]);
});

afterEach(() => {
DotnetInstallDir.addToPath = addToPathOriginal;
jest.clearAllMocks();
jest.resetAllMocks();
});
Expand Down Expand Up @@ -96,10 +98,9 @@ describe('setup-dotnet tests', () => {
inputs['dotnet-quality'] = '';

installDotnetSpy.mockImplementation(() => Promise.resolve(''));
addToPathSpy.mockImplementation(() => {});

await setup.run();
expect(addToPathSpy).toHaveBeenCalledTimes(1);
expect(DotnetInstallDir.addToPath).toHaveBeenCalledTimes(1);
});

it('should call auth.configAuthentication() if source-url input is provided', async () => {
Expand Down Expand Up @@ -140,18 +141,16 @@ describe('setup-dotnet tests', () => {
installDotnetSpy.mockImplementation(() =>
Promise.resolve(`${inputs['dotnet-version']}`)
);
addToPathSpy.mockImplementation(() => {});

await setup.run();
expect(setOutputSpy).toHaveBeenCalledTimes(1);
expect(DotnetInstallDir.addToPath).toHaveBeenCalledTimes(1);
});

it(`shouldn't call setOutput() if parsing dotnet-installer logs failed`, async () => {
inputs['dotnet-version'] = ['6.0.300'];
const warningMessage = `Failed to output the installed version of .NET. The 'dotnet-version' output will not be set.`;

installDotnetSpy.mockImplementation(() => Promise.resolve(null));
addToPathSpy.mockImplementation(() => {});

await setup.run();
expect(warningSpy).toHaveBeenCalledWith(warningMessage);
Expand All @@ -162,8 +161,6 @@ describe('setup-dotnet tests', () => {
inputs['dotnet-version'] = [];
const warningMessage = `The 'dotnet-version' output will not be set.`;

addToPathSpy.mockImplementation(() => {});

await setup.run();

expect(infoSpy).toHaveBeenCalledWith(warningMessage);
Expand Down

0 comments on commit 427804d

Please sign in to comment.