Files
yarn/__tests__/util/git/git-spawn.js
Krzysztof Zbudniewek 4f41887d36 fix(git-spawn): Set GIT_SSH_VARIANT (#4806)
**Summary**

Fixes #4729.
Previous version in #4805.

Manually specify `GIT_SSH_VARIANT` in order to get package download via `git+ssh` with a non-standard port when using `plink.exe` working.

Without `GIT_SSH_VARIANT` set properly, Git won't convert `-p` into `-P` and `plink.exe` will throw an error about unknown `-p` parameter.

**Test plan**

*Before:*
![virtualbox_msedge_-_win10_30_10_2017_16_35_24](https://user-images.githubusercontent.com/5042328/32179804-9a87c676-bd90-11e7-86d0-09380d61eadf.png)

*After:*
![virtualbox_msedge_-_win10_30_10_2017_19_07_15](https://user-images.githubusercontent.com/5042328/32187512-9bcb980e-bda5-11e7-96ea-27a513837d6e.png)

Also got `git-spawn.js` test suite updated for testing `GIT_SSH_VARIANT`.
2017-10-31 09:10:09 +00:00

94 lines
2.3 KiB
JavaScript

/* @flow */
import path from 'path';
jest.mock('../../../src/util/child.js', () => {
const realChild = (require: any).requireActual('../../../src/util/child.js');
realChild.spawn = jest.fn(() => Promise.resolve(''));
return realChild;
});
function runGit(args, opts): any {
const {spawn} = require('../../../src/util/child.js');
const {spawn: spawnGit} = require('../../../src/util/git/git-spawn.js');
const spawnMock = (spawn: any).mock;
spawnGit(args, opts);
return spawnMock.calls[0];
}
describe('spawn', () => {
beforeEach(() => {
jest.resetModules();
});
test('spawn with default', () => {
process.env.GIT_SSH_COMMAND = '';
const gitCall = runGit(['status']);
delete process.env.GIT_SSH_COMMAND;
expect(gitCall[2].env).toMatchObject({
GIT_ASKPASS: '',
GIT_TERMINAL_PROMPT: 0,
GIT_SSH_COMMAND: '"ssh" -oBatchMode=yes',
GIT_SSH_VARIANT: 'ssh',
...process.env,
});
});
test('spawn with plink', () => {
process.env.GIT_SSH_COMMAND = '';
// Test for case-sensitivity too (should be insensitive)
const plinkPath = path.join('C:', 'pLink.EXE');
process.env.GIT_SSH = plinkPath;
const gitCall = runGit(['status']);
delete process.env.GIT_SSH_COMMAND;
delete process.env.GIT_SSH;
expect(gitCall[2].env).toMatchObject({
GIT_ASKPASS: '',
GIT_TERMINAL_PROMPT: 0,
GIT_SSH_COMMAND: `"${plinkPath}" -batch`,
GIT_SSH_VARIANT: 'plink',
...process.env,
});
});
test('spawn with custom GIT_SSH', () => {
process.env.GIT_SSH_COMMAND = '';
process.env.GIT_SSH = 'custom-ssh.sh';
const gitCall = runGit(['status']);
delete process.env.GIT_SSH;
delete process.env.GIT_SSH_COMMAND;
const calledEnv = gitCall[2].env;
expect(calledEnv).toMatchObject({
GIT_ASKPASS: '',
GIT_TERMINAL_PROMPT: 0,
GIT_SSH_COMMAND: '',
...process.env,
});
});
test('spawn with custom GIT_SSH_COMMAND', () => {
process.env.GIT_SSH_COMMAND = 'some-custom-ssh.sh';
const gitCall = runGit(['status']);
delete process.env.GIT_SSH_COMMAND;
const calledEnv = gitCall[2].env;
expect(calledEnv).toMatchObject({
GIT_ASKPASS: '',
GIT_TERMINAL_PROMPT: 0,
GIT_SSH_COMMAND: 'some-custom-ssh.sh',
...process.env,
});
});
});