From aa6cb2432e63d899a28cef36e60cb544842cd162 Mon Sep 17 00:00:00 2001 From: Raine Revere Date: Sun, 5 Nov 2023 20:59:58 +0000 Subject: [PATCH] npm: Throw a proper error when no mock version is provided. getPackageVersionProtected does catch any errors, but it rethrows them if they are not 404's. --- src/package-managers/npm.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/package-managers/npm.ts b/src/package-managers/npm.ts index dc76852d..add44429 100644 --- a/src/package-managers/npm.ts +++ b/src/package-managers/npm.ts @@ -267,7 +267,7 @@ export async function packageAuthorChanged( } /** Returns true if an object is a Packument. */ -const isPackument = (o: any): o is Partial => o && (o.name || o.engines || o.version || o.versions) +const isPackument = (o: any): o is Partial => !!(o && (o.name || o.engines || o.version || o.versions)) /** Creates a function with the same signature as viewMany that always returns the given versions. */ export const mockViewMany = @@ -283,11 +283,10 @@ export const mockViewMany = const version = isPackument(partialPackument) ? partialPackument.version : partialPackument - // if there is no version, hard exit - // otherwise getPackageProtected will swallow the error if (!version) { - console.error(`No mock version supplied for ${name}`) - process.exit(1) + throw new Error( + `viewMany is mocked, but no mock version was supplied for ${name}. Make sure that all dependencies are mocked. `, + ) } const time = (isPackument(partialPackument) && partialPackument.time?.[version]) || new Date().toISOString()