Skip to content

Commit

Permalink
Add (failing) test for module based feature telemetry in App Router
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Feb 12, 2025
1 parent f5f7151 commit 83b64e9
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 176 deletions.
16 changes: 16 additions & 0 deletions test/integration/telemetry/app/app-dir/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Image from 'next/image'
import LegacyImage from 'next/legacy/image'
import profilePic from '../../public/small.jpg'

function About() {
return (
<>
<h1>My Homepage</h1>
<LegacyImage src={profilePic} alt="Picture of the author" />
<Image src={profilePic} alt="Picture of the author" />
<p>Welcome to my homepage!</p>
</>
)
}

export default About
3 changes: 3 additions & 0 deletions test/integration/telemetry/app/hello/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Page() {
return 'hello world'
}
7 changes: 7 additions & 0 deletions test/integration/telemetry/app/layout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function RootLayout({ children }) {
return (
<html>
<body>{children}</body>
</html>
)
}
7 changes: 6 additions & 1 deletion test/integration/telemetry/test/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('config telemetry', () => {
expect(event1).toMatch(/"reactStrictMode": false/)
expect(event1).toMatch(/"turboFlag": false/)
expect(event1).toMatch(/"pagesDir": true/)
expect(event1).toMatch(/"appDir": false/)
expect(event1).toMatch(/"appDir": true/)
} catch (err) {
require('console').error('failing stderr', stderr, err)
throw err
Expand Down Expand Up @@ -287,6 +287,7 @@ describe('config telemetry', () => {
expect.arrayContaining([
{
featureName: 'next/image',
// FIXME: Should be +1 from App Router
invocationCount: 2,
},
{
Expand Down Expand Up @@ -532,12 +533,14 @@ describe('config telemetry', () => {
)
// eslint-disable-next-line jest/no-standalone-expect
expect(featureUsageEvents).toContainEqual({
// FIXME: Should be +1 from App Router
featureName: 'next/legacy/image',
invocationCount: 2,
})
// eslint-disable-next-line jest/no-standalone-expect
expect(featureUsageEvents).toContainEqual({
featureName: 'next/image',
// FIXME: Should be +1 from App Router
invocationCount: 2,
})
}
Expand Down Expand Up @@ -724,6 +727,7 @@ describe('config telemetry', () => {
path.join(appDir, 'next.config.js')
)

await fs.move(path.join(appDir, 'app'), path.join(appDir, '~app'))
await fs.move(path.join(appDir, '_app'), path.join(appDir, 'app'))

const { stderr } = await nextBuild(appDir, [], {
Expand All @@ -737,6 +741,7 @@ describe('config telemetry', () => {
)

await fs.move(path.join(appDir, 'app'), path.join(appDir, '_app'))
await fs.move(path.join(appDir, '~app'), path.join(appDir, 'app'))

const featureUsageEvents = findAllTelemetryEvents(
stderr,
Expand Down
4 changes: 2 additions & 2 deletions test/integration/telemetry/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,8 @@ describe('Telemetry CLI', () => {
expect(event1).toMatch(/"ssrPageCount": 3/)
expect(event1).toMatch(/"staticPageCount": 5/)
expect(event1).toMatch(/"totalPageCount": 12/)
expect(event1).toMatch(/"totalAppPagesCount": 0/)
expect(event1).toMatch(/"staticAppPagesCount": 0/)
expect(event1).toMatch(/"totalAppPagesCount": 3/)
expect(event1).toMatch(/"staticAppPagesCount": 3/)
expect(event1).toMatch(/"serverAppPagesCount": 0/)
expect(event1).toMatch(/"edgeRuntimeAppCount": 0/)
expect(event1).toMatch(/"edgeRuntimePagesCount": 2/)
Expand Down
Loading

0 comments on commit 83b64e9

Please sign in to comment.