Skip to content

Commit 074d6a0

Browse files
committed
mostly working e2e tests
1 parent 4a8401a commit 074d6a0

File tree

3 files changed

+245
-280
lines changed

3 files changed

+245
-280
lines changed
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
tests:
2+
# - name: with-js-config-object-style
3+
# config: |
4+
# /** @type {import('next').NextConfig} */
5+
# const nextConfig = {
6+
# reactStrictMode: true,
7+
# async headers() {
8+
# return [
9+
# {
10+
# source: '/:path*',
11+
# headers: [
12+
# {
13+
# key: 'x-custom-header',
14+
# value: 'js-config-value',
15+
# },
16+
# {
17+
# key: 'x-config-type',
18+
# value: 'object',
19+
# },
20+
# ],
21+
# },
22+
# ];
23+
# },
24+
# };
25+
26+
# module.exports = nextConfig;
27+
# file: next.config.js
28+
# - name: with-js-config-function-style
29+
# config: |
30+
# /** @type {import('next').NextConfig} */
31+
# const nextConfig = (phase, { defaultConfig }) => {
32+
# return {
33+
# reactStrictMode: true,
34+
# async headers() {
35+
# return [
36+
# {
37+
# source: '/:path*',
38+
# headers: [
39+
# {
40+
# key: 'x-custom-header',
41+
# value: 'js-config-value',
42+
# },
43+
# {
44+
# key: 'x-config-type',
45+
# value: 'function',
46+
# },
47+
# ],
48+
# },
49+
# ];
50+
# }
51+
# };
52+
# };
53+
54+
# module.exports = nextConfig;
55+
# file: next.config.js
56+
- name: with-js-async-function
57+
config: |
58+
// @ts-check
59+
60+
module.exports = async (phase, { defaultConfig }) => {
61+
/**
62+
* @type {import('next').NextConfig}
63+
*/
64+
const nextConfig = {
65+
async headers() {
66+
return [
67+
{
68+
source: '/:path*',
69+
headers: [
70+
{
71+
key: 'x-custom-header',
72+
value: 'js-config-value',
73+
},
74+
{
75+
key: 'x-config-type',
76+
value: 'function',
77+
},
78+
],
79+
},
80+
];
81+
}
82+
}
83+
return nextConfig
84+
}
85+
file: next.config.js
86+
# - name: with-ts-config
87+
# config: |
88+
# import type { NextConfig } from 'next'
89+
90+
# const nextConfig: NextConfig = {
91+
# async headers() {
92+
# return [
93+
# {
94+
# source: '/:path*',
95+
# headers: [
96+
# {
97+
# key: 'x-custom-header',
98+
# value: 'ts-config-value',
99+
# }
100+
# ],
101+
# },
102+
# ];
103+
# }
104+
# }
105+
106+
# export default nextConfig
107+
# file: next.config.ts
108+
# - name: with-ecmascript-modules
109+
# config: |
110+
# // @ts-check
111+
112+
# /**
113+
# * @type {import('next').NextConfig}
114+
# */
115+
# const nextConfig = {
116+
# /* config options here */
117+
# async headers() {
118+
# return [
119+
# {
120+
# source: '/:path*',
121+
# headers: [
122+
# {
123+
# key: 'x-custom-header',
124+
# value: 'mjs-config-value',
125+
# },
126+
# ],
127+
# },
128+
# ];
129+
# }
130+
# }
131+
132+
# export default nextConfig
133+
# file: next.config.mjs
134+
# - name: with-empty-config
135+
# config: |
136+
# // @ts-check
137+
138+
# /** @type {import('next').NextConfig} */
139+
# const nextConfig = {
140+
# /* config options here */
141+
# }
142+
143+
# module.exports = nextConfig
144+
# file: next.config.js

packages/@apphosting/adapter-nextjs/e2e/config-override.spec.ts

Lines changed: 78 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,23 @@ if (!runId) {
1717
throw new Error("RUN_ID environment variable expected");
1818
}
1919

20+
const compiledFilesPath = posix.join(
21+
process.cwd(),
22+
"e2e",
23+
"runs",
24+
runId,
25+
".next",
26+
"standalone",
27+
".next",
28+
);
29+
2030
describe("next.config override", () => {
21-
it("should have images optimization disabled", async () => {
22-
const serverFiles = await fsExtra.readJson(
23-
`${process.cwd()}/e2e/runs/${runId}/.next/standalone/.next/required-server-files.json`,
24-
);
25-
console.log(`serverFiles: ${JSON.stringify(serverFiles)}`);
31+
it("should have images optimization disabled", async function () {
32+
if (scenario.includes("with-empty-config")) {
33+
this.skip();
34+
}
35+
36+
const serverFiles = await fsExtra.readJson(`${compiledFilesPath}/required-server-files.json`);
2637
const config = serverFiles.config;
2738

2839
// Verify that images.unoptimized is set to true
@@ -34,158 +45,66 @@ describe("next.config override", () => {
3445
);
3546
});
3647

37-
// it("should preserve user config settings", async () => {
38-
// // This test checks if the user's original config settings are preserved
39-
// // We'll check for the custom header that was set in the next.config
40-
// const response = await fetch(posix.join(host, "/"));
41-
// assert.ok(response.ok);
42-
43-
// // Check for the custom header that was set in the next.config
44-
// if (scenario.includes("with-js-config")) {
45-
// assert.equal(response.headers.get("x-custom-header") ?? "", "js-config-value");
46-
// } else if (scenario.includes("with-ts-config")) {
47-
// assert.equal(response.headers.get("x-custom-header") ?? "", "ts-config-value");
48-
// } else if (scenario.includes("with-mjs-config")) {
49-
// assert.equal(response.headers.get("x-custom-header") ?? "", "mjs-config-value");
50-
// } else if (scenario.includes("with-complex-config")) {
51-
// assert.equal(response.headers.get("x-custom-header") ?? "", "complex-config-value");
52-
// }
53-
// });
54-
55-
// it("should handle function-style config correctly", async () => {
56-
// // Only run this test for scenarios with function-style config
57-
// if (!scenario.includes("function-style")) {
58-
// this.skip();
59-
// return;
60-
// }
61-
62-
// // Check for the custom header that indicates function-style config was processed correctly
63-
// const response = await fetch(posix.join(host, "/"));
64-
// assert.ok(response.ok);
65-
// assert.equal(response.headers.get("x-config-type") ?? "", "function");
66-
// });
67-
68-
// it("should handle object-style config correctly", async () => {
69-
// // Only run this test for scenarios with object-style config
70-
// if (
71-
// !scenario.includes("object-style") &&
72-
// !scenario.includes("with-complex-config") &&
73-
// !scenario.includes("with-empty-config")
74-
// ) {
75-
// this.skip();
76-
// return;
77-
// }
78-
79-
// // Check for the custom header that indicates object-style config was processed correctly
80-
// const response = await fetch(posix.join(host, "/"));
81-
// assert.ok(response.ok);
82-
83-
// // Empty config doesn't set this header
84-
// if (!scenario.includes("with-empty-config")) {
85-
// assert.equal(response.headers.get("x-config-type") ?? "", "object");
86-
// }
87-
// });
88-
89-
// it("should handle empty config correctly", async () => {
90-
// // Only run this test for the empty config scenario
91-
// if (!scenario.includes("with-empty-config")) {
92-
// this.skip();
93-
// return;
94-
// }
95-
96-
// // Just check that the page loads successfully
97-
// const response = await fetch(posix.join(host, "/"));
98-
// assert.ok(response.ok);
99-
// });
100-
101-
// it("should verify original config file was preserved", async () => {
102-
// // This test verifies that the original config file was preserved
103-
// // We'll check the file system to make sure the original config file exists
104-
// let originalConfigExists = false;
105-
106-
// if (scenario.includes("with-js-config")) {
107-
// originalConfigExists = await fsExtra.pathExists("next.config.original.js");
108-
// } else if (scenario.includes("with-ts-config")) {
109-
// originalConfigExists = await fsExtra.pathExists("next.config.original.ts");
110-
// } else if (scenario.includes("with-mjs-config")) {
111-
// originalConfigExists = await fsExtra.pathExists("next.config.original.mjs");
112-
// } else if (
113-
// scenario.includes("with-empty-config") ||
114-
// scenario.includes("with-complex-config") ||
115-
// scenario.includes("with-error-handling")
116-
// ) {
117-
// originalConfigExists = await fsExtra.pathExists("next.config.original.js");
118-
// }
119-
120-
// assert.ok(originalConfigExists, "Original config file should be preserved");
121-
// });
122-
123-
// it("should handle error gracefully when config file has syntax errors", async () => {
124-
// // Only run this test for the error handling scenario
125-
// if (!scenario.includes("with-error-handling")) {
126-
// this.skip();
127-
// return;
128-
// }
129-
130-
// // The build should have succeeded despite the invalid config file
131-
// // because we started with a valid config
132-
// const response = await fetch(posix.join(host, "/"));
133-
// assert.ok(response.ok);
134-
135-
// // Check if the invalid config file exists
136-
// const invalidConfigExists = await fsExtra.pathExists("next.config.invalid.js");
137-
// assert.ok(invalidConfigExists, "Invalid config file should exist");
138-
// });
139-
140-
// it("should verify the generated config file has the correct format", async () => {
141-
// // Skip for error handling scenario
142-
// if (scenario.includes("with-error-handling")) {
143-
// this.skip();
144-
// return;
145-
// }
146-
147-
// let configPath = "";
148-
149-
// if (scenario.includes("with-js-config")) {
150-
// configPath = "next.config.js";
151-
// } else if (scenario.includes("with-ts-config")) {
152-
// configPath = "next.config.ts";
153-
// } else if (scenario.includes("with-mjs-config")) {
154-
// configPath = "next.config.mjs";
155-
// } else if (scenario.includes("with-empty-config") || scenario.includes("with-complex-config")) {
156-
// configPath = "next.config.js";
157-
// }
158-
159-
// // Check if the generated config file exists
160-
// const configExists = await fsExtra.pathExists(configPath);
161-
// assert.ok(configExists, "Generated config file should exist");
162-
163-
// // Read the config file content
164-
// const configContent = await fsExtra.readFile(configPath, "utf-8");
165-
166-
// // Verify that the config file contains the unoptimized: true setting
167-
// assert.ok(configContent.includes("unoptimized: true"), "Config should have unoptimized: true");
168-
169-
// // Verify that the config file imports the original config
170-
// if (
171-
// scenario.includes("with-js-config") ||
172-
// scenario.includes("with-empty-config") ||
173-
// scenario.includes("with-complex-config")
174-
// ) {
175-
// assert.ok(
176-
// configContent.includes("require('./next.config.original.js')"),
177-
// "Config should import the original JS config",
178-
// );
179-
// } else if (scenario.includes("with-ts-config")) {
180-
// assert.ok(
181-
// configContent.includes("import originalConfig from './next.config.original'"),
182-
// "Config should import the original TS config",
183-
// );
184-
// } else if (scenario.includes("with-mjs-config")) {
185-
// assert.ok(
186-
// configContent.includes("import originalConfig from './next.config.original.mjs'"),
187-
// "Config should import the original MJS config",
188-
// );
189-
// }
190-
// });
48+
it("should preserve other user set next configs", async function () {
49+
if (scenario.includes("with-empty-config")) {
50+
this.skip();
51+
}
52+
53+
// This test checks if the user's original config settings are preserved
54+
// We'll check for the custom header that was set in the next.config
55+
const response = await fetch(posix.join(host, "/"));
56+
57+
// Log all headers individually for debugging
58+
console.log("Response headers:");
59+
response.headers.forEach((value, key) => {
60+
console.log(` ${key}: ${value}`);
61+
});
62+
63+
assert.ok(response.ok);
64+
65+
// Check for the custom header that was set in the next.config
66+
const customHeader = response.headers.get("x-custom-header") ?? "";
67+
const validValues = [
68+
"js-config-value",
69+
"ts-config-value",
70+
"mjs-config-value",
71+
"complex-config-value",
72+
];
73+
assert.ok(
74+
validValues.includes(customHeader),
75+
`Expected header to be one of ${validValues.join(", ")} but got "${customHeader}"`,
76+
);
77+
});
78+
79+
it("should handle function-style config correctly", async function () {
80+
// Only run this test for scenarios with function-style config
81+
if (!scenario.includes("function-style")) {
82+
this.skip();
83+
}
84+
85+
// Check for the custom header that indicates function-style config was processed correctly
86+
const response = await fetch(posix.join(host, "/"));
87+
assert.ok(response.ok);
88+
assert.equal(response.headers.get("x-config-type") ?? "", "function");
89+
});
90+
91+
it("should handle object-style config correctly", async function () {
92+
// Only run this test for scenarios with object-style config
93+
if (
94+
!scenario.includes("object-style") &&
95+
!scenario.includes("with-complex-config") &&
96+
!scenario.includes("with-empty-config")
97+
) {
98+
this.skip();
99+
}
100+
101+
// Check for the custom header that indicates object-style config was processed correctly
102+
const response = await fetch(posix.join(host, "/"));
103+
assert.ok(response.ok);
104+
105+
// Empty config doesn't set this header
106+
if (!scenario.includes("with-empty-config")) {
107+
assert.equal(response.headers.get("x-config-type") ?? "", "object");
108+
}
109+
});
191110
});

0 commit comments

Comments
 (0)