Skip to content

Commit 70e1bd8

Browse files
committed
add additional tests and fix lint errors
1 parent 1e98f4f commit 70e1bd8

File tree

2 files changed

+90
-2
lines changed

2 files changed

+90
-2
lines changed

packages/@apphosting/adapter-nextjs/e2e/config-override-test-cases.yaml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,61 @@ tests:
142142
143143
module.exports = nextConfig
144144
file: next.config.js
145+
- name: with-images-unoptimized-false
146+
config: |
147+
/** @type {import('next').NextConfig} */
148+
const nextConfig = {
149+
reactStrictMode: true,
150+
images: {
151+
unoptimized: false,
152+
},
153+
async headers() {
154+
return [
155+
{
156+
source: '/:path*',
157+
headers: [
158+
{
159+
key: 'x-custom-header',
160+
value: 'js-config-value',
161+
},
162+
{
163+
key: 'x-config-type',
164+
value: 'object',
165+
},
166+
],
167+
},
168+
];
169+
},
170+
};
171+
172+
module.exports = nextConfig;
173+
file: next.config.js
174+
- name: with-custom-image-loader
175+
config: |
176+
/** @type {import('next').NextConfig} */
177+
const nextConfig = {
178+
images: {
179+
loader: "akamai",
180+
path: "",
181+
},
182+
async headers() {
183+
return [
184+
{
185+
source: '/:path*',
186+
headers: [
187+
{
188+
key: 'x-custom-header',
189+
value: 'js-config-value',
190+
},
191+
{
192+
key: 'x-config-type',
193+
value: 'object',
194+
},
195+
],
196+
},
197+
];
198+
},
199+
};
200+
201+
module.exports = nextConfig;
202+
file: next.config.js

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

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,20 @@ const compiledFilesPath = posix.join(
2727
".next",
2828
);
2929

30+
const requiredServerFilePath = posix.join(compiledFilesPath, "required-server-files.json");
31+
3032
describe("next.config override", () => {
3133
it("should have images optimization disabled", async function () {
32-
if (scenario.includes("with-empty-config")) {
34+
if (
35+
scenario.includes("with-empty-config") ||
36+
scenario.includes("with-images-unoptimized-false") ||
37+
scenario.includes("with-custom-image-loader")
38+
) {
39+
// eslint-disable-next-line @typescript-eslint/no-invalid-this
3340
this.skip();
3441
}
3542

36-
const serverFiles = await fsExtra.readJson(`${compiledFilesPath}/required-server-files.json`);
43+
const serverFiles = await fsExtra.readJson(requiredServerFilePath);
3744
const config = serverFiles.config;
3845

3946
// Verify that images.unoptimized is set to true
@@ -47,6 +54,7 @@ describe("next.config override", () => {
4754

4855
it("should preserve other user set next configs", async function () {
4956
if (scenario.includes("with-empty-config")) {
57+
// eslint-disable-next-line @typescript-eslint/no-invalid-this
5058
this.skip();
5159
}
5260

@@ -68,6 +76,7 @@ describe("next.config override", () => {
6876
it("should handle function-style config correctly", async function () {
6977
// Only run this test for scenarios with function-style config
7078
if (!scenario.includes("function-style")) {
79+
// eslint-disable-next-line @typescript-eslint/no-invalid-this
7180
this.skip();
7281
}
7382

@@ -80,6 +89,7 @@ describe("next.config override", () => {
8089
it("should handle object-style config correctly", async function () {
8190
// Only run this test for scenarios with object-style config
8291
if (!scenario.includes("object-style") && !scenario.includes("with-empty-config")) {
92+
// eslint-disable-next-line @typescript-eslint/no-invalid-this
8393
this.skip();
8494
}
8595

@@ -92,4 +102,24 @@ describe("next.config override", () => {
92102
assert.equal(response.headers.get("x-config-type") ?? "", "object");
93103
}
94104
});
105+
106+
it("should not override images.unoptimized if user explicitly defines configs", async function () {
107+
if (
108+
!scenario.includes("with-images-unoptimized-false") &&
109+
!scenario.includes("with-custom-image-loader")
110+
) {
111+
// eslint-disable-next-line @typescript-eslint/no-invalid-this
112+
this.skip();
113+
}
114+
115+
const serverFiles = await fsExtra.readJson(requiredServerFilePath);
116+
const config = serverFiles.config;
117+
118+
assert.ok(config.images, "Config should have images property");
119+
assert.strictEqual(
120+
config.images.unoptimized,
121+
false,
122+
"Images should have unoptimized set to false",
123+
);
124+
});
95125
});

0 commit comments

Comments
 (0)