Skip to content

Commit 4710f0a

Browse files
author
Nicolas Dorseuil
committed
fix unit test
1 parent 373547b commit 4710f0a

File tree

2 files changed

+45
-24
lines changed

2 files changed

+45
-24
lines changed

packages/tests-unit/tests/adapters/cache.test.ts

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,12 @@ describe("CacheHandler", () => {
364364
});
365365

366366
expect(incrementalCache.set).toHaveBeenCalledWith(
367-
"key",
367+
{
368+
baseKey: "key",
369+
cacheType: "cache",
370+
buildId: "undefined-build-id",
371+
},
368372
{ type: "route", body: "{}", meta: { status: 200, headers: {} } },
369-
"cache",
370373
);
371374
});
372375

@@ -381,13 +384,16 @@ describe("CacheHandler", () => {
381384
});
382385

383386
expect(incrementalCache.set).toHaveBeenCalledWith(
384-
"key",
387+
{
388+
baseKey: "key",
389+
cacheType: "cache",
390+
buildId: "undefined-build-id",
391+
},
385392
{
386393
type: "route",
387394
body: Buffer.from("{}").toString("base64"),
388395
meta: { status: 200, headers: { "content-type": "image/png" } },
389396
},
390-
"cache",
391397
);
392398
});
393399

@@ -401,13 +407,16 @@ describe("CacheHandler", () => {
401407
});
402408

403409
expect(incrementalCache.set).toHaveBeenCalledWith(
404-
"key",
410+
{
411+
baseKey: "key",
412+
cacheType: "cache",
413+
buildId: "undefined-build-id",
414+
},
405415
{
406416
type: "page",
407417
html: "<html></html>",
408418
json: {},
409419
},
410-
"cache",
411420
);
412421
});
413422

@@ -421,14 +430,17 @@ describe("CacheHandler", () => {
421430
});
422431

423432
expect(incrementalCache.set).toHaveBeenCalledWith(
424-
"key",
433+
{
434+
baseKey: "key",
435+
cacheType: "cache",
436+
buildId: "undefined-build-id",
437+
},
425438
{
426439
type: "app",
427440
html: "<html></html>",
428441
rsc: "rsc",
429442
meta: { status: 200, headers: {} },
430443
},
431-
"cache",
432444
);
433445
});
434446

@@ -442,14 +454,17 @@ describe("CacheHandler", () => {
442454
});
443455

444456
expect(incrementalCache.set).toHaveBeenCalledWith(
445-
"key",
457+
{
458+
baseKey: "key",
459+
cacheType: "cache",
460+
buildId: "undefined-build-id",
461+
},
446462
{
447463
type: "app",
448464
html: "<html></html>",
449465
rsc: "rsc",
450466
meta: { status: 200, headers: {} },
451467
},
452-
"cache",
453468
);
454469
});
455470

@@ -467,7 +482,11 @@ describe("CacheHandler", () => {
467482
});
468483

469484
expect(incrementalCache.set).toHaveBeenCalledWith(
470-
"key",
485+
{
486+
baseKey: "key",
487+
cacheType: "fetch",
488+
buildId: "undefined-build-id",
489+
},
471490
{
472491
kind: "FETCH",
473492
data: {
@@ -479,20 +498,22 @@ describe("CacheHandler", () => {
479498
},
480499
revalidate: 60,
481500
},
482-
"fetch",
483501
);
484502
});
485503

486504
it("Should set cache when for REDIRECT", async () => {
487505
await cache.set("key", { kind: "REDIRECT", props: {} });
488506

489507
expect(incrementalCache.set).toHaveBeenCalledWith(
490-
"key",
508+
{
509+
baseKey: "key",
510+
cacheType: "cache",
511+
buildId: "undefined-build-id",
512+
},
491513
{
492514
type: "redirect",
493515
props: {},
494516
},
495-
"cache",
496517
);
497518
});
498519

packages/tests-unit/tests/utils/cache.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,41 +22,41 @@ describe("createCacheKey", () => {
2222
globalThis.openNextConfig = originalGlobalThis.openNextConfig;
2323
});
2424

25-
test("prepends build ID for non-data cache entries", () => {
25+
test("have a defined build id for non-data cache entries", () => {
2626
process.env.NEXT_BUILD_ID = "test-build-id";
2727
const key = "test-key";
2828

29-
const result = createCacheKey(key, false);
29+
const result = createCacheKey({ key, type: "cache" });
3030

31-
expect(result).toBe("test-build-id/test-key");
31+
expect(result.buildId).toBe("test-build-id");
3232
});
3333

34-
test("prepends build ID for data cache when persistentDataCache is not enabled", () => {
34+
test("have a defined build id for data cache when persistentDataCache is not enabled", () => {
3535
process.env.NEXT_BUILD_ID = "test-build-id";
3636
globalThis.openNextConfig.dangerous.persistentDataCache = false;
3737
const key = "test-key";
3838

39-
const result = createCacheKey(key, true);
39+
const result = createCacheKey({ key, type: "fetch" });
4040

41-
expect(result).toBe("test-build-id/test-key");
41+
expect(result.buildId).toBe("test-build-id");
4242
});
4343

4444
test("does not prepend build ID for data cache when persistentDataCache is enabled", () => {
4545
process.env.NEXT_BUILD_ID = "test-build-id";
4646
globalThis.openNextConfig.dangerous.persistentDataCache = true;
4747
const key = "test-key";
4848

49-
const result = createCacheKey(key, true);
49+
const result = createCacheKey({ key, type: "fetch" });
5050

51-
expect(result).toBe("test-key");
51+
expect(result.buildId).toBeUndefined();
5252
});
5353

5454
test("handles missing build ID", () => {
5555
process.env.NEXT_BUILD_ID = undefined;
5656
const key = "test-key";
5757

58-
const result = createCacheKey(key, false);
58+
const result = createCacheKey({ key, type: "fetch" });
5959

60-
expect(result).toBe("test-key");
60+
expect(result.buildId).toBeUndefined();
6161
});
6262
});

0 commit comments

Comments
 (0)