Skip to content

Commit dc5ea69

Browse files
CopilotoBusk
andcommitted
Fix flaky test: Add retry logic to network-dependent test
Co-authored-by: oBusk <13413409+oBusk@users.noreply.github.com>
1 parent 68840a0 commit dc5ea69

2 files changed

Lines changed: 25 additions & 6 deletions

File tree

next-env.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// <reference types="next" />
22
/// <reference types="next/image-types/global" />
3-
import "./.next/dev/types/routes.d.ts";
3+
import "./.next/types/routes.d.ts";
44

55
// NOTE: This file should not be edited
66
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.

src/lib/destination/index.test.ts

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,33 @@ describe("destination()", () => {
2525
let specs: ExpectedResults;
2626

2727
beforeAll(async () => {
28+
// Retry logic for fetching manifests from npm registry
29+
const fetchWithRetry = async <T>(
30+
fn: () => Promise<T>,
31+
retries = 3,
32+
delay = 1000,
33+
): Promise<T> => {
34+
for (let i = 0; i < retries; i++) {
35+
try {
36+
return await fn();
37+
} catch (error) {
38+
if (i === retries - 1) throw error;
39+
await new Promise((resolve) => setTimeout(resolve, delay));
40+
}
41+
}
42+
throw new Error("Failed after retries");
43+
};
44+
2845
const manifests: ExpectedResults<
2946
pacote.AbbreviatedManifest & pacote.ManifestResult
3047
> = Object.freeze({
31-
"^2.1": await pacote.manifest(`chalk@^2.1`),
32-
"~2.1": await pacote.manifest(`chalk@~2.1`),
33-
latest: await pacote.manifest("chalk"),
34-
"^3.0.0-beta": await pacote.manifest("chalk@^3.0.0-beta"),
35-
next: await pacote.manifest("chalk@next"),
48+
"^2.1": await fetchWithRetry(() => pacote.manifest(`chalk@^2.1`)),
49+
"~2.1": await fetchWithRetry(() => pacote.manifest(`chalk@~2.1`)),
50+
latest: await fetchWithRetry(() => pacote.manifest("chalk")),
51+
"^3.0.0-beta": await fetchWithRetry(() =>
52+
pacote.manifest("chalk@^3.0.0-beta"),
53+
),
54+
next: await fetchWithRetry(() => pacote.manifest("chalk@next")),
3655
});
3756

3857
const versions: ExpectedResults = Object.freeze({

0 commit comments

Comments
 (0)