|
3 | 3 |
|
4 | 4 | 'use strict';
|
5 | 5 |
|
| 6 | +import * as sinon from 'sinon'; |
| 7 | + |
6 | 8 | import { expect } from 'chai';
|
7 |
| -import { OSType, getOSType } from '../../../client/common/utils/platform'; |
| 9 | +import * as platformApis from '../../../client/common/utils/platform'; |
| 10 | + |
| 11 | +const { OSType, getOSType } = platformApis; |
| 12 | + |
| 13 | +suite('Utils for platform - getUserHomeDir function', () => { |
| 14 | + let getEnvVarStub: sinon.SinonStub; |
| 15 | + let getOSTypeStub: sinon.SinonStub; |
| 16 | + |
| 17 | + setup(() => { |
| 18 | + getEnvVarStub = sinon.stub(platformApis, 'getEnvironmentVariable'); |
| 19 | + getEnvVarStub.callsFake((envVarName) => { |
| 20 | + if (envVarName === 'USERPROFILE') return 'my/home/dir/in/windows/os'; |
| 21 | + return 'my/home/dir/in/a/not/windows/os'; |
| 22 | + }); |
| 23 | + }); |
| 24 | + |
| 25 | + teardown(() => { |
| 26 | + getEnvVarStub.restore(); |
| 27 | + getOSTypeStub.restore(); |
| 28 | + }); |
| 29 | + |
| 30 | + test('getUserHomeDir when platform is Linux', () => { |
| 31 | + getOSTypeStub = sinon.stub(platformApis, 'getOSType').callsFake(() => platformApis.OSType.Linux); |
| 32 | + |
| 33 | + const os = getOSTypeStub(); |
| 34 | + const homeDirEnvVar = platformApis.getUserHomeDir(); |
| 35 | + |
| 36 | + expect(homeDirEnvVar).equal('my/home/dir/in/a/not/windows/os'); |
| 37 | + expect(os).equal(platformApis.OSType.Linux); |
| 38 | + }); |
| 39 | + |
| 40 | + test('getUserHomeDir when platform is OSX', () => { |
| 41 | + getOSTypeStub = sinon.stub(platformApis, 'getOSType').callsFake(() => platformApis.OSType.OSX); |
| 42 | + |
| 43 | + const os = getOSTypeStub(); |
| 44 | + const homeDirEnvVar = platformApis.getUserHomeDir(); |
| 45 | + |
| 46 | + expect(homeDirEnvVar).equal('my/home/dir/in/a/not/windows/os'); |
| 47 | + expect(os).equal(platformApis.OSType.OSX); |
| 48 | + }); |
| 49 | + |
| 50 | + test('getUserHomeDir when platform is Unknown', () => { |
| 51 | + getOSTypeStub = sinon.stub(platformApis, 'getOSType').callsFake(() => platformApis.OSType.Unknown); |
| 52 | + |
| 53 | + const os = getOSTypeStub(); |
| 54 | + const homeDirEnvVar = platformApis.getUserHomeDir(); |
| 55 | + |
| 56 | + expect(homeDirEnvVar).equal('my/home/dir/in/a/not/windows/os'); |
| 57 | + expect(os).equal(platformApis.OSType.Unknown); |
| 58 | + }); |
| 59 | + |
| 60 | + test('getUserHomeDir when platform is Windows', () => { |
| 61 | + getOSTypeStub = sinon.stub(platformApis, 'getOSType').callsFake(() => platformApis.OSType.Windows); |
| 62 | + |
| 63 | + const os = getOSTypeStub(); |
| 64 | + const homeDirEnvVar = platformApis.getUserHomeDir(); |
| 65 | + |
| 66 | + expect(homeDirEnvVar).equal('my/home/dir/in/a/not/windows/os'); |
| 67 | + expect(os).equal(platformApis.OSType.Windows); |
| 68 | + }); |
| 69 | +}); |
8 | 70 |
|
9 | 71 | suite('Utils for platform - getOSType function', () => {
|
10 | 72 | const testsData = [
|
|
0 commit comments