test-platform-shared.js
1.17 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
const assert = require('assert');
const defaultShell = require('../src/index');
const getShell = require('../src/get-shell');
const withEnv = require('./utils').withEnv;
function sharedTests() {
it('custom /bin/zsh shell should work', () => {
withEnv({ SHELL: '/bin/zsh' }, () => {
assert.strictEqual(getShell().shell, '/bin/zsh');
assert.strictEqual(getShell().executeFlag, '-c');
});
});
it('custom execute flag should override default', () => {
withEnv({ SHELL_EXECUTE_FLAG: '--execute' }, () => {
assert.strictEqual(getShell().executeFlag, '--execute');
});
});
it('customizing whole command should work', () => {
withEnv({ SHELL: '/bin/verycustomshell', SHELL_EXECUTE_FLAG: '-x' }, () => {
assert.strictEqual(getShell().shell, '/bin/verycustomshell');
assert.strictEqual(getShell().executeFlag, '-x');
});
});
it('unknown shell without execution flag should throw error', () => {
withEnv({ SHELL: '/bin/false' }, () => {
assert.throws(
() => {
defaultShell.spawn('echo test');
},
/Unable to detect platform shell type/
);
});
});
}
module.exports = sharedTests;