Skip to content

Commit

Permalink
Measure getStaticProps, getServerSideProps (#10800)
Browse files Browse the repository at this point in the history
* Measure `getStaticProps`, `getServerSideProps`

* Test new fields
  • Loading branch information
Timer committed Mar 3, 2020
1 parent ad1a061 commit a5d0cb9
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 3 deletions.
6 changes: 5 additions & 1 deletion packages/next/build/index.ts
Expand Up @@ -815,7 +815,11 @@ export default async function build(dir: string, conf = null): Promise<void> {
eventBuildOptimize(pagePaths, {
durationInSeconds: analysisEnd[0],
staticPageCount: staticPages.size,
ssrPageCount: pagePaths.length - staticPages.size,
staticPropsPageCount: ssgPages.size,
serverPropsPageCount: serverPropsPages.size,
ssrPageCount:
pagePaths.length -
(staticPages.size + ssgPages.size + serverPropsPages.size),
hasStatic404: useStatic404,
})
)
Expand Down
2 changes: 2 additions & 0 deletions packages/next/telemetry/events/build.ts
Expand Up @@ -37,6 +37,8 @@ type EventBuildOptimized = {
durationInSeconds: number
totalPageCount: number
staticPageCount: number
staticPropsPageCount: number
serverPropsPageCount: number
ssrPageCount: number
hasDunderPages: boolean
hasTestPages: boolean
Expand Down
7 changes: 7 additions & 0 deletions test/integration/telemetry/pages/gip.js
@@ -0,0 +1,7 @@
function A() {
return 'Hello World'
}

A.getInitialProps = () => ({ foo: 'bar' })

export default A
5 changes: 5 additions & 0 deletions test/integration/telemetry/pages/gssp.js
@@ -0,0 +1,5 @@
export default () => 'Hello World'

export function getServerSideProps() {
return { props: {} }
}
5 changes: 5 additions & 0 deletions test/integration/telemetry/pages/ssg.js
@@ -0,0 +1,5 @@
export default () => 'Hello World'

export function getStaticProps() {
return { props: {} }
}
9 changes: 9 additions & 0 deletions test/integration/telemetry/pages/ssg/[dynamic].js
@@ -0,0 +1,9 @@
export default () => 'Hello World'

export function getStaticProps() {
return { props: {} }
}

export function getStaticPaths() {
return { paths: [], fallback: true }
}
16 changes: 14 additions & 2 deletions test/integration/telemetry/test/index.test.js
Expand Up @@ -224,8 +224,6 @@ describe('Telemetry CLI', () => {
path.join(appDir, 'package.babel')
)

console.log(stderr)

const event = /NEXT_CLI_SESSION_STARTED[\s\S]+?{([\s\S]+?)}/
.exec(stderr)
.pop()
Expand Down Expand Up @@ -324,6 +322,20 @@ describe('Telemetry CLI', () => {
expect(event1).toMatch(/hasStatic404.*?true/)
})

it('detect page counts correctly for `next build`', async () => {
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})

const event1 = /NEXT_BUILD_OPTIMIZED[\s\S]+?{([\s\S]+?)}/.exec(stderr).pop()
expect(event1).toMatch(/"staticPropsPageCount": 2/)
expect(event1).toMatch(/"serverPropsPageCount": 1/)
expect(event1).toMatch(/"ssrPageCount": 1/)
expect(event1).toMatch(/"staticPageCount": 2/)
expect(event1).toMatch(/"totalPageCount": 6/)
})

it('detects isSrcDir dir correctly for `next dev`', async () => {
let port = await findPort()
let stderr = ''
Expand Down

0 comments on commit a5d0cb9

Please sign in to comment.