From dd8958875fb2f0342aa1f93e492baf09a4798417 Mon Sep 17 00:00:00 2001 From: Marc Cataford Date: Fri, 19 Feb 2021 09:49:13 -0500 Subject: [PATCH] refactor: error behaviour on limit exceeded --- src/__tests__/index.test.ts | 4 +++- src/index.ts | 8 +++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/__tests__/index.test.ts b/src/__tests__/index.test.ts index f9cacdf..b6d789c 100644 --- a/src/__tests__/index.test.ts +++ b/src/__tests__/index.test.ts @@ -204,7 +204,9 @@ describe('Packwatch', () => { unpackedSize: '140B', }) - await packwatch({ cwd: workspacePath }) + await expect(async () => + packwatch({ cwd: workspacePath }), + ).rejects.toThrow('PACKAGE_EXCEEDS_LIMIT') expect(mockLogger.mock.calls).toHaveLength(1) expect(mockLogger.mock.calls[0][0]).toEqual( expect.stringMatching( diff --git a/src/index.ts b/src/index.ts index f464536..670f70c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -36,11 +36,9 @@ export default async function packwatch({ console.log( '❗ It looks like you ran PackWatch without a manifest. To prevent accidental passes in CI or hooks, packwatch will terminate with an error. If you are running packwatch for the first time in your project, this is expected!', ) + throw new Error('NO_MANIFEST_NO_UPDATE') } - // If the update flag wasn't specified, exit with a non-zero code so we - // don't "accidentally" pass CI builds if the manifest didn't exist - if (!isUpdatingManifest) throw new Error() - else return + return } const previousStats = getPreviousPackageStats(cwd) @@ -79,7 +77,7 @@ export default async function packwatch({ console.log( `🔥🔥📦🔥🔥 Your package exceeds the limit set in ${MANIFEST_FILENAME}! ${packageSize} > ${limit}\nEither update the limit by using the --update-manifest flag or trim down your packed files!`, ) - return + throw new Error('PACKAGE_EXCEEDS_LIMIT') } /*