diff --git a/packages/next/telemetry/storage.ts b/packages/next/telemetry/storage.ts index 8c2274378028619..00ba9f9071bc53e 100644 --- a/packages/next/telemetry/storage.ts +++ b/packages/next/telemetry/storage.ts @@ -152,7 +152,11 @@ export class Telemetry { } get isEnabled(): boolean { - return !!this.conf && this.conf.get(TELEMETRY_KEY_ENABLED, true) !== false + return ( + !this.NEXT_TELEMETRY_DISABLED && + !!this.conf && + this.conf.get(TELEMETRY_KEY_ENABLED, true) !== false + ) } oneWayHash = (payload: BinaryLike): string => { diff --git a/test/integration/telemetry/test/index.test.js b/test/integration/telemetry/test/index.test.js index 3558f6360ab4925..0f3abcca358831a 100644 --- a/test/integration/telemetry/test/index.test.js +++ b/test/integration/telemetry/test/index.test.js @@ -72,6 +72,18 @@ describe('Telemetry CLI', () => { expect(stdout).toMatch(/Status: Disabled/) }) + it('can disable telemetry with env NEXT_TELEMETRY_DISABLED', async () => { + // next config is not reset between tests + await runNextCommand(['telemetry', 'enable']) + const { stdout } = await runNextCommand(['telemetry', 'status'], { + stdout: true, + env: { + NEXT_TELEMETRY_DISABLED: '1', + }, + }) + expect(stdout).toMatch(/Status: Disabled/) + }) + it('detects isSrcDir dir correctly for `next build`', async () => { // must clear cache for GSSP imports to be detected correctly await fs.remove(path.join(appDir, '.next'))