From 42277414c74077324e1a1eb1f3cfd58f64fbabc5 Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Wed, 23 Sep 2026 13:38:53 +0100 Subject: [PATCH] Stub `getCommitOid` correctly and check calls --- src/git-utils.test.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/git-utils.test.ts b/src/git-utils.test.ts index f6a25778a..64b76590a 100644 --- a/src/git-utils.test.ts +++ b/src/git-utils.test.ts @@ -34,6 +34,7 @@ test.serial( const actualRef = await gitUtils.getRef(); t.deepEqual(actualRef, expectedRef); + t.is(callback.callCount, 1); t.true(callback.calledOnceWith(tmpDir, "HEAD")); }); }, @@ -58,6 +59,8 @@ test.serial( 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")); }); }, @@ -72,14 +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.true(callback.calledOnceWith(tmpDir, "refs/pull/1/merge")); - t.true(callback.calledOnceWith(tmpDir, "HEAD")); + t.is(callback.callCount, 2); + t.true(callback.calledWith(tmpDir, "refs/remotes/pull/1/merge")); + t.true(callback.calledWith(tmpDir, "HEAD")); }); }, ); @@ -107,8 +114,8 @@ test.serial( const actualRef = await gitUtils.getRef(); t.deepEqual(actualRef, "refs/pull/2/merge"); - t.true(callback.calledOnceWith(tmpDir, "refs/pull/1/merge")); - t.true(callback.calledOnceWith(tmpDir, "HEAD")); + // getCommitOid shouldn't be called, because the ref should be taken from the input + t.is(callback.callCount, 0); }); }, );