Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions __tests__/util/git.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/* @flow */

jest.mock('../../src/util/child.js');

import Git from '../../src/util/git.js';
import {spawn} from '../../src/util/child.js';
import {NoopReporter} from '../../src/reporters/index.js';

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

let hasException = false;
(Git: any).repoExists = jest.fn();
Git.repoExists.mockImplementation(() => Promise.resolve(true)).mockImplementationOnce(() => {
throw new Error('Non-existent repo!');
});
try {
await Git.secureGitUrl(Git.npmUrlToGitUrl('http://fake-fake-fake-fake.com/123.git'), '', reporter);
} catch (e) {
Expand Down Expand Up @@ -121,3 +128,16 @@ de43f4a993d1e08cd930ee22ecb2bac727f53449 refs/tags/v0.21.0-pre`),
'v0.21.0-pre': 'de43f4a993d1e08cd930ee22ecb2bac727f53449',
});
});

test('spawn', () => {
const spawnMock = (spawn: any).mock;

Git.spawn(['status']);

expect(spawnMock.calls[0][2].env).toMatchObject({
...process.env,
GIT_ASKPASS: '',
GIT_TERMINAL_PROMPT: 0,
GIT_SSH_COMMAND: 'ssh -oBatchMode=yes',
});
});
7 changes: 7 additions & 0 deletions src/util/__mocks__/child.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* @flow */

const realChild = (require: any).requireActual('./child.js');

realChild.spawn = jest.fn(() => Promise.resolve(''));

module.exports = realChild;