Skip to content

Commit a1794a0

Browse files
committed
Fix mockGetReleaseByTag usage
1 parent ac44fd0 commit a1794a0

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

‎src/start-proxy.test.ts‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,10 @@ function mockGetReleaseByTag(expectedTag?: string, assets?: ReleaseAssets) {
729729
}
730730
});
731731

732-
return mockGetApiClient({ repos: { getReleaseByTag } });
732+
return {
733+
getReleaseByTag,
734+
getApiClient: mockGetApiClient({ repos: { getReleaseByTag } }),
735+
};
733736
}
734737

735738
function mockOfflineFeatures(tempDir: string, logger: Logger) {
@@ -833,7 +836,7 @@ test.serial(
833836
sinon.stub(actionsUtil, "isRunningLocalAction").returns(true);
834837

835838
for (const assets of testAssets) {
836-
const stub = mockGetReleaseByTag(defaults.bundleVersion, assets);
839+
const stubs = mockGetReleaseByTag(defaults.bundleVersion, assets);
837840
const info = await startProxyExports.getDownloadUrl(
838841
state,
839842
SAMPLE_DOTCOM_API_DETAILS,
@@ -848,7 +851,9 @@ test.serial(
848851
),
849852
);
850853

851-
stub.restore();
854+
// mockGetReleaseByTag stubs the global getApiClient; since we are calling
855+
// that in a loop, we need to manually restore it here
856+
stubs.getApiClient.restore();
852857
}
853858
});
854859
},
@@ -864,7 +869,7 @@ test.serial("getDownloadUrl returns matching release asset", async (t) => {
864869
url: "url-we-want",
865870
},
866871
];
867-
const getReleaseByTag = mockGetReleaseByTag(defaults.bundleVersion, assets);
872+
const stubs = mockGetReleaseByTag(defaults.bundleVersion, assets);
868873

869874
await withTmpDir(async (tempDir) => {
870875
state.env.set(ActionsEnvVars.RUNNER_TEMP, tempDir);
@@ -879,7 +884,7 @@ test.serial("getDownloadUrl returns matching release asset", async (t) => {
879884
SAMPLE_DOTCOM_API_DETAILS,
880885
);
881886

882-
t.is(getReleaseByTag.callCount, 1);
887+
t.is(stubs.getReleaseByTag.callCount, 1);
883888

884889
t.is(info.version, defaults.cliVersion);
885890
t.is(info.url, "url-we-want");
@@ -1036,7 +1041,7 @@ test.serial(
10361041
const logger = new RecordingLogger();
10371042
const state = initAllState({ logger });
10381043
const downloadUrl = "url-we-want";
1039-
const getApiClient = mockGetReleaseByTag(defaults.bundleVersion, [
1044+
const stubs = mockGetReleaseByTag(defaults.bundleVersion, [
10401045
{
10411046
name: startProxyExports.getProxyPackage(getTestPlatform(state)),
10421047
url: downloadUrl,
@@ -1070,7 +1075,7 @@ test.serial(
10701075
SAMPLE_DOTCOM_API_DETAILS,
10711076
);
10721077

1073-
t.is(getApiClient.callCount, 1);
1078+
t.is(stubs.getReleaseByTag.callCount, 1);
10741079
t.assert(find.calledOnce);
10751080
t.assert(getAuthorizationHeaderFor.calledOnce);
10761081

0 commit comments

Comments
 (0)