Skip to content

Commit 95f2ab3

Browse files
Skip fetching notifications in CI/tests
1 parent 604a6bf commit 95f2ab3

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

packages/cli-kit/src/public/node/notifications-system.test.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,23 +426,27 @@ describe('showNotificationsIfNeeded', () => {
426426
describe('fetchNotificationsInBackground', () => {
427427
test('calls the expected Shopify binary for global installation', async () => {
428428
// Given / When
429-
fetchNotificationsInBackground('theme:init', ['shopify', 'theme', 'init'])
429+
fetchNotificationsInBackground('theme:init', ['shopify', 'theme', 'init'], {SHOPIFY_UNIT_TEST: 'false'})
430430

431431
// Then
432432
expect(exec).toHaveBeenCalledWith('shopify', ['notifications', 'list'], expect.anything())
433433
})
434434

435435
test('calls the expected Shopify binary for local installation', async () => {
436436
// Given / When
437-
fetchNotificationsInBackground('theme:init', ['npm', 'run', 'shopify', 'theme', 'init'])
437+
fetchNotificationsInBackground('theme:init', ['npm', 'run', 'shopify', 'theme', 'init'], {
438+
SHOPIFY_UNIT_TEST: 'false',
439+
})
438440

439441
// Then
440442
expect(exec).toHaveBeenCalledWith('npm', ['run', 'shopify', 'notifications', 'list'], expect.anything())
441443
})
442444

443445
test('calls the expected Shopify binary for dev environment', async () => {
444446
// Given / When
445-
fetchNotificationsInBackground('theme:init', ['node', 'packages/cli/bin/dev.js', 'theme', 'init'])
447+
fetchNotificationsInBackground('theme:init', ['node', 'packages/cli/bin/dev.js', 'theme', 'init'], {
448+
SHOPIFY_UNIT_TEST: 'false',
449+
})
446450

447451
// Then
448452
expect(exec).toHaveBeenCalledWith('node', ['packages/cli/bin/dev.js', 'notifications', 'list'], expect.anything())

packages/cli-kit/src/public/node/notifications-system.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import {outputDebug} from './output.js'
55
import {zod} from './schema.js'
66
import {AbortSilentError} from './error.js'
77
import {isTruthy} from './context/utilities.js'
8-
import {jsonOutputEnabled} from './environment.js'
98
import {exec} from './system.js'
9+
import {jsonOutputEnabled} from './environment.js'
1010
import {CLI_KIT_VERSION} from '../common/version.js'
1111
import {NotificationKey, NotificationsKey, cacheRetrieve, cacheStore} from '../../private/node/conf-store.js'
1212
import {fetch} from '@shopify/cli-kit/node/http'
@@ -55,7 +55,7 @@ export async function showNotificationsIfNeeded(
5555
environment: NodeJS.ProcessEnv = process.env,
5656
): Promise<void> {
5757
try {
58-
if (skipNotifications(environment)) return
58+
if (skipNotifications(environment) || jsonOutputEnabled(environment)) return
5959

6060
const notifications = await getNotifications()
6161
const commandId = getCurrentCommandId()
@@ -74,8 +74,8 @@ export async function showNotificationsIfNeeded(
7474
}
7575
}
7676

77-
function skipNotifications(environment: NodeJS.ProcessEnv): boolean {
78-
return isTruthy(environment.CI) || isTruthy(environment.SHOPIFY_UNIT_TEST) || jsonOutputEnabled(environment)
77+
function skipNotifications(environment: NodeJS.ProcessEnv = process.env): boolean {
78+
return isTruthy(environment.CI) || isTruthy(environment.SHOPIFY_UNIT_TEST)
7979
}
8080

8181
/**
@@ -152,8 +152,15 @@ async function cacheNotifications(notifications: string): Promise<void> {
152152
*
153153
* @param currentCommand - The current Shopify command being run.
154154
* @param argv - The arguments passed to the current process.
155+
* @param environment - Process environment variables.
155156
*/
156-
export function fetchNotificationsInBackground(currentCommand: string, argv = process.argv): void {
157+
export function fetchNotificationsInBackground(
158+
currentCommand: string,
159+
argv = process.argv,
160+
environment: NodeJS.ProcessEnv = process.env,
161+
): void {
162+
if (skipNotifications(environment)) return
163+
157164
let command = 'shopify'
158165
const args = ['notifications', 'list']
159166
// Run the Shopify command the same way as the current execution when it's not the global installation

0 commit comments

Comments
 (0)