From 2f1b3ce279ce760382792d1e4aa51904508025ef Mon Sep 17 00:00:00 2001 From: Burak Yigit Kaya Date: Thu, 29 Jun 2017 17:52:43 +0100 Subject: [PATCH 1/3] Update: add regression tests for Git.spawn env issues **Summary** Regression tests for #3742 and follow up to #3743. **Test plan** Tests shall pass. --- __tests__/util/git.js | 20 ++++++++++++++++++++ src/util/__mocks__/child.js | 9 +++++++++ 2 files changed, 29 insertions(+) create mode 100644 src/util/__mocks__/child.js diff --git a/__tests__/util/git.js b/__tests__/util/git.js index 3314ee64ca..b25da61a7e 100644 --- a/__tests__/util/git.js +++ b/__tests__/util/git.js @@ -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; @@ -76,6 +79,10 @@ test('secureGitUrl', async function(): Promise { 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) { @@ -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); + expect(spawnMock.calls[0][2].env).toMatchObject({ + GIT_ASKPASS: '', + GIT_TERMINAL_PROMPT: 0, + GIT_SSH_COMMAND: 'ssh -oBatchMode=yes', + }); +}); diff --git a/src/util/__mocks__/child.js b/src/util/__mocks__/child.js new file mode 100644 index 0000000000..9415058cf0 --- /dev/null +++ b/src/util/__mocks__/child.js @@ -0,0 +1,9 @@ +/* @flow */ + +const realChild = (require: any).requireActual('./child.js'); + +realChild.spawn = jest.fn(() => { + return Promise.resolve(''); +}); + +module.exports = realChild; From 9519ad3105ff43b049ebac7ea123e9c88c262d8c Mon Sep 17 00:00:00 2001 From: Burak Yigit Kaya Date: Thu, 29 Jun 2017 18:56:55 +0100 Subject: [PATCH 2/3] Fix CircleCI tests where process.env needs to be overridden --- __tests__/util/git.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__tests__/util/git.js b/__tests__/util/git.js index b25da61a7e..4112ed7b97 100644 --- a/__tests__/util/git.js +++ b/__tests__/util/git.js @@ -134,8 +134,8 @@ test('spawn', () => { Git.spawn(['status']); - expect(spawnMock.calls[0][2].env).toMatchObject(process.env); expect(spawnMock.calls[0][2].env).toMatchObject({ + ...process.env, GIT_ASKPASS: '', GIT_TERMINAL_PROMPT: 0, GIT_SSH_COMMAND: 'ssh -oBatchMode=yes', From 77dfcc9a7f8c3ebcc3f871a8b1407ac1c447a5b4 Mon Sep 17 00:00:00 2001 From: Burak Yigit Kaya Date: Thu, 29 Jun 2017 18:57:10 +0100 Subject: [PATCH 3/3] Don't use unnecessary braces and return statements --- src/util/__mocks__/child.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/util/__mocks__/child.js b/src/util/__mocks__/child.js index 9415058cf0..12066b691d 100644 --- a/src/util/__mocks__/child.js +++ b/src/util/__mocks__/child.js @@ -2,8 +2,6 @@ const realChild = (require: any).requireActual('./child.js'); -realChild.spawn = jest.fn(() => { - return Promise.resolve(''); -}); +realChild.spawn = jest.fn(() => Promise.resolve('')); module.exports = realChild;