Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/composables/useInstallSizeDiff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ function getComparisonVersion(pkg: SlimPackument, resolvedVersion: string): stri
.sort((a, b) => compare(a, b))

const currentIdx = stableVersions.indexOf(resolvedVersion)
if (currentIdx <= 0) return null
// Don't compare the second version against the first as the first
// has no baseline so a large size difference is expected
if (currentIdx <= 1) return null

return stableVersions[currentIdx - 1]!
}
Expand Down
36 changes: 32 additions & 4 deletions test/nuxt/composables/use-install-size-diff.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,19 @@ describe('useInstallSizeDiff', () => {
expect(comparisonVersion.value).toBeNull()
})

it('returns null for the second stable version (no baseline for first)', () => {
const pkg = createPackage('test', {
'1.0.0': '2020-01-01',
'1.1.0': '2021-01-01',
})

const { comparisonVersion } = useInstallSizeDiff('test', '1.1.0', pkg, null)
expect(comparisonVersion.value).toBeNull()
})

it('skips prerelease versions when finding previous stable', () => {
const pkg = createPackage('test', {
'0.9.0': '2019-01-01',
'1.0.0': '2020-01-01',
'2.0.0-beta.1': '2021-01-01',
'2.0.0-beta.2': '2021-06-01',
Expand Down Expand Up @@ -117,6 +128,7 @@ describe('useInstallSizeDiff', () => {

it('returns null when both thresholds are not met', async () => {
const pkg = createPackage('pkg-no-threshold', {
'0.9.0': '2019-01-01',
'1.0.0': '2020-01-01',
'1.1.0': '2021-01-01',
})
Expand All @@ -140,7 +152,11 @@ describe('useInstallSizeDiff', () => {
})

it('sets sizeThresholdExceeded when size increased by more than 25%', async () => {
const pkg = createPackage('pkg-size-only', { '1.0.0': '2020-01-01', '1.1.0': '2021-01-01' })
const pkg = createPackage('pkg-size-only', {
'0.9.0': '2019-01-01',
'1.0.0': '2020-01-01',
'1.1.0': '2021-01-01',
})
const current = createInstallSize('pkg-size-only', {
version: '1.1.0',
totalSize: 7000,
Expand Down Expand Up @@ -172,7 +188,11 @@ describe('useInstallSizeDiff', () => {
})

it('sets depThresholdExceeded when more than 5 dependencies were added', async () => {
const pkg = createPackage('pkg-deps-only', { '1.0.0': '2020-01-01', '1.1.0': '2021-01-01' })
const pkg = createPackage('pkg-deps-only', {
'0.9.0': '2019-01-01',
'1.0.0': '2020-01-01',
'1.1.0': '2021-01-01',
})
const current = createInstallSize('pkg-deps-only', {
version: '1.1.0',
totalSize: 5100,
Expand Down Expand Up @@ -204,7 +224,11 @@ describe('useInstallSizeDiff', () => {
})

it('returns correct diff values', async () => {
const pkg = createPackage('pkg-both', { '1.0.0': '2020-01-01', '1.1.0': '2021-01-01' })
const pkg = createPackage('pkg-both', {
'0.9.0': '2019-01-01',
'1.0.0': '2020-01-01',
'1.1.0': '2021-01-01',
})
const current = createInstallSize('pkg-both', {
version: '1.1.0',
totalSize: 10000,
Expand Down Expand Up @@ -234,7 +258,11 @@ describe('useInstallSizeDiff', () => {

describe('fetch behavior', () => {
it('calls the correct API endpoint for the comparison version', async () => {
const pkg = createPackage('my-pkg', { '1.0.0': '2020-01-01', '1.1.0': '2021-01-01' })
const pkg = createPackage('my-pkg', {
'0.9.0': '2019-01-01',
'1.0.0': '2020-01-01',
'1.1.0': '2021-01-01',
})
const current = createInstallSize('my-pkg', { version: '1.1.0', totalSize: 7000 })
fetchSpy.mockResolvedValue(createInstallSize('my-pkg', { version: '1.0.0', totalSize: 5000 }))

Expand Down
Loading