-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug in create CLI using
--install-deps
flag (#644)
* Fix bug in create CLI using `--install-deps` flag * Use flags to camel case util * Add tests for init --------- Co-authored-by: Matt Seccafien <[email protected]>
- Loading branch information
Showing
3 changed files
with
104 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@shopify/cli-hydrogen': patch | ||
--- | ||
|
||
Fix bug in CLI not recognising the --install-deps flag when creating projects |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import {describe, it, expect, vi, beforeEach} from 'vitest'; | ||
import {temporaryDirectoryTask} from 'tempy'; | ||
import {runInit} from './init.js'; | ||
import {ui} from '@shopify/cli-kit'; | ||
import {installNodeModules} from '@shopify/cli-kit/node/node-package-manager'; | ||
|
||
describe('init', () => { | ||
beforeEach(() => { | ||
vi.resetAllMocks(); | ||
vi.mock('@shopify/cli-kit'); | ||
vi.mock('../../utils/transpile-ts.js'); | ||
vi.mock('../../utils/template-downloader.js', async () => ({ | ||
getLatestTemplates: () => Promise.resolve({}), | ||
})); | ||
vi.mock('@shopify/cli-kit/node/node-package-manager'); | ||
vi.mocked(ui.prompt).mockImplementation(() => | ||
Promise.resolve({installDeps: 'false'}), | ||
); | ||
}); | ||
|
||
const defaultOptions = (stubs: Record<any, unknown>) => ({ | ||
template: 'hello-world', | ||
language: 'js', | ||
path: 'path/to/project', | ||
...stubs, | ||
}); | ||
|
||
describe('installDeps', () => { | ||
it('prompts the user to install dependencies when installDeps is not passed', async () => { | ||
await temporaryDirectoryTask(async (tmpDir) => { | ||
// Given | ||
const options = defaultOptions({path: tmpDir}); | ||
|
||
vi.mocked(ui.prompt).mockImplementation(() => | ||
Promise.resolve({installDeps: 'false'}), | ||
); | ||
|
||
// When | ||
await runInit(options); | ||
|
||
// Then | ||
expect(ui.prompt).toHaveBeenCalledWith( | ||
expect.arrayContaining([ | ||
expect.objectContaining({ | ||
name: 'installDeps', | ||
}), | ||
]), | ||
); | ||
expect(installNodeModules).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
it('does not prompt the user to install dependencies when installDeps is true', async () => { | ||
await temporaryDirectoryTask(async (tmpDir) => { | ||
// Given | ||
const options = defaultOptions({installDeps: true, path: tmpDir}); | ||
|
||
// When | ||
await runInit(options); | ||
|
||
// Then | ||
expect(ui.prompt).not.toHaveBeenCalledWith( | ||
expect.arrayContaining([ | ||
expect.objectContaining({ | ||
name: 'installDeps', | ||
}), | ||
]), | ||
); | ||
expect(installNodeModules).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
it('does not show a prompt to install dependencies when installDeps is false', async () => { | ||
await temporaryDirectoryTask(async (tmpDir) => { | ||
// Given | ||
const options = defaultOptions({installDeps: false, path: tmpDir}); | ||
|
||
// When | ||
await runInit(options); | ||
|
||
// Then | ||
expect(ui.prompt).not.toHaveBeenCalledWith( | ||
expect.arrayContaining([ | ||
expect.objectContaining({ | ||
name: 'installDeps', | ||
}), | ||
]), | ||
); | ||
expect(installNodeModules).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters