Skip to content

Commit

Permalink
get test to be reliable
Browse files Browse the repository at this point in the history
  • Loading branch information
james-elicx committed Feb 11, 2025
1 parent a9d38f5 commit 21c85f5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 16 deletions.
5 changes: 0 additions & 5 deletions packages/cloudflare/src/api/internal/manifest.ts

This file was deleted.

11 changes: 3 additions & 8 deletions packages/cloudflare/src/api/memory-queue.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import { beforeAll, describe, expect, it, vi } from "vitest";

import cache from "./memory-queue";

vi.mock("./internal/manifest.js", () => ({
getPrerenderManifest: () => ({ preview: { previewModeId: "id" } }),
}));
vi.mock("./.next/prerender-manifest.json", () => Promise.resolve({ preview: { previewModeId: "id" } }));

const defaultOpts = {
MessageBody: { host: "test.local", url: "/test" },
Expand All @@ -30,12 +28,9 @@ describe("MemoryQueue", () => {
await Promise.all(secondBatch);
expect(globalThis.internalFetch).toHaveBeenCalledTimes(2);

const thirdBatch = [
cache.send(defaultOpts),
cache.send({ ...defaultOpts, MessageGroupId: generateMessageGroupId("/other") }),
];
const thirdBatch = [cache.send({ ...defaultOpts, MessageGroupId: generateMessageGroupId("/other") })];
vi.advanceTimersByTime(1);
await Promise.all(thirdBatch);
expect(globalThis.internalFetch).toHaveBeenCalledTimes(4);
expect(globalThis.internalFetch).toHaveBeenCalledTimes(3);
});
});
6 changes: 3 additions & 3 deletions packages/cloudflare/src/api/memory-queue.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import logger from "@opennextjs/aws/logger.js";
import type { Queue, QueueMessage } from "@opennextjs/aws/types/overrides.js";

import { getPrerenderManifest } from "./internal/manifest.js";

/**
* The Memory Queue offers basic ISR revalidation by directly requesting a revalidation of a route.
*
Expand All @@ -23,9 +21,11 @@ class MemoryQueue implements Queue {
);

try {
const manifest = await getPrerenderManifest();
const protocol = host.includes("localhost") ? "http" : "https";

// TODO: Drop the import - https://github.com/opennextjs/opennextjs-cloudflare/issues/361
// @ts-ignore
const manifest = await import("./.next/prerender-manifest.json");
await globalThis.internalFetch(`${protocol}://${host}${url}`, {
method: "HEAD",
headers: {
Expand Down

0 comments on commit 21c85f5

Please sign in to comment.