|
1 | 1 | import * as assert from "assert"; |
2 | 2 | import { posix } from "path"; |
| 3 | +import fsExtra from "fs-extra"; |
3 | 4 |
|
4 | 5 | export const host = process.env.HOST; |
5 | | - |
6 | 6 | if (!host) { |
7 | 7 | throw new Error("HOST environment variable expected"); |
8 | 8 | } |
9 | 9 |
|
| 10 | +let adapterVersion: string; |
| 11 | +before(() => { |
| 12 | + const packageJson = fsExtra.readJSONSync("package.json"); |
| 13 | + adapterVersion = packageJson.version; |
| 14 | + if (!adapterVersion) throw new Error("couldn't parse package.json version"); |
| 15 | +}); |
| 16 | + |
10 | 17 | describe("app", () => { |
11 | 18 | it("/", async () => { |
12 | 19 | const response = await fetch(host); |
13 | 20 | assert.ok(response.ok); |
14 | 21 | assert.equal(response.headers.get("content-type")?.toLowerCase(), "text/html; charset=utf-8"); |
15 | | - assert.equal( |
16 | | - response.headers.get("cache-control"), |
17 | | - "s-maxage=31536000, stale-while-revalidate", |
18 | | - ); |
| 22 | + assert.equal(response.headers.get("cache-control"), "s-maxage=31536000, "); |
19 | 23 | }); |
20 | 24 |
|
21 | 25 | it("/ssg", async () => { |
22 | 26 | const response = await fetch(posix.join(host, "ssg")); |
23 | 27 | assert.ok(response.ok); |
24 | 28 | assert.equal(response.headers.get("content-type")?.toLowerCase(), "text/html; charset=utf-8"); |
25 | | - assert.equal( |
26 | | - response.headers.get("cache-control"), |
27 | | - "s-maxage=31536000, stale-while-revalidate", |
28 | | - ); |
| 29 | + assert.equal(response.headers.get("cache-control"), "s-maxage=31536000, "); |
29 | 30 | const text = await response.text(); |
30 | 31 | assert.ok(text.includes("SSG")); |
31 | 32 | assert.ok(text.includes("Generated")); |
@@ -80,10 +81,7 @@ describe("app", () => { |
80 | 81 | const response = await fetch(posix.join(host, "isr", "demand")); |
81 | 82 | assert.ok(response.ok); |
82 | 83 | assert.equal(response.headers.get("content-type")?.toLowerCase(), "text/html; charset=utf-8"); |
83 | | - assert.equal( |
84 | | - response.headers.get("cache-control"), |
85 | | - "s-maxage=31536000, stale-while-revalidate", |
86 | | - ); |
| 84 | + assert.equal(response.headers.get("cache-control"), "s-maxage=31536000, "); |
87 | 85 | const text = await response.text(); |
88 | 86 | assert.ok(text.includes("A cached page")); |
89 | 87 | assert.ok(text.includes("Generated")); |
@@ -123,4 +121,30 @@ describe("app", () => { |
123 | 121 | "private, no-cache, no-store, max-age=0, must-revalidate", |
124 | 122 | ); |
125 | 123 | }); |
| 124 | + |
| 125 | + it("should have x-fah-adapter header and no x-fah-middleware header on all routes", async () => { |
| 126 | + const routes = [ |
| 127 | + "/", |
| 128 | + "/ssg", |
| 129 | + "/ssr", |
| 130 | + "/ssr/streaming", |
| 131 | + "/isr/time", |
| 132 | + "/isr/demand", |
| 133 | + "/nonexistent-route", |
| 134 | + ]; |
| 135 | + |
| 136 | + for (const route of routes) { |
| 137 | + const response = await fetch(posix.join(host, route)); |
| 138 | + assert.equal( |
| 139 | + response.headers.get("x-fah-adapter"), |
| 140 | + `nextjs-${adapterVersion}`, |
| 141 | + `Route ${route} missing x-fah-adapter header`, |
| 142 | + ); |
| 143 | + assert.equal( |
| 144 | + response.headers.get("x-fah-middleware"), |
| 145 | + null, |
| 146 | + `Route ${route} should not have x-fah-middleware header`, |
| 147 | + ); |
| 148 | + } |
| 149 | + }); |
126 | 150 | }); |
0 commit comments