mirror of
https://github.com/azure/login.git
synced 2026-03-15 09:20:56 -04:00
Added Unit tests (#15)
* Added unit tests for Azure PowerShell * Added unit tests * changes in utils * removed babel * changed variable name of enable-PSSession * refactor * added ci.yml * changes in utils test
This commit is contained in:
48
__tests__/PowerShell/Utilities/Utils.test.ts
Normal file
48
__tests__/PowerShell/Utilities/Utils.test.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import Utils from '../../../src/PowerShell/Utilities/Utils';
|
||||
|
||||
const version: string = '9.0.0';
|
||||
const moduleName: string = 'az';
|
||||
|
||||
afterEach(() => {
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
describe('Testing isValidVersion', () => {
|
||||
const validVersion: string = '1.2.4';
|
||||
const invalidVersion: string = 'a.bcd';
|
||||
|
||||
test('isValidVersion should be true', () => {
|
||||
expect(Utils.isValidVersion(validVersion)).toBeTruthy();
|
||||
});
|
||||
test('isValidVersion should be false', () => {
|
||||
expect(Utils.isValidVersion(invalidVersion)).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Testing setPSModulePath', () => {
|
||||
test('PSModulepath with azPSVersion non-empty', () => {
|
||||
if(!process.env.PSModulePath) {
|
||||
process.env.PSModulePath = process.env.PSModulePath + "modulePath";
|
||||
}
|
||||
Utils.setPSModulePath(version);
|
||||
expect(process.env.PSModulepath).toContain(version);
|
||||
});
|
||||
test('PSModulePath with azPSVersion empty', () => {
|
||||
const currPSModulePath = process.env.PSModulepath;
|
||||
Utils.setPSModulePath();
|
||||
expect(process.env.PSModulePath).not.toEqual(currPSModulePath);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Testing getLatestModule', () => {
|
||||
let getLatestModuleSpy;
|
||||
|
||||
beforeEach(() => {
|
||||
getLatestModuleSpy = jest.spyOn(Utils, 'getLatestModule');
|
||||
});
|
||||
test('getLatestModule should pass', async () => {
|
||||
getLatestModuleSpy.mockImplementationOnce((_moduleName: string) => Promise.resolve(version));
|
||||
await Utils.getLatestModule(moduleName);
|
||||
expect(getLatestModuleSpy).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user