@@ -331,9 +331,14 @@ describe('Telemetry CLI', () => {
331331 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 ( )
332332 expect ( event1 ) . toMatch ( / " s t a t i c P r o p s P a g e C o u n t " : 2 / )
333333 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 / )
335335 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 / )
337342 } )
338343
339344 it ( 'detects isSrcDir dir correctly for `next dev`' , async ( ) => {
@@ -377,7 +382,19 @@ describe('Telemetry CLI', () => {
377382 )
378383 await fs . mkdir ( path . join ( __dirname , '../app' ) )
379384 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' ) ,
381398 'export default function Page() { return "hello world" }'
382399 )
383400
@@ -490,6 +507,73 @@ describe('Telemetry CLI', () => {
490507 }
491508 } )
492509
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+
493577 it ( 'detect reportWebVitals correctly for `next build`' , async ( ) => {
494578 // Case 1: When _app.js does not exist.
495579 let build = await nextBuild ( appDir , [ ] , {
@@ -750,6 +834,7 @@ describe('Telemetry CLI', () => {
750834 stderr ,
751835 'NEXT_BUILD_FEATURE_USAGE'
752836 )
837+
753838 expect ( featureUsageEvents ) . toEqual (
754839 expect . arrayContaining ( [
755840 {
@@ -758,7 +843,7 @@ describe('Telemetry CLI', () => {
758843 } ,
759844 {
760845 featureName : 'next/image' ,
761- invocationCount : 1 ,
846+ invocationCount : 2 ,
762847 } ,
763848 {
764849 featureName : 'next/script' ,
@@ -787,8 +872,14 @@ describe('Telemetry CLI', () => {
787872 stderr : true ,
788873 env : { NEXT_TELEMETRY_DEBUG : 1 } ,
789874 } )
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+ )
792883 const featureUsageEvents = findAllTelemetryEvents (
793884 stderr ,
794885 'NEXT_BUILD_FEATURE_USAGE'
@@ -963,11 +1054,11 @@ describe('Telemetry CLI', () => {
9631054 )
9641055 expect ( featureUsageEvents ) . toContainEqual ( {
9651056 featureName : 'next/legacy/image' ,
966- invocationCount : 1 ,
1057+ invocationCount : 2 ,
9671058 } )
9681059 expect ( featureUsageEvents ) . toContainEqual ( {
9691060 featureName : 'next/image' ,
970- invocationCount : 1 ,
1061+ invocationCount : 2 ,
9711062 } )
9721063 } )
9731064
0 commit comments