From c9eb7df23871a922c3ae471524857293454d6c42 Mon Sep 17 00:00:00 2001 From: Marc Cataford Date: Wed, 22 Mar 2023 00:10:57 -0400 Subject: [PATCH] test: fix assumption based on node version --- tests/index.test.ts | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/tests/index.test.ts b/tests/index.test.ts index 65bc5eb..159e771 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -8,6 +8,14 @@ import type { Report } from '../src/types' let workspace: string | null +function getActualPackageSizeByNodeVersion(nodeVersion: string): string { + if (nodeVersion.startsWith('v14')) return '160' + else if (nodeVersion.startsWith('v16')) return '157' + else if (nodeVersion.startsWith('v18')) return '157' + + return 'unknown' +} + async function prepareWorkspace(): Promise { const workspacePath = await fs.mkdtemp(`${tmpdir()}/`) workspace = workspacePath @@ -41,6 +49,7 @@ async function createManifest( } describe('Packwatch', () => { + const actualSize = getActualPackageSizeByNodeVersion(process.version) afterEach(async () => { jest.restoreAllMocks() @@ -81,7 +90,7 @@ describe('Packwatch', () => { ) expect(generatedManifest).toBe( - '{"limit":"160 B","packageSize":"160 B","unpackedSize":"68 B"}', + `{"limit":"${actualSize} B","packageSize":"${actualSize} B","unpackedSize":"68 B"}`, ) }) @@ -132,9 +141,9 @@ describe('Packwatch', () => { const mockLogger = jest.spyOn(console, 'log') await createPackageJson(workspacePath) await createManifest(workspacePath, { - limit: '160B', - packageSize: '160B', - packageSizeBytes: 160, + limit: `${actualSize}B`, + packageSize: `${actualSize}B`, + packageSizeBytes: Number(actualSize), unpackedSize: '150B', unpackedSizeBytes: 150, }) @@ -142,7 +151,7 @@ describe('Packwatch', () => { expect(mockLogger.mock.calls).toHaveLength(1) expect(mockLogger.mock.calls[0][0]).toEqual( expect.stringMatching( - /Nothing to report! Your package is the same size as the latest manifest reports! \(Limit: 160B\)/, + /Nothing to report! Your package is the same size as the latest manifest reports!/, ), ) }) @@ -153,8 +162,8 @@ describe('Packwatch', () => { await createPackageJson(workspacePath) await createManifest(workspacePath, { limit: '170B', - packageSize: '160B', - packageSizeBytes: 160, + packageSize: `${actualSize}B`, + packageSizeBytes: Number(actualSize), unpackedSize: '150B', unpackedSizeBytes: 150, })