Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 47 additions & 2 deletions packages/cli-kit/src/public/node/is-global.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import {currentProcessIsGlobal, inferPackageManagerForGlobalCLI, installGlobalCLIPrompt} from './is-global.js'
import {
currentProcessIsGlobal,
inferPackageManagerForGlobalCLI,
installGlobalCLIPrompt,
installGlobalShopifyCLI,
} from './is-global.js'
import {findPathUpSync} from './fs.js'
import {cwd} from './path.js'
import {terminalSupportsPrompting} from './system.js'
import {exec, terminalSupportsPrompting} from './system.js'
import {renderSelectPrompt} from './ui.js'
import {globalCLIVersion} from './version.js'
import {outputInfo} from './output.js'
import {beforeEach, describe, expect, test, vi} from 'vitest'
import {realpathSync} from 'fs'

vi.mock('./system.js')
vi.mock('./ui.js')
vi.mock('which')
vi.mock('./version.js')
vi.mock('./output.js')

// Mock fs.js to make findPathUpSync controllable for getProjectDir.
// find-up v6 runs returned paths through locatePathSync which checks file existence,
Expand Down Expand Up @@ -323,3 +330,41 @@ describe('installGlobalCLIPrompt', () => {
expect(got).toEqual({install: false, alreadyInstalled: false})
})
})

describe('installGlobalShopifyCLI', () => {
test('calls exec with the correct arguments when using yarn', async () => {
// Given
vi.mocked(exec).mockResolvedValue(undefined)

// When
await installGlobalShopifyCLI('yarn')

// Then
expect(outputInfo).toHaveBeenCalledWith('Running yarn global add @shopify/cli@latest...')
expect(exec).toHaveBeenCalledWith('yarn', ['global', 'add', '@shopify/cli@latest'], {stdio: 'inherit'})
})

test('calls exec with the correct arguments when using npm', async () => {
// Given
vi.mocked(exec).mockResolvedValue(undefined)

// When
await installGlobalShopifyCLI('npm')

// Then
expect(outputInfo).toHaveBeenCalledWith('Running npm install -g @shopify/cli@latest...')
expect(exec).toHaveBeenCalledWith('npm', ['install', '-g', '@shopify/cli@latest'], {stdio: 'inherit'})
})

test('calls exec with the correct arguments when using pnpm', async () => {
// Given
vi.mocked(exec).mockResolvedValue(undefined)

// When
await installGlobalShopifyCLI('pnpm')

// Then
expect(outputInfo).toHaveBeenCalledWith('Running pnpm install -g @shopify/cli@latest...')
expect(exec).toHaveBeenCalledWith('pnpm', ['install', '-g', '@shopify/cli@latest'], {stdio: 'inherit'})
})
})
Loading