diff --git a/src/git-utils.test.ts b/src/git-utils.test.ts index b77d40a7ec..64b76590ae 100644 --- a/src/git-utils.test.ts +++ b/src/git-utils.test.ts @@ -29,10 +29,13 @@ test.serial( process.env["GITHUB_SHA"] = currentSha; const callback = sinon.stub(gitUtils, "getCommitOid"); - callback.withArgs("HEAD").resolves(currentSha); + callback.withArgs(sinon.match.string, "HEAD").resolves(currentSha); const actualRef = await gitUtils.getRef(); t.deepEqual(actualRef, expectedRef); + + t.is(callback.callCount, 1); + t.true(callback.calledOnceWith(tmpDir, "HEAD")); }); }, ); @@ -48,11 +51,17 @@ test.serial( const sha = "a".repeat(40); const callback = sinon.stub(gitUtils, "getCommitOid"); - callback.withArgs("refs/remotes/pull/1/merge").resolves(sha); - callback.withArgs("HEAD").resolves(sha); + callback + .withArgs(sinon.match.string, "refs/remotes/pull/1/merge") + .resolves(sha); + callback.withArgs(sinon.match.any, "HEAD").resolves(sha); const actualRef = await gitUtils.getRef(); t.deepEqual(actualRef, expectedRef); + + t.is(callback.callCount, 2); + t.true(callback.calledWith(tmpDir, "HEAD")); + t.true(callback.calledWith(tmpDir, "refs/remotes/pull/1/merge")); }); }, ); @@ -66,11 +75,18 @@ test.serial( process.env["GITHUB_SHA"] = "a".repeat(40); const callback = sinon.stub(gitUtils, "getCommitOid"); - callback.withArgs(tmpDir, "refs/pull/1/merge").resolves("a".repeat(40)); + callback + .withArgs(tmpDir, "refs/remotes/pull/1/merge") + .resolves("a".repeat(40)); callback.withArgs(tmpDir, "HEAD").resolves("b".repeat(40)); + callback.throws(new Error("Unexpected getCommitOid call in test.")); const actualRef = await gitUtils.getRef(); t.deepEqual(actualRef, "refs/pull/1/head"); + + t.is(callback.callCount, 2); + t.true(callback.calledWith(tmpDir, "refs/remotes/pull/1/merge")); + t.true(callback.calledWith(tmpDir, "HEAD")); }); }, ); @@ -92,11 +108,14 @@ test.serial( process.env["GITHUB_SHA"] = "a".repeat(40); const callback = sinon.stub(gitUtils, "getCommitOid"); - callback.withArgs("refs/pull/1/merge").resolves("b".repeat(40)); - callback.withArgs("HEAD").resolves("b".repeat(40)); + callback.withArgs(tmpDir, "refs/pull/1/merge").resolves("b".repeat(40)); + callback.withArgs(sinon.match.any, "HEAD").resolves("b".repeat(40)); const actualRef = await gitUtils.getRef(); t.deepEqual(actualRef, "refs/pull/2/merge"); + + // getCommitOid shouldn't be called, because the ref should be taken from the input + t.is(callback.callCount, 0); }); }, );