From 7a27d0956e0cbcdabed845f65bec50975f2a5c0b Mon Sep 17 00:00:00 2001 From: Gonzalo Riestra Date: Fri, 22 Nov 2024 17:55:19 +0100 Subject: [PATCH] Skip notifications check on CI and tests --- .../cli-kit/src/public/node/notifications-system.test.ts | 6 +++--- packages/cli-kit/src/public/node/notifications-system.ts | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/cli-kit/src/public/node/notifications-system.test.ts b/packages/cli-kit/src/public/node/notifications-system.test.ts index f07b422335..974d522cc4 100644 --- a/packages/cli-kit/src/public/node/notifications-system.test.ts +++ b/packages/cli-kit/src/public/node/notifications-system.test.ts @@ -334,7 +334,7 @@ describe('notifications-system', () => { vi.mocked(cacheRetrieveOrRepopulate).mockResolvedValue(JSON.stringify({notifications})) // When - await showNotificationsIfNeeded() + await showNotificationsIfNeeded(undefined, {SHOPIFY_UNIT_TEST: 'false'}) // Then expect(renderInfo).toHaveBeenCalled() @@ -346,7 +346,7 @@ describe('notifications-system', () => { vi.mocked(cacheRetrieveOrRepopulate).mockResolvedValue(JSON.stringify({notifications})) // When - await showNotificationsIfNeeded() + await showNotificationsIfNeeded(undefined, {SHOPIFY_UNIT_TEST: 'false'}) // Then expect(renderWarning).toHaveBeenCalled() @@ -358,7 +358,7 @@ describe('notifications-system', () => { vi.mocked(cacheRetrieveOrRepopulate).mockResolvedValue(JSON.stringify({notifications})) // When - await expect(showNotificationsIfNeeded()).rejects.toThrowError() + await expect(showNotificationsIfNeeded(undefined, {SHOPIFY_UNIT_TEST: 'false'})).rejects.toThrowError() // Then expect(renderError).toHaveBeenCalled() diff --git a/packages/cli-kit/src/public/node/notifications-system.ts b/packages/cli-kit/src/public/node/notifications-system.ts index b6ab7cc637..b382dafb2a 100644 --- a/packages/cli-kit/src/public/node/notifications-system.ts +++ b/packages/cli-kit/src/public/node/notifications-system.ts @@ -4,6 +4,7 @@ import {getCurrentCommandId} from './global-context.js' import {outputDebug} from './output.js' import {zod} from './schema.js' import {AbortSilentError} from './error.js' +import {isTruthy} from './context/utilities.js' import {CLI_KIT_VERSION} from '../common/version.js' import { NotificationKey, @@ -50,10 +51,13 @@ export type Notifications = zod.infer * Shows notifications to the user if they meet the criteria specified in the notifications.json file. * * @param currentSurfaces - The surfaces present in the current project (usually for app extensions). + * @param environment - Process environment variables. * @returns - A promise that resolves when the notifications have been shown. */ -export async function showNotificationsIfNeeded(currentSurfaces?: string[]): Promise { +export async function showNotificationsIfNeeded(currentSurfaces?: string[], environment = process.env): Promise { try { + if (isTruthy(environment.CI) || isTruthy(environment.SHOPIFY_UNIT_TEST)) return + const notifications = await getNotifications() const commandId = getCurrentCommandId() const notificationsToShow = filterNotifications(notifications.notifications, commandId, currentSurfaces)