diff --git a/packages/cli/src/commands/init/__tests__/init.test.ts b/packages/cli/src/commands/init/__tests__/init.test.ts new file mode 100644 index 000000000..62af44f84 --- /dev/null +++ b/packages/cli/src/commands/init/__tests__/init.test.ts @@ -0,0 +1,16 @@ +import initialize from '../init'; +import * as npm from '../../../tools/npm'; +import * as yarn from '../../../tools/yarn'; + +afterEach(() => { + jest.restoreAllMocks(); +}); + +test('rejects when the requested package manager is unavailable', async () => { + jest.spyOn(npm, 'npmResolveConcreteVersion').mockResolvedValue('0.76.0'); + jest.spyOn(yarn, 'getYarnVersionIfAvailable').mockReturnValue(null); + + await expect(initialize(['TestApp'], {pm: 'yarn'})).rejects.toThrowError( + 'Seems like the package manager you want to use is not installed.', + ); +}); diff --git a/packages/cli/src/commands/init/init.ts b/packages/cli/src/commands/init/init.ts index 20be2d731..d01547dca 100644 --- a/packages/cli/src/commands/init/init.ts +++ b/packages/cli/src/commands/init/init.ts @@ -498,10 +498,9 @@ export default (async function initialize( const projectFolder = path.join(root, directoryName); if (options.pm && !checkPackageManagerAvailability(options.pm)) { - logger.error( + throw new CLIError( 'Seems like the package manager you want to use is not installed. Please install it or choose another package manager.', ); - return; } let shouldBumpYarnVersion = true;