@@ -17,12 +17,23 @@ if (!runId) {
17
17
throw new Error ( "RUN_ID environment variable expected" ) ;
18
18
}
19
19
20
+ const compiledFilesPath = posix . join (
21
+ process . cwd ( ) ,
22
+ "e2e" ,
23
+ "runs" ,
24
+ runId ,
25
+ ".next" ,
26
+ "standalone" ,
27
+ ".next" ,
28
+ ) ;
29
+
20
30
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` ) ;
26
37
const config = serverFiles . config ;
27
38
28
39
// Verify that images.unoptimized is set to true
@@ -34,158 +45,66 @@ describe("next.config override", () => {
34
45
) ;
35
46
} ) ;
36
47
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
+ } ) ;
191
110
} ) ;
0 commit comments