test: fix assumption based on node version

This commit is contained in:
Marc 2023-03-22 00:10:57 -04:00
parent 4b45d80f26
commit c9eb7df238
Signed by: marc
GPG key ID: 048E042F22B5DC79

View file

@ -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<string> {
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,
})