From 929e2ac792370f252605c338a041dec4fa13d87c Mon Sep 17 00:00:00 2001 From: Ash Date: Sun, 17 Dec 2023 12:43:52 +0000 Subject: [PATCH] test(cli): override CI environment variable when testing functionality that depends on it --- .../cli/src/util/createTelemetryStore.ts | 2 +- packages/@sanity/cli/test/telemetry.test.ts | 68 ++++++++++++++++--- 2 files changed, 58 insertions(+), 12 deletions(-) diff --git a/packages/@sanity/cli/src/util/createTelemetryStore.ts b/packages/@sanity/cli/src/util/createTelemetryStore.ts index 0ea4af0ce211..0c6f1b09d774 100644 --- a/packages/@sanity/cli/src/util/createTelemetryStore.ts +++ b/packages/@sanity/cli/src/util/createTelemetryStore.ts @@ -82,7 +82,7 @@ export type ConsentInformation = export function resolveConsent({env}: Options): Promise { debug('Resolving consent…') - if (isCi) { + if (isTrueish(isCi)) { debug('CI environment detected, treating telemetry consent as denied') return Promise.resolve({status: 'denied'}) } diff --git a/packages/@sanity/cli/test/telemetry.test.ts b/packages/@sanity/cli/test/telemetry.test.ts index 5fb6f8ea25d5..8efb69ed911d 100644 --- a/packages/@sanity/cli/test/telemetry.test.ts +++ b/packages/@sanity/cli/test/telemetry.test.ts @@ -1,10 +1,19 @@ -import {describeCliTest, testConcurrent} from './shared/describe' +import {describeCliTest} from './shared/describe' import {runSanityCmdCommand} from './shared/environment' describeCliTest('CLI: `sanity telemetry status`', () => { test('sanity telemetry status: granted', async () => { - await runSanityCmdCommand('v3', ['telemetry', 'enable']) - const result = await runSanityCmdCommand('v3', ['telemetry', 'status']) + await runSanityCmdCommand('v3', ['telemetry', 'enable'], { + env: { + CI: 'false', + }, + }) + + const result = await runSanityCmdCommand('v3', ['telemetry', 'status'], { + env: { + CI: 'false', + }, + }) expect(result.stdout).toMatchInlineSnapshot(` "Status: Enabled @@ -18,8 +27,17 @@ https://www.sanity.io/telemetry }) test('sanity telemetry status: denied', async () => { - await runSanityCmdCommand('v3', ['telemetry', 'disable']) - const result = await runSanityCmdCommand('v3', ['telemetry', 'status']) + await runSanityCmdCommand('v3', ['telemetry', 'disable'], { + env: { + CI: 'false', + }, + }) + + const result = await runSanityCmdCommand('v3', ['telemetry', 'status'], { + env: { + CI: 'false', + }, + }) expect(result.stdout).toMatchInlineSnapshot(` "Status: Disabled @@ -36,6 +54,7 @@ https://www.sanity.io/telemetry test('sanity telemetry status: denied using DO_NOT_TRACK', async () => { const result = await runSanityCmdCommand('v3', ['telemetry', 'status'], { env: { + CI: 'false', DO_NOT_TRACK: '1', }, }) @@ -57,8 +76,17 @@ https://www.sanity.io/telemetry describeCliTest('CLI: `sanity telemetry enable`', () => { test('sanity telemetry enable: success', async () => { - await runSanityCmdCommand('v3', ['telemetry', 'disable']) - const result = await runSanityCmdCommand('v3', ['telemetry', 'enable']) + await runSanityCmdCommand('v3', ['telemetry', 'disable'], { + env: { + CI: 'false', + }, + }) + + const result = await runSanityCmdCommand('v3', ['telemetry', 'enable'], { + env: { + CI: 'false', + }, + }) expect(result.stdout).toMatchInlineSnapshot(` "Status: Enabled @@ -72,7 +100,11 @@ https://www.sanity.io/telemetry }) test('sanity telemetry enable: success (already enabled)', async () => { - const result = await runSanityCmdCommand('v3', ['telemetry', 'enable']) + const result = await runSanityCmdCommand('v3', ['telemetry', 'enable'], { + env: { + CI: 'false', + }, + }) expect(result.stdout).toMatchInlineSnapshot(` "Status: Enabled @@ -88,8 +120,17 @@ https://www.sanity.io/telemetry describeCliTest('CLI: `sanity telemetry disable`', () => { test('sanity telemetry disable: success', async () => { - await runSanityCmdCommand('v3', ['telemetry', 'enable']) - const result = await runSanityCmdCommand('v3', ['telemetry', 'disable']) + await runSanityCmdCommand('v3', ['telemetry', 'enable'], { + env: { + CI: 'false', + }, + }) + + const result = await runSanityCmdCommand('v3', ['telemetry', 'disable'], { + env: { + CI: 'false', + }, + }) expect(result.stdout).toMatchInlineSnapshot(` "Status: Disabled @@ -104,7 +145,11 @@ https://www.sanity.io/telemetry }) test('sanity telemetry disable: success (already denied)', async () => { - const result = await runSanityCmdCommand('v3', ['telemetry', 'disable']) + const result = await runSanityCmdCommand('v3', ['telemetry', 'disable'], { + env: { + CI: 'false', + }, + }) expect(result.stdout).toMatchInlineSnapshot(` "Status: Disabled @@ -121,6 +166,7 @@ https://www.sanity.io/telemetry test('sanity telemetry disable: success (already denied using DO_NOT_TRACK)', async () => { const result = await runSanityCmdCommand('v3', ['telemetry', 'disable'], { env: { + CI: 'false', DO_NOT_TRACK: '1', }, })