@@ -172,20 +172,32 @@ describe("next config overrides", () => {
172172 ...config,
173173 images: {
174174 ...(config.images || {}),
175- ...(config.images?.unoptimized === undefined && config.images?.loader === undefined
176- ? { unoptimized: true }
175+ ...(config.images?.unoptimized === undefined && config.images?.loader === undefined
176+ ? { unoptimized: true }
177177 : {}),
178178 },
179179 });
180180
181- const config = typeof originalConfig === 'function'
181+ const config = typeof originalConfig === 'function'
182182 ? async (...args) => {
183183 const resolvedConfig = await originalConfig(...args);
184184 return fahOptimizedConfig(resolvedConfig);
185185 }
186186 : fahOptimizedConfig(originalConfig);
187187 ` ;
188188
189+ const defaultNextConfig = `
190+ // @ts-nocheck
191+
192+ /** @type {import('next').NextConfig} */
193+ const nextConfig = {
194+ images: {
195+ unoptimized: true,
196+ }
197+ }
198+
199+ module.exports = nextConfig
200+ `
189201 beforeEach ( ( ) => {
190202 tmpDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "test-overrides" ) ) ;
191203 } ) ;
@@ -194,12 +206,12 @@ describe("next config overrides", () => {
194206 const { overrideNextConfig } = await importOverrides ;
195207 const originalConfig = `
196208 // @ts-check
197-
209+
198210 /** @type {import('next').NextConfig} */
199211 const nextConfig = {
200212 /* config options here */
201213 }
202-
214+
203215 module.exports = nextConfig
204216 ` ;
205217
@@ -213,7 +225,7 @@ describe("next config overrides", () => {
213225 normalizeWhitespace ( `
214226 // @ts-nocheck
215227 const originalConfig = require('./next.config.original.js');
216-
228+
217229 ${ nextConfigOverrideBody }
218230
219231 module.exports = config;
@@ -225,14 +237,14 @@ describe("next config overrides", () => {
225237 const { overrideNextConfig } = await importOverrides ;
226238 const originalConfig = `
227239 // @ts-check
228-
240+
229241 /**
230242 * @type {import('next').NextConfig}
231243 */
232244 const nextConfig = {
233245 /* config options here */
234246 }
235-
247+
236248 export default nextConfig
237249 ` ;
238250
@@ -257,7 +269,7 @@ describe("next config overrides", () => {
257269 const { overrideNextConfig } = await importOverrides ;
258270 const originalConfig = `
259271 // @ts-check
260-
272+
261273 export default (phase, { defaultConfig }) => {
262274 /**
263275 * @type {import('next').NextConfig}
@@ -280,7 +292,7 @@ describe("next config overrides", () => {
280292 import originalConfig from './next.config.original.mjs';
281293
282294 ${ nextConfigOverrideBody }
283-
295+
284296 export default config;
285297 ` ) ,
286298 ) ;
@@ -290,11 +302,11 @@ describe("next config overrides", () => {
290302 const { overrideNextConfig } = await importOverrides ;
291303 const originalConfig = `
292304 import type { NextConfig } from 'next'
293-
305+
294306 const nextConfig: NextConfig = {
295307 /* config options here */
296308 }
297-
309+
298310 export default nextConfig
299311 ` ;
300312
@@ -307,22 +319,21 @@ describe("next config overrides", () => {
307319 normalizeWhitespace ( `
308320 // @ts-nocheck
309321 import originalConfig from './next.config.original';
310-
322+
311323 ${ nextConfigOverrideBody }
312-
324+
313325 module.exports = config;
314326 ` ) ,
315327 ) ;
316328 } ) ;
317329
318- it ( "should not do anything if no next.config.* file exists " , async ( ) => {
330+ it ( "should create a default next.config.js file if one does not exist yet " , async ( ) => {
319331 const { overrideNextConfig } = await importOverrides ;
320332 await overrideNextConfig ( tmpDir , "next.config.js" ) ;
321-
322- // Assert that no next.config* files were created
323- const files = fs . readdirSync ( tmpDir ) ;
324- const nextConfigFiles = files . filter ( ( file ) => file . startsWith ( "next.config" ) ) ;
325- assert . strictEqual ( nextConfigFiles . length , 0 , "No next.config files should exist" ) ;
333+ const updatedConfig = fs . readFileSync ( path . join ( tmpDir , "next.config.js" ) , "utf-8" ) ;
334+ assert . equal (
335+ normalizeWhitespace ( updatedConfig ) , normalizeWhitespace ( defaultNextConfig ) ,
336+ ) ;
326337 } ) ;
327338} ) ;
328339
0 commit comments