Skip to content

Commit 963d337

Browse files
committed
ref microsoft#44776 Refactoring test
1 parent ac63779 commit 963d337

1 file changed

Lines changed: 20 additions & 10 deletions

File tree

extensions/git/src/test/git.test.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -190,16 +190,18 @@ This is a commit message.`;
190190
This is a commit message.`;
191191

192192
const git = sinon.createStubInstance(Git);
193-
git.exec = sinon.stub();
194-
git.exec
195-
.withArgs('REPOSITORY_ROOT', ['show', '-s', '--format=%H\n%P\n%B', 'REF_SINGLE_PARENT'], spawnOption)
196-
.returns(Promise.resolve({stdout: GIT_OUTPUT_SINGLE_PARENT}));
197-
git.exec
198-
.withArgs('REPOSITORY_ROOT', ['show', '-s', '--format=%H\n%P\n%B', 'REF_MULTIPLE_PARENTS'], spawnOption)
199-
.returns(Promise.resolve({stdout: GIT_OUTPUT_MULTIPLE_PARENTS}));
200-
git.exec
201-
.withArgs('REPOSITORY_ROOT', ['show', '-s', '--format=%H\n%P\n%B', 'REF_NO_PARENTS'], spawnOption)
202-
.returns(Promise.resolve({stdout: GIT_OUTPUT_NO_PARENTS}));
193+
git.exec = stub([
194+
{
195+
withArgs: ['REPOSITORY_ROOT', ['show', '-s', '--format=%H\n%P\n%B', 'REF_SINGLE_PARENT'], spawnOption],
196+
returns: GIT_OUTPUT_SINGLE_PARENT
197+
}, {
198+
withArgs: ['REPOSITORY_ROOT', ['show', '-s', '--format=%H\n%P\n%B', 'REF_MULTIPLE_PARENTS'], spawnOption],
199+
returns: GIT_OUTPUT_MULTIPLE_PARENTS
200+
}, {
201+
withArgs: ['REPOSITORY_ROOT', ['show', '-s', '--format=%H\n%P\n%B', 'REF_NO_PARENTS'], spawnOption],
202+
returns: GIT_OUTPUT_NO_PARENTS
203+
}
204+
]);
203205
const repository = new Repository(git, 'REPOSITORY_ROOT');
204206

205207
test('get commit', async () => {
@@ -219,5 +221,13 @@ This is a commit message.`;
219221
const commit = await repository.getCommit('REF_NO_PARENTS');
220222
assert.deepEqual(commit.previousHashes, []);
221223
});
224+
225+
function stub(argOutputPairs: {withArgs: any[], returns: string}[]): sinon.SinonStub {
226+
const stub = sinon.stub();
227+
argOutputPairs.forEach(({withArgs, returns}) => {
228+
stub.withArgs(...withArgs).returns(Promise.resolve({stdout: returns}));
229+
});
230+
return stub;
231+
}
222232
});
223233
});

0 commit comments

Comments
 (0)