Skip to content

Commit

Permalink
Turbopack build: Skip irrelevant telemetry tests (#69671)
Browse files Browse the repository at this point in the history
Similar to #68969, skips a few more tests that are checking features
that we don't have to report on.

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->
  • Loading branch information
timneutkens committed Sep 5, 2024
1 parent 668558a commit 8662ba0
Show file tree
Hide file tree
Showing 3 changed files with 269 additions and 229 deletions.
368 changes: 200 additions & 168 deletions test/integration/telemetry/test/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,95 +264,105 @@ describe('config telemetry', () => {
expect(event1).toMatch(/"@next\/next\/.+?": "(off|warn|error)"/)
})

it('emits telemery for usage of image, script & dynamic', async () => {
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
lint: true,
})
const featureUsageEvents = findAllTelemetryEvents(
stderr,
'NEXT_BUILD_FEATURE_USAGE'
)

expect(featureUsageEvents).toEqual(
expect.arrayContaining([
{
featureName: 'next/image',
invocationCount: 2,
},
{
featureName: 'next/script',
invocationCount: 1,
},
{
featureName: 'next/dynamic',
invocationCount: 1,
},
])
)
})
// Turbopack intentionally does not support these events
;(process.env.TURBOPACK ? it.skip : it)(
'emits telemery for usage of image, script & dynamic',
async () => {
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
lint: true,
})
const featureUsageEvents = findAllTelemetryEvents(
stderr,
'NEXT_BUILD_FEATURE_USAGE'
)

it('emits telemetry for usage of swc', async () => {
await fs.remove(path.join(appDir, 'next.config.js'))
await fs.remove(path.join(appDir, 'jsconfig.json'))
await fs.rename(
path.join(appDir, 'next.config.swc'),
path.join(appDir, 'next.config.js')
)
await fs.rename(
path.join(appDir, 'jsconfig.swc'),
path.join(appDir, 'jsconfig.json')
)
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
await fs.rename(
path.join(appDir, 'next.config.js'),
path.join(appDir, 'next.config.swc')
)
await fs.rename(
path.join(appDir, 'jsconfig.json'),
path.join(appDir, 'jsconfig.swc')
)
const featureUsageEvents = findAllTelemetryEvents(
stderr,
'NEXT_BUILD_FEATURE_USAGE'
)
expect(featureUsageEvents).toEqual(
expect.arrayContaining([
{
featureName: 'swcLoader',
invocationCount: 1,
},
{
featureName: 'swcRelay',
invocationCount: 1,
},
{
featureName: 'swcStyledComponents',
invocationCount: 1,
},
{
featureName: 'swcReactRemoveProperties',
invocationCount: 1,
},
{
featureName: 'swcExperimentalDecorators',
invocationCount: 1,
},
{
featureName: 'swcRemoveConsole',
invocationCount: 1,
},
{
featureName: 'swcImportSource',
invocationCount: 0,
},
])
)
})
// eslint-disable-next-line jest/no-standalone-expect
expect(featureUsageEvents).toEqual(
expect.arrayContaining([
{
featureName: 'next/image',
invocationCount: 2,
},
{
featureName: 'next/script',
invocationCount: 1,
},
{
featureName: 'next/dynamic',
invocationCount: 1,
},
])
)
}
)

// Turbopack intentionally does not support these events
;(process.env.TURBOPACK ? it.skip : it)(
'emits telemetry for usage of swc',
async () => {
await fs.remove(path.join(appDir, 'next.config.js'))
await fs.remove(path.join(appDir, 'jsconfig.json'))
await fs.rename(
path.join(appDir, 'next.config.swc'),
path.join(appDir, 'next.config.js')
)
await fs.rename(
path.join(appDir, 'jsconfig.swc'),
path.join(appDir, 'jsconfig.json')
)
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
await fs.rename(
path.join(appDir, 'next.config.js'),
path.join(appDir, 'next.config.swc')
)
await fs.rename(
path.join(appDir, 'jsconfig.json'),
path.join(appDir, 'jsconfig.swc')
)
const featureUsageEvents = findAllTelemetryEvents(
stderr,
'NEXT_BUILD_FEATURE_USAGE'
)
// eslint-disable-next-line jest/no-standalone-expect
expect(featureUsageEvents).toEqual(
expect.arrayContaining([
{
featureName: 'swcLoader',
invocationCount: 1,
},
{
featureName: 'swcRelay',
invocationCount: 1,
},
{
featureName: 'swcStyledComponents',
invocationCount: 1,
},
{
featureName: 'swcReactRemoveProperties',
invocationCount: 1,
},
{
featureName: 'swcExperimentalDecorators',
invocationCount: 1,
},
{
featureName: 'swcRemoveConsole',
invocationCount: 1,
},
{
featureName: 'swcImportSource',
invocationCount: 0,
},
])
)
}
)

it('emits telemetry for usage of `optimizeCss`', async () => {
await fs.rename(
Expand Down Expand Up @@ -478,95 +488,117 @@ describe('config telemetry', () => {
])
})

it('emits telemetry for usage of next/legacy/image', async () => {
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
const featureUsageEvents = findAllTelemetryEvents(
stderr,
'NEXT_BUILD_FEATURE_USAGE'
)
expect(featureUsageEvents).toContainEqual({
featureName: 'next/legacy/image',
invocationCount: 2,
})
expect(featureUsageEvents).toContainEqual({
featureName: 'next/image',
invocationCount: 2,
})
})
// Turbopack intentionally does not support these events
;(process.env.TURBOPACK ? it.skip : it)(
'emits telemetry for usage of next/legacy/image',
async () => {
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
const featureUsageEvents = findAllTelemetryEvents(
stderr,
'NEXT_BUILD_FEATURE_USAGE'
)
// eslint-disable-next-line jest/no-standalone-expect
expect(featureUsageEvents).toContainEqual({
featureName: 'next/legacy/image',
invocationCount: 2,
})
// eslint-disable-next-line jest/no-standalone-expect
expect(featureUsageEvents).toContainEqual({
featureName: 'next/image',
invocationCount: 2,
})
}
)

it('emits telemetry for usage of @vercel/og', async () => {
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
const featureUsageEvents = findAllTelemetryEvents(
stderr,
'NEXT_BUILD_FEATURE_USAGE'
)
expect(featureUsageEvents).toContainEqual({
featureName: 'vercelImageGeneration',
invocationCount: 1,
})
})
// Turbopack intentionally does not support these events
;(process.env.TURBOPACK ? it.skip : it)(
'emits telemetry for usage of @vercel/og',
async () => {
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
const featureUsageEvents = findAllTelemetryEvents(
stderr,
'NEXT_BUILD_FEATURE_USAGE'
)
// eslint-disable-next-line jest/no-standalone-expect
expect(featureUsageEvents).toContainEqual({
featureName: 'vercelImageGeneration',
invocationCount: 1,
})
}
)

it('emits telemetry for transpilePackages', async () => {
await fs.rename(
path.join(appDir, 'next.config.transpile-packages'),
path.join(appDir, 'next.config.js')
)
// Turbopack intentionally does not support these events
;(process.env.TURBOPACK ? it.skip : it)(
'emits telemetry for transpilePackages',
async () => {
await fs.rename(
path.join(appDir, 'next.config.transpile-packages'),
path.join(appDir, 'next.config.js')
)

const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})

await fs.rename(
path.join(appDir, 'next.config.js'),
path.join(appDir, 'next.config.transpile-packages')
)
await fs.rename(
path.join(appDir, 'next.config.js'),
path.join(appDir, 'next.config.transpile-packages')
)

const featureUsageEvents = findAllTelemetryEvents(
stderr,
'NEXT_BUILD_FEATURE_USAGE'
)
expect(featureUsageEvents).toContainEqual({
featureName: 'transpilePackages',
invocationCount: 1,
})
})
const featureUsageEvents = findAllTelemetryEvents(
stderr,
'NEXT_BUILD_FEATURE_USAGE'
)
// eslint-disable-next-line jest/no-standalone-expect
expect(featureUsageEvents).toContainEqual({
featureName: 'transpilePackages',
invocationCount: 1,
})
}
)

it('emits telemetry for middleware related options', async () => {
await fs.rename(
path.join(appDir, 'next.config.middleware-options'),
path.join(appDir, 'next.config.js')
)
// Turbopack intentionally does not support these events
;(process.env.TURBOPACK ? it.skip : it)(
'emits telemetry for middleware related options',
async () => {
await fs.rename(
path.join(appDir, 'next.config.middleware-options'),
path.join(appDir, 'next.config.js')
)

const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})

await fs.rename(
path.join(appDir, 'next.config.js'),
path.join(appDir, 'next.config.middleware-options')
)
await fs.rename(
path.join(appDir, 'next.config.js'),
path.join(appDir, 'next.config.middleware-options')
)

const featureUsageEvents = findAllTelemetryEvents(
stderr,
'NEXT_BUILD_FEATURE_USAGE'
)
expect(featureUsageEvents).toContainEqual({
featureName: 'skipMiddlewareUrlNormalize',
invocationCount: 1,
})
expect(featureUsageEvents).toContainEqual({
featureName: 'skipTrailingSlashRedirect',
invocationCount: 1,
})
})
const featureUsageEvents = findAllTelemetryEvents(
stderr,
'NEXT_BUILD_FEATURE_USAGE'
)
// eslint-disable-next-line jest/no-standalone-expect
expect(featureUsageEvents).toContainEqual({
featureName: 'skipMiddlewareUrlNormalize',
invocationCount: 1,
})
// eslint-disable-next-line jest/no-standalone-expect
expect(featureUsageEvents).toContainEqual({
featureName: 'skipTrailingSlashRedirect',
invocationCount: 1,
})
}
)

it('emits telemetry for default React Compiler options', async () => {
const { stderr } = await nextBuild(appDir, [], {
Expand Down
Loading

0 comments on commit 8662ba0

Please sign in to comment.