Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add telemetry for @next/font (#42579)
## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have a helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have a helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `pnpm build && pnpm lint` - [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
- Loading branch information
Hannes Bornö
committed
Nov 8, 2022
1 parent
90ddc24
commit 81890c8
Showing
11 changed files
with
204 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module.exports = { | ||
'https://fonts.googleapis.com/css2?family=Open+Sans:wght@300..800&display=optional': ` | ||
/* latin */ | ||
@font-face { | ||
font-family: 'Open Sans'; | ||
font-style: normal; | ||
font-weight: 300 800; | ||
font-stretch: 100%; | ||
font-display: optional; | ||
src: url(https://fonts.gstatic.com/s/opensans/v34/memvYaGs126MiZpBA-UvWbX2vVnXBbObj2OVTS-mu0SC55I.woff2) format('woff2'); | ||
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; | ||
} | ||
`, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { createNext, FileRef } from 'e2e-utils' | ||
import { NextInstance } from 'test/lib/next-modes/base' | ||
import { findAllTelemetryEvents } from 'next-test-utils' | ||
import { join } from 'path' | ||
|
||
const mockedGoogleFontResponses = require.resolve( | ||
'./google-font-mocked-responses.js' | ||
) | ||
|
||
describe('@next/font used telemetry', () => { | ||
let next: NextInstance | ||
|
||
beforeAll(async () => { | ||
next = await createNext({ | ||
files: { | ||
pages: new FileRef(join(__dirname, 'telemetry/pages')), | ||
'next.config.js': new FileRef( | ||
join(__dirname, 'telemetry/next.config.js') | ||
), | ||
}, | ||
dependencies: { | ||
'@next/font': 'canary', | ||
}, | ||
env: { | ||
NEXT_FONT_GOOGLE_MOCKED_RESPONSES: mockedGoogleFontResponses, | ||
NEXT_TELEMETRY_DEBUG: '1', | ||
}, | ||
}) | ||
}) | ||
afterAll(() => next.destroy()) | ||
|
||
it('should send @next/font/google and @next/font/local usage event', async () => { | ||
const events = findAllTelemetryEvents( | ||
next.cliOutput, | ||
'NEXT_BUILD_FEATURE_USAGE' | ||
) | ||
expect(events).toContainEqual({ | ||
featureName: '@next/font/google', | ||
invocationCount: 1, | ||
}) | ||
expect(events).toContainEqual({ | ||
featureName: '@next/font/local', | ||
invocationCount: 1, | ||
}) | ||
}) | ||
}) | ||
|
||
describe('@next/font unused telemetry', () => { | ||
let next: NextInstance | ||
|
||
beforeAll(async () => { | ||
next = await createNext({ | ||
files: { | ||
pages: new FileRef(join(__dirname, 'telemetry/pages-unused')), | ||
'next.config.js': new FileRef( | ||
join(__dirname, 'telemetry/next.config.js') | ||
), | ||
}, | ||
dependencies: { | ||
'@next/font': 'canary', | ||
}, | ||
env: { | ||
NEXT_FONT_GOOGLE_MOCKED_RESPONSES: mockedGoogleFontResponses, | ||
NEXT_TELEMETRY_DEBUG: '1', | ||
}, | ||
}) | ||
}) | ||
afterAll(() => next.destroy()) | ||
|
||
it('should not send @next/font/google and @next/font/local usage event', async () => { | ||
const events = findAllTelemetryEvents( | ||
next.cliOutput, | ||
'NEXT_BUILD_FEATURE_USAGE' | ||
) | ||
expect(events).toContainEqual({ | ||
featureName: '@next/font/google', | ||
invocationCount: 0, | ||
}) | ||
expect(events).toContainEqual({ | ||
featureName: '@next/font/local', | ||
invocationCount: 0, | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module.exports = { | ||
experimental: { | ||
fontLoaders: [ | ||
{ | ||
loader: '@next/font/google', | ||
options: { subsets: ['latin'] }, | ||
}, | ||
{ | ||
loader: '@next/font/local', | ||
}, | ||
], | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Page() { | ||
return <p>Hello world</p> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import localFont from '@next/font/local' | ||
|
||
const myFont = localFont({ src: './my-font.woff2' }) | ||
|
||
function MyApp({ Component, pageProps }) { | ||
return ( | ||
<div className={myFont.className}> | ||
<Component {...pageProps} /> | ||
</div> | ||
) | ||
} | ||
|
||
export default MyApp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Open_Sans } from '@next/font/google' | ||
const openSans = Open_Sans({ subsets: ['latin'] }) | ||
|
||
export default function Page() { | ||
return ( | ||
<> | ||
<p>Hello world 1</p> | ||
<p className={openSans.className}>Hello world 2</p> | ||
</> | ||
) | ||
} |
Binary file not shown.