Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Nov 11, 2022
1 parent 9adedac commit 8faa747
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
19 changes: 12 additions & 7 deletions packages/next/build/webpack/plugins/middleware-plugin.ts
Expand Up @@ -683,6 +683,7 @@ function getExtractMetadata(params: {
wasmBindings: new Map(),
assetBindings: new Map(),
}
let ogImageGenerationCount = 0

for (const module of modules) {
const buildInfo = getModuleBuildInfo(module)
Expand All @@ -697,13 +698,10 @@ function getExtractMetadata(params: {
/[\\/]node_modules[\\/]@vercel[\\/]og[\\/]dist[\\/]index.js$/.test(
resource
)
telemetry.record({
eventName: EVENT_BUILD_FEATURE_USAGE,
payload: {
featureName: 'vercelImageGeneration',
invocationCount: hasOGImageGeneration ? 1 : 0,
},
})

if (hasOGImageGeneration) {
ogImageGenerationCount++
}
}

/**
Expand Down Expand Up @@ -818,6 +816,13 @@ function getExtractMetadata(params: {
}
}

telemetry.record({
eventName: EVENT_BUILD_FEATURE_USAGE,
payload: {
featureName: 'vercelImageGeneration',
invocationCount: ogImageGenerationCount,
},
})
metadataByEntry.set(entryName, entryMetadata)
}
}
Expand Down
17 changes: 12 additions & 5 deletions test/integration/telemetry/test/index.test.js
Expand Up @@ -834,6 +834,7 @@ describe('Telemetry CLI', () => {
stderr,
'NEXT_BUILD_FEATURE_USAGE'
)

expect(featureUsageEvents).toEqual(
expect.arrayContaining([
{
Expand All @@ -842,7 +843,7 @@ describe('Telemetry CLI', () => {
},
{
featureName: 'next/image',
invocationCount: 1,
invocationCount: 2,
},
{
featureName: 'next/script',
Expand Down Expand Up @@ -871,8 +872,14 @@ describe('Telemetry CLI', () => {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
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.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'
Expand Down Expand Up @@ -1047,11 +1054,11 @@ describe('Telemetry CLI', () => {
)
expect(featureUsageEvents).toContainEqual({
featureName: 'next/legacy/image',
invocationCount: 1,
invocationCount: 2,
})
expect(featureUsageEvents).toContainEqual({
featureName: 'next/image',
invocationCount: 1,
invocationCount: 2,
})
})

Expand Down

0 comments on commit 8faa747

Please sign in to comment.