Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Measure getStaticProps, getServerSideProps #10800

Merged
merged 3 commits into from
Mar 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/next/build/index.ts
Original file line number Diff line number Diff line change
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:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This count has been wrong historically. Fixed now!

pagePaths.length -
(staticPages.size + ssgPages.size + serverPropsPages.size),
hasStatic404: useStatic404,
})
)
Expand Down
2 changes: 2 additions & 0 deletions packages/next/telemetry/events/build.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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