@@ -331,9 +331,14 @@ describe('Telemetry CLI', () => {
331
331
const event1 = / N E X T _ B U I L D _ O P T I M I Z E D [ \s \S ] + ?{ ( [ \s \S ] + ?) } / . exec ( stderr ) . pop ( )
332
332
expect ( event1 ) . toMatch ( / " s t a t i c P r o p s P a g e C o u n t " : 2 / )
333
333
expect ( event1 ) . toMatch ( / " s e r v e r P r o p s P a g e C o u n t " : 2 / )
334
- expect ( event1 ) . toMatch ( / " s s r P a g e C o u n t " : 2 / )
334
+ expect ( event1 ) . toMatch ( / " s s r P a g e C o u n t " : 3 / )
335
335
expect ( event1 ) . toMatch ( / " s t a t i c P a g e C o u n t " : 4 / )
336
- expect ( event1 ) . toMatch ( / " t o t a l P a g e C o u n t " : 1 0 / )
336
+ expect ( event1 ) . toMatch ( / " t o t a l P a g e C o u n t " : 1 1 / )
337
+ expect ( event1 ) . toMatch ( / " t o t a l A p p P a g e s C o u n t " : 0 / )
338
+ expect ( event1 ) . toMatch ( / " s t a t i c A p p P a g e s C o u n t " : 0 / )
339
+ expect ( event1 ) . toMatch ( / " s e r v e r A p p P a g e s C o u n t " : 0 / )
340
+ expect ( event1 ) . toMatch ( / " e d g e R u n t i m e A p p C o u n t " : 0 / )
341
+ expect ( event1 ) . toMatch ( / " e d g e R u n t i m e P a g e s C o u n t " : 2 / )
337
342
} )
338
343
339
344
it ( 'detects isSrcDir dir correctly for `next dev`' , async ( ) => {
@@ -377,7 +382,19 @@ describe('Telemetry CLI', () => {
377
382
)
378
383
await fs . mkdir ( path . join ( __dirname , '../app' ) )
379
384
await fs . writeFile (
380
- path . join ( __dirname , '../app/page.js' ) ,
385
+ path . join ( __dirname , '../app/layout.js' ) ,
386
+ `
387
+ export default function RootLayout({ children }) {
388
+ return <html>
389
+ <head/>
390
+ <body>{children}</body>
391
+ </html>
392
+ }
393
+ `
394
+ )
395
+ await fs . ensureFile ( path . join ( __dirname , '../app/hello/page.js' ) )
396
+ await fs . writeFile (
397
+ path . join ( __dirname , '../app/hello/page.js' ) ,
381
398
'export default function Page() { return "hello world" }'
382
399
)
383
400
@@ -490,6 +507,73 @@ describe('Telemetry CLI', () => {
490
507
}
491
508
} )
492
509
510
+ it ( 'should detect app page counts' , async ( ) => {
511
+ const teardown = await setupAppDir ( )
512
+
513
+ try {
514
+ await fs . ensureFile ( path . join ( __dirname , '../app/ssr/page.js' ) )
515
+ await fs . writeFile (
516
+ path . join ( __dirname , '../app/ssr/page.js' ) ,
517
+ `
518
+ export const revalidate = 0
519
+ export default function Page() {
520
+ return <p>ssr page</p>
521
+ }
522
+ `
523
+ )
524
+ await fs . ensureFile ( path . join ( __dirname , '../app/edge-ssr/page.js' ) )
525
+ await fs . writeFile (
526
+ path . join ( __dirname , '../app/edge-ssr/page.js' ) ,
527
+ `
528
+ export const runtime = 'experimental-edge'
529
+ export default function Page() {
530
+ return <p>edge-ssr page</p>
531
+ }
532
+ `
533
+ )
534
+ await fs . ensureFile ( path . join ( __dirname , '../app/app-ssg/[slug]/page.js' ) )
535
+ await fs . writeFile (
536
+ path . join ( __dirname , '../app/app-ssg/[slug]/page.js' ) ,
537
+ `
538
+ export function generateStaticParams() {
539
+ return [
540
+ { slug: 'post-1' },
541
+ { slug: 'post-2' },
542
+ ]
543
+ }
544
+ export default function Page() {
545
+ return <p>ssg page</p>
546
+ }
547
+ `
548
+ )
549
+ const { stderr } = await nextBuild ( appDir , [ ] , {
550
+ stderr : true ,
551
+ env : { NEXT_TELEMETRY_DEBUG : 1 } ,
552
+ } )
553
+
554
+ const event1 = / N E X T _ B U I L D _ O P T I M I Z E D [ \s \S ] + ?{ ( [ \s \S ] + ?) } /
555
+ . exec ( stderr )
556
+ . pop ( )
557
+ expect ( event1 ) . toMatch ( / " s t a t i c P r o p s P a g e C o u n t " : 2 / )
558
+ expect ( event1 ) . toMatch ( / " s e r v e r P r o p s P a g e C o u n t " : 2 / )
559
+ expect ( event1 ) . toMatch ( / " s s r P a g e C o u n t " : 3 / )
560
+ expect ( event1 ) . toMatch ( / " s t a t i c P a g e C o u n t " : 4 / )
561
+ expect ( event1 ) . toMatch ( / " t o t a l P a g e C o u n t " : 1 1 / )
562
+ expect ( event1 ) . toMatch ( / " t o t a l A p p P a g e s C o u n t " : 4 / )
563
+ expect ( event1 ) . toMatch ( / " s e r v e r A p p P a g e s C o u n t " : 2 / )
564
+ expect ( event1 ) . toMatch ( / " e d g e R u n t i m e A p p C o u n t " : 1 / )
565
+ expect ( event1 ) . toMatch ( / " e d g e R u n t i m e P a g e s C o u n t " : 2 / )
566
+
567
+ const event2 = / N E X T _ B U I L D _ C O M P L E T E D [ \s \S ] + ?{ ( [ \s \S ] + ?) } /
568
+ . exec ( stderr )
569
+ . pop ( )
570
+
571
+ expect ( event2 ) . toMatch ( / " t o t a l A p p P a g e s C o u n t " : 4 / )
572
+ } finally {
573
+ await teardown ( )
574
+ }
575
+ } )
576
+
493
577
it ( 'detect reportWebVitals correctly for `next build`' , async ( ) => {
494
578
// Case 1: When _app.js does not exist.
495
579
let build = await nextBuild ( appDir , [ ] , {
@@ -750,6 +834,7 @@ describe('Telemetry CLI', () => {
750
834
stderr ,
751
835
'NEXT_BUILD_FEATURE_USAGE'
752
836
)
837
+
753
838
expect ( featureUsageEvents ) . toEqual (
754
839
expect . arrayContaining ( [
755
840
{
@@ -758,7 +843,7 @@ describe('Telemetry CLI', () => {
758
843
} ,
759
844
{
760
845
featureName : 'next/image' ,
761
- invocationCount : 1 ,
846
+ invocationCount : 2 ,
762
847
} ,
763
848
{
764
849
featureName : 'next/script' ,
@@ -787,8 +872,14 @@ describe('Telemetry CLI', () => {
787
872
stderr : true ,
788
873
env : { NEXT_TELEMETRY_DEBUG : 1 } ,
789
874
} )
790
- await fs . remove ( path . join ( appDir , 'next.config.js' ) )
791
- await fs . remove ( path . join ( appDir , 'jsconfig.json' ) )
875
+ await fs . rename (
876
+ path . join ( appDir , 'next.config.js' ) ,
877
+ path . join ( appDir , 'next.config.swc' )
878
+ )
879
+ await fs . rename (
880
+ path . join ( appDir , 'jsconfig.json' ) ,
881
+ path . join ( appDir , 'jsconfig.swc' )
882
+ )
792
883
const featureUsageEvents = findAllTelemetryEvents (
793
884
stderr ,
794
885
'NEXT_BUILD_FEATURE_USAGE'
@@ -963,11 +1054,11 @@ describe('Telemetry CLI', () => {
963
1054
)
964
1055
expect ( featureUsageEvents ) . toContainEqual ( {
965
1056
featureName : 'next/legacy/image' ,
966
- invocationCount : 1 ,
1057
+ invocationCount : 2 ,
967
1058
} )
968
1059
expect ( featureUsageEvents ) . toContainEqual ( {
969
1060
featureName : 'next/image' ,
970
- invocationCount : 1 ,
1061
+ invocationCount : 2 ,
971
1062
} )
972
1063
} )
973
1064
0 commit comments