Skip to content

Commit cd26fec

Browse files
BYKbestander
authored andcommitted
Update: add regression tests for Git.spawn env issues (#3759)
* Update: add regression tests for Git.spawn env issues **Summary** Regression tests for #3742 and follow up to #3743. **Test plan** Tests shall pass. * Fix CircleCI tests where process.env needs to be overridden * Don't use unnecessary braces and return statements
1 parent 08a9c7b commit cd26fec

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

__tests__/util/git.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/* @flow */
22

3+
jest.mock('../../src/util/child.js');
4+
35
import Git from '../../src/util/git.js';
6+
import {spawn} from '../../src/util/child.js';
47
import {NoopReporter} from '../../src/reporters/index.js';
58

69
jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000;
@@ -76,6 +79,10 @@ test('secureGitUrl', async function(): Promise<void> {
7679
const reporter = new NoopReporter();
7780

7881
let hasException = false;
82+
(Git: any).repoExists = jest.fn();
83+
Git.repoExists.mockImplementation(() => Promise.resolve(true)).mockImplementationOnce(() => {
84+
throw new Error('Non-existent repo!');
85+
});
7986
try {
8087
await Git.secureGitUrl(Git.npmUrlToGitUrl('http://fake-fake-fake-fake.com/123.git'), '', reporter);
8188
} catch (e) {
@@ -121,3 +128,16 @@ de43f4a993d1e08cd930ee22ecb2bac727f53449 refs/tags/v0.21.0-pre`),
121128
'v0.21.0-pre': 'de43f4a993d1e08cd930ee22ecb2bac727f53449',
122129
});
123130
});
131+
132+
test('spawn', () => {
133+
const spawnMock = (spawn: any).mock;
134+
135+
Git.spawn(['status']);
136+
137+
expect(spawnMock.calls[0][2].env).toMatchObject({
138+
...process.env,
139+
GIT_ASKPASS: '',
140+
GIT_TERMINAL_PROMPT: 0,
141+
GIT_SSH_COMMAND: 'ssh -oBatchMode=yes',
142+
});
143+
});

src/util/__mocks__/child.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* @flow */
2+
3+
const realChild = (require: any).requireActual('./child.js');
4+
5+
realChild.spawn = jest.fn(() => Promise.resolve(''));
6+
7+
module.exports = realChild;

0 commit comments

Comments
 (0)