command.test.js
1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import chai from 'chai';
import sinonChai from 'sinon-chai';
import proxyquire from 'proxyquire';
chai.use(sinonChai);
const {expect} = chai;
describe(`commandConvert`, () => {
const platform = process.platform;
let commandConvert;
describe(`on Windows`, () =>{
beforeEach(() =>{
Object.defineProperty(process, 'platform', {value: 'win32'});
commandConvert = proxyquire('./command', {});
});
afterEach(() =>{
Object.defineProperty(process, 'platform', {value: platform});
});
it(`should convert unix-style env variable usage for windows`, () =>{
expect(commandConvert('$test')).to.equal('%test%');
});
it(`should leave command unchanged when not a variable`, () =>{
expect(commandConvert('test')).to.equal('test');
});
});
describe(`on Unix-based`, () =>{
beforeEach(() => {
Object.defineProperty(process, 'platform', {value: 'linux'});
commandConvert = proxyquire('./command', {});
});
afterEach(() =>{
Object.defineProperty(process, 'platform', {value: platform});
});
it(`should convert windows-style env variable usage for linux`, () =>{
expect(commandConvert('%test%')).to.equal('$test');
});
it(`should leave variable unchanged when using correct operating system`, () =>{
expect(commandConvert('$test')).to.equal('$test');
});
});
});