@@ -10,6 +10,7 @@ import { beforeEach, describe, expect, Mock, test, vi } from 'vitest'
10
10
import { decodeBlobKey , encodeBlobKey , mockFileSystem } from '../../../tests/index.js'
11
11
import { type FixtureTestContext } from '../../../tests/utils/contexts.js'
12
12
import { createFsFixture } from '../../../tests/utils/fixture.js'
13
+ import { HtmlBlob } from '../../shared/blob-types.cjs'
13
14
import { PluginContext , RequiredServerFilesManifest } from '../plugin-context.js'
14
15
15
16
import { copyStaticAssets , copyStaticContent } from './static.js'
@@ -22,18 +23,19 @@ type Context = FixtureTestContext & {
22
23
const createFsFixtureWithBasePath = (
23
24
fixture : Record < string , string > ,
24
25
ctx : Omit < Context , 'pluginContext' > ,
25
-
26
26
{
27
27
basePath = '' ,
28
28
// eslint-disable-next-line unicorn/no-useless-undefined
29
29
i18n = undefined ,
30
30
dynamicRoutes = { } ,
31
+ pagesManifest = { } ,
31
32
} : {
32
33
basePath ?: string
33
34
i18n ?: Pick < NonNullable < RequiredServerFilesManifest [ 'config' ] [ 'i18n' ] > , 'locales' >
34
35
dynamicRoutes ?: {
35
36
[ route : string ] : Pick < PrerenderManifest [ 'dynamicRoutes' ] [ '' ] , 'fallback' >
36
37
}
38
+ pagesManifest ?: Record < string , string >
37
39
} = { } ,
38
40
) => {
39
41
return createFsFixture (
@@ -49,6 +51,7 @@ const createFsFixtureWithBasePath = (
49
51
} ,
50
52
} as Pick < RequiredServerFilesManifest , 'relativeAppDir' | 'appDir' > ) ,
51
53
[ join ( ctx . publishDir , 'prerender-manifest.json' ) ] : JSON . stringify ( { dynamicRoutes } ) ,
54
+ [ join ( ctx . publishDir , 'server' , 'pages-manifest.json' ) ] : JSON . stringify ( pagesManifest ) ,
52
55
} ,
53
56
ctx ,
54
57
)
@@ -62,10 +65,7 @@ async function readDirRecursive(dir: string) {
62
65
return paths
63
66
}
64
67
65
- let failBuildMock : Mock <
66
- Parameters < PluginContext [ 'utils' ] [ 'build' ] [ 'failBuild' ] > ,
67
- ReturnType < PluginContext [ 'utils' ] [ 'build' ] [ 'failBuild' ] >
68
- >
68
+ let failBuildMock : Mock < PluginContext [ 'utils' ] [ 'build' ] [ 'failBuild' ] >
69
69
70
70
const dontFailTest : PluginContext [ 'utils' ] [ 'build' ] [ 'failBuild' ] = ( ) => {
71
71
return undefined as never
@@ -197,12 +197,13 @@ describe('Regular Repository layout', () => {
197
197
)
198
198
} )
199
199
200
- describe ( 'should copy the static pages to the publish directory if there are no corresponding JSON files and mark wether html file is a fallback ' , ( ) => {
200
+ describe ( 'should copy the static pages to the publish directory if there are no corresponding JSON files and mark wether html file is a fully static pages router page ' , ( ) => {
201
201
test < Context > ( 'no i18n' , async ( { pluginContext, ...ctx } ) => {
202
202
await createFsFixtureWithBasePath (
203
203
{
204
204
'.next/server/pages/test.html' : '' ,
205
205
'.next/server/pages/test2.html' : '' ,
206
+ '.next/server/pages/test3.html' : '' ,
206
207
'.next/server/pages/test3.json' : '' ,
207
208
'.next/server/pages/blog/[slug].html' : '' ,
208
209
} ,
@@ -213,27 +214,36 @@ describe('Regular Repository layout', () => {
213
214
fallback : '/blog/[slug].html' ,
214
215
} ,
215
216
} ,
217
+ pagesManifest : {
218
+ '/blog/[slug]' : 'pages/blog/[slug].js' ,
219
+ '/test' : 'pages/test.html' ,
220
+ '/test2' : 'pages/test2.html' ,
221
+ '/test3' : 'pages/test3.js' ,
222
+ } ,
216
223
} ,
217
224
)
218
225
219
226
await copyStaticContent ( pluginContext )
220
227
const files = await glob ( '**/*' , { cwd : pluginContext . blobDir , dot : true } )
221
228
222
- const expectedStaticPages = [ 'blog/[slug].html' , 'test.html' , 'test2.html' ]
223
- const expectedFallbacks = new Set ( [ 'blog/[slug] .html' ] )
229
+ const expectedHtmlBlobs = [ 'blog/[slug].html' , 'test.html' , 'test2.html' ]
230
+ const expectedFullyStaticPages = new Set ( [ 'test.html' , 'test2 .html'] )
224
231
225
- expect ( files . map ( ( path ) => decodeBlobKey ( path ) ) . sort ( ) ) . toEqual ( expectedStaticPages )
232
+ expect ( files . map ( ( path ) => decodeBlobKey ( path ) ) . sort ( ) ) . toEqual ( expectedHtmlBlobs )
226
233
227
- for ( const page of expectedStaticPages ) {
228
- const expectedIsFallback = expectedFallbacks . has ( page )
234
+ for ( const page of expectedHtmlBlobs ) {
235
+ const expectedIsFullyStaticPage = expectedFullyStaticPages . has ( page )
229
236
230
237
const blob = JSON . parse (
231
238
await readFile ( join ( pluginContext . blobDir , await encodeBlobKey ( page ) ) , 'utf-8' ) ,
232
- )
239
+ ) as HtmlBlob
233
240
234
- expect ( blob , `${ page } should ${ expectedIsFallback ? '' : 'not ' } be a fallback` ) . toEqual ( {
241
+ expect (
242
+ blob ,
243
+ `${ page } should ${ expectedIsFullyStaticPage ? '' : 'not ' } be a fully static Page` ,
244
+ ) . toEqual ( {
235
245
html : '' ,
236
- isFallback : expectedIsFallback ,
246
+ isFullyStaticPage : expectedIsFullyStaticPage ,
237
247
} )
238
248
}
239
249
} )
@@ -243,10 +253,12 @@ describe('Regular Repository layout', () => {
243
253
{
244
254
'.next/server/pages/de/test.html' : '' ,
245
255
'.next/server/pages/de/test2.html' : '' ,
256
+ '.next/server/pages/de/test3.html' : '' ,
246
257
'.next/server/pages/de/test3.json' : '' ,
247
258
'.next/server/pages/de/blog/[slug].html' : '' ,
248
259
'.next/server/pages/en/test.html' : '' ,
249
260
'.next/server/pages/en/test2.html' : '' ,
261
+ '.next/server/pages/en/test3.html' : '' ,
250
262
'.next/server/pages/en/test3.json' : '' ,
251
263
'.next/server/pages/en/blog/[slug].html' : '' ,
252
264
} ,
@@ -260,34 +272,50 @@ describe('Regular Repository layout', () => {
260
272
i18n : {
261
273
locales : [ 'en' , 'de' ] ,
262
274
} ,
275
+ pagesManifest : {
276
+ '/blog/[slug]' : 'pages/blog/[slug].js' ,
277
+ '/en/test' : 'pages/en/test.html' ,
278
+ '/de/test' : 'pages/de/test.html' ,
279
+ '/en/test2' : 'pages/en/test2.html' ,
280
+ '/de/test2' : 'pages/de/test2.html' ,
281
+ '/test3' : 'pages/test3.js' ,
282
+ } ,
263
283
} ,
264
284
)
265
285
266
286
await copyStaticContent ( pluginContext )
267
287
const files = await glob ( '**/*' , { cwd : pluginContext . blobDir , dot : true } )
268
288
269
- const expectedStaticPages = [
289
+ const expectedHtmlBlobs = [
270
290
'de/blog/[slug].html' ,
271
291
'de/test.html' ,
272
292
'de/test2.html' ,
273
293
'en/blog/[slug].html' ,
274
294
'en/test.html' ,
275
295
'en/test2.html' ,
276
296
]
277
- const expectedFallbacks = new Set ( [ 'en/blog/[slug].html' , 'de/blog/[slug].html' ] )
297
+ const expectedFullyStaticPages = new Set ( [
298
+ 'en/test.html' ,
299
+ 'de/test.html' ,
300
+ 'en/test2.html' ,
301
+ 'de/test2.html' ,
302
+ ] )
278
303
279
- expect ( files . map ( ( path ) => decodeBlobKey ( path ) ) . sort ( ) ) . toEqual ( expectedStaticPages )
304
+ expect ( files . map ( ( path ) => decodeBlobKey ( path ) ) . sort ( ) ) . toEqual ( expectedHtmlBlobs )
280
305
281
- for ( const page of expectedStaticPages ) {
282
- const expectedIsFallback = expectedFallbacks . has ( page )
306
+ for ( const page of expectedHtmlBlobs ) {
307
+ const expectedIsFullyStaticPage = expectedFullyStaticPages . has ( page )
283
308
284
309
const blob = JSON . parse (
285
310
await readFile ( join ( pluginContext . blobDir , await encodeBlobKey ( page ) ) , 'utf-8' ) ,
286
- )
311
+ ) as HtmlBlob
287
312
288
- expect ( blob , `${ page } should ${ expectedIsFallback ? '' : 'not ' } be a fallback` ) . toEqual ( {
313
+ expect (
314
+ blob ,
315
+ `${ page } should ${ expectedIsFullyStaticPage ? '' : 'not ' } be a fully static Page` ,
316
+ ) . toEqual ( {
289
317
html : '' ,
290
- isFallback : expectedIsFallback ,
318
+ isFullyStaticPage : expectedIsFullyStaticPage ,
291
319
} )
292
320
}
293
321
} )
@@ -419,12 +447,13 @@ describe('Mono Repository', () => {
419
447
)
420
448
} )
421
449
422
- describe ( 'should copy the static pages to the publish directory if there are no corresponding JSON files and mark wether html file is a fallback ' , ( ) => {
450
+ describe ( 'should copy the static pages to the publish directory if there are no corresponding JSON files and mark wether html file is a fully static pages router page ' , ( ) => {
423
451
test < Context > ( 'no i18n' , async ( { pluginContext, ...ctx } ) => {
424
452
await createFsFixtureWithBasePath (
425
453
{
426
454
'apps/app-1/.next/server/pages/test.html' : '' ,
427
455
'apps/app-1/.next/server/pages/test2.html' : '' ,
456
+ 'apps/app-1/.next/server/pages/test3.html' : '' ,
428
457
'apps/app-1/.next/server/pages/test3.json' : '' ,
429
458
'apps/app-1/.next/server/pages/blog/[slug].html' : '' ,
430
459
} ,
@@ -435,27 +464,36 @@ describe('Mono Repository', () => {
435
464
fallback : '/blog/[slug].html' ,
436
465
} ,
437
466
} ,
467
+ pagesManifest : {
468
+ '/blog/[slug]' : 'pages/blog/[slug].js' ,
469
+ '/test' : 'pages/test.html' ,
470
+ '/test2' : 'pages/test2.html' ,
471
+ '/test3' : 'pages/test3.js' ,
472
+ } ,
438
473
} ,
439
474
)
440
475
441
476
await copyStaticContent ( pluginContext )
442
477
const files = await glob ( '**/*' , { cwd : pluginContext . blobDir , dot : true } )
443
478
444
- const expectedStaticPages = [ 'blog/[slug].html' , 'test.html' , 'test2.html' ]
445
- const expectedFallbacks = new Set ( [ 'blog/[slug] .html' ] )
479
+ const expectedHtmlBlobs = [ 'blog/[slug].html' , 'test.html' , 'test2.html' ]
480
+ const expectedFullyStaticPages = new Set ( [ 'test.html' , 'test2 .html'] )
446
481
447
- expect ( files . map ( ( path ) => decodeBlobKey ( path ) ) . sort ( ) ) . toEqual ( expectedStaticPages )
482
+ expect ( files . map ( ( path ) => decodeBlobKey ( path ) ) . sort ( ) ) . toEqual ( expectedHtmlBlobs )
448
483
449
- for ( const page of expectedStaticPages ) {
450
- const expectedIsFallback = expectedFallbacks . has ( page )
484
+ for ( const page of expectedHtmlBlobs ) {
485
+ const expectedIsFullyStaticPage = expectedFullyStaticPages . has ( page )
451
486
452
487
const blob = JSON . parse (
453
488
await readFile ( join ( pluginContext . blobDir , await encodeBlobKey ( page ) ) , 'utf-8' ) ,
454
- )
489
+ ) as HtmlBlob
455
490
456
- expect ( blob , `${ page } should ${ expectedIsFallback ? '' : 'not ' } be a fallback` ) . toEqual ( {
491
+ expect (
492
+ blob ,
493
+ `${ page } should ${ expectedIsFullyStaticPage ? '' : 'not ' } be a fully static Page` ,
494
+ ) . toEqual ( {
457
495
html : '' ,
458
- isFallback : expectedIsFallback ,
496
+ isFullyStaticPage : expectedIsFullyStaticPage ,
459
497
} )
460
498
}
461
499
} )
@@ -465,10 +503,12 @@ describe('Mono Repository', () => {
465
503
{
466
504
'apps/app-1/.next/server/pages/de/test.html' : '' ,
467
505
'apps/app-1/.next/server/pages/de/test2.html' : '' ,
506
+ 'apps/app-1/.next/server/pages/de/test3.html' : '' ,
468
507
'apps/app-1/.next/server/pages/de/test3.json' : '' ,
469
508
'apps/app-1/.next/server/pages/de/blog/[slug].html' : '' ,
470
509
'apps/app-1/.next/server/pages/en/test.html' : '' ,
471
510
'apps/app-1/.next/server/pages/en/test2.html' : '' ,
511
+ 'apps/app-1/.next/server/pages/en/test3.html' : '' ,
472
512
'apps/app-1/.next/server/pages/en/test3.json' : '' ,
473
513
'apps/app-1/.next/server/pages/en/blog/[slug].html' : '' ,
474
514
} ,
@@ -482,34 +522,50 @@ describe('Mono Repository', () => {
482
522
i18n : {
483
523
locales : [ 'en' , 'de' ] ,
484
524
} ,
525
+ pagesManifest : {
526
+ '/blog/[slug]' : 'pages/blog/[slug].js' ,
527
+ '/en/test' : 'pages/en/test.html' ,
528
+ '/de/test' : 'pages/de/test.html' ,
529
+ '/en/test2' : 'pages/en/test2.html' ,
530
+ '/de/test2' : 'pages/de/test2.html' ,
531
+ '/test3' : 'pages/test3.js' ,
532
+ } ,
485
533
} ,
486
534
)
487
535
488
536
await copyStaticContent ( pluginContext )
489
537
const files = await glob ( '**/*' , { cwd : pluginContext . blobDir , dot : true } )
490
538
491
- const expectedStaticPages = [
539
+ const expectedHtmlBlobs = [
492
540
'de/blog/[slug].html' ,
493
541
'de/test.html' ,
494
542
'de/test2.html' ,
495
543
'en/blog/[slug].html' ,
496
544
'en/test.html' ,
497
545
'en/test2.html' ,
498
546
]
499
- const expectedFallbacks = new Set ( [ 'en/blog/[slug].html' , 'de/blog/[slug].html' ] )
547
+ const expectedFullyStaticPages = new Set ( [
548
+ 'en/test.html' ,
549
+ 'de/test.html' ,
550
+ 'en/test2.html' ,
551
+ 'de/test2.html' ,
552
+ ] )
500
553
501
- expect ( files . map ( ( path ) => decodeBlobKey ( path ) ) . sort ( ) ) . toEqual ( expectedStaticPages )
554
+ expect ( files . map ( ( path ) => decodeBlobKey ( path ) ) . sort ( ) ) . toEqual ( expectedHtmlBlobs )
502
555
503
- for ( const page of expectedStaticPages ) {
504
- const expectedIsFallback = expectedFallbacks . has ( page )
556
+ for ( const page of expectedHtmlBlobs ) {
557
+ const expectedIsFullyStaticPage = expectedFullyStaticPages . has ( page )
505
558
506
559
const blob = JSON . parse (
507
560
await readFile ( join ( pluginContext . blobDir , await encodeBlobKey ( page ) ) , 'utf-8' ) ,
508
- )
561
+ ) as HtmlBlob
509
562
510
- expect ( blob , `${ page } should ${ expectedIsFallback ? '' : 'not ' } be a fallback` ) . toEqual ( {
563
+ expect (
564
+ blob ,
565
+ `${ page } should ${ expectedIsFullyStaticPage ? '' : 'not ' } be a fully static Page` ,
566
+ ) . toEqual ( {
511
567
html : '' ,
512
- isFallback : expectedIsFallback ,
568
+ isFullyStaticPage : expectedIsFullyStaticPage ,
513
569
} )
514
570
}
515
571
} )
0 commit comments