Unverified Commit 99bf5e9a authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

Add (failing) test for module based feature telemetry in App Router (#75952)

Noticed this while adding bundle layers to Pages router. The telemetry Webpack plugin is picking up these features but then we're not recording them properly.
parent 2cbd03c8
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
export default function Page() {
return 'hello world'
}
export default function RootLayout({ children }) {
return (
<html>
<body>{children}</body>
</html>
)
}
...@@ -84,7 +84,7 @@ describe('config telemetry', () => { ...@@ -84,7 +84,7 @@ describe('config telemetry', () => {
expect(event1).toMatch(/"reactStrictMode": false/) expect(event1).toMatch(/"reactStrictMode": false/)
expect(event1).toMatch(/"turboFlag": false/) expect(event1).toMatch(/"turboFlag": false/)
expect(event1).toMatch(/"pagesDir": true/) expect(event1).toMatch(/"pagesDir": true/)
expect(event1).toMatch(/"appDir": false/) expect(event1).toMatch(/"appDir": true/)
} catch (err) { } catch (err) {
require('console').error('failing stderr', stderr, err) require('console').error('failing stderr', stderr, err)
throw err throw err
...@@ -287,6 +287,7 @@ describe('config telemetry', () => { ...@@ -287,6 +287,7 @@ describe('config telemetry', () => {
expect.arrayContaining([ expect.arrayContaining([
{ {
featureName: 'next/image', featureName: 'next/image',
// FIXME: Should be +1 from App Router
invocationCount: 2, invocationCount: 2,
}, },
{ {
...@@ -532,12 +533,14 @@ describe('config telemetry', () => { ...@@ -532,12 +533,14 @@ describe('config telemetry', () => {
) )
// eslint-disable-next-line jest/no-standalone-expect // eslint-disable-next-line jest/no-standalone-expect
expect(featureUsageEvents).toContainEqual({ expect(featureUsageEvents).toContainEqual({
// FIXME: Should be +1 from App Router
featureName: 'next/legacy/image', featureName: 'next/legacy/image',
invocationCount: 2, invocationCount: 2,
}) })
// eslint-disable-next-line jest/no-standalone-expect // eslint-disable-next-line jest/no-standalone-expect
expect(featureUsageEvents).toContainEqual({ expect(featureUsageEvents).toContainEqual({
featureName: 'next/image', featureName: 'next/image',
// FIXME: Should be +1 from App Router
invocationCount: 2, invocationCount: 2,
}) })
} }
...@@ -724,6 +727,7 @@ describe('config telemetry', () => { ...@@ -724,6 +727,7 @@ describe('config telemetry', () => {
path.join(appDir, 'next.config.js') 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')) await fs.move(path.join(appDir, '_app'), path.join(appDir, 'app'))
const { stderr } = await nextBuild(appDir, [], { const { stderr } = await nextBuild(appDir, [], {
...@@ -737,6 +741,7 @@ describe('config telemetry', () => { ...@@ -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'))
await fs.move(path.join(appDir, '~app'), path.join(appDir, 'app'))
const featureUsageEvents = findAllTelemetryEvents( const featureUsageEvents = findAllTelemetryEvents(
stderr, stderr,
......
...@@ -382,8 +382,8 @@ describe('Telemetry CLI', () => { ...@@ -382,8 +382,8 @@ describe('Telemetry CLI', () => {
expect(event1).toMatch(/"ssrPageCount": 3/) expect(event1).toMatch(/"ssrPageCount": 3/)
expect(event1).toMatch(/"staticPageCount": 5/) expect(event1).toMatch(/"staticPageCount": 5/)
expect(event1).toMatch(/"totalPageCount": 12/) expect(event1).toMatch(/"totalPageCount": 12/)
expect(event1).toMatch(/"totalAppPagesCount": 0/) expect(event1).toMatch(/"totalAppPagesCount": 3/)
expect(event1).toMatch(/"staticAppPagesCount": 0/) expect(event1).toMatch(/"staticAppPagesCount": 3/)
expect(event1).toMatch(/"serverAppPagesCount": 0/) expect(event1).toMatch(/"serverAppPagesCount": 0/)
expect(event1).toMatch(/"edgeRuntimeAppCount": 0/) expect(event1).toMatch(/"edgeRuntimeAppCount": 0/)
expect(event1).toMatch(/"edgeRuntimePagesCount": 2/) expect(event1).toMatch(/"edgeRuntimePagesCount": 2/)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment