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
2 changes: 1 addition & 1 deletion server/api/registry/analysis/[...pkg].get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default defineCachedEventHandler(

try {
const { packageName, version } = v.parse(PackageRouteParamsSchema, {
packageName: rawPackageName,
packageName: decodeURIComponent(rawPackageName),
version: rawVersion,
})

Expand Down
2 changes: 1 addition & 1 deletion server/api/registry/install-size/[...pkg].get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default defineCachedEventHandler(

try {
const { packageName, version: requestedVersion } = v.parse(PackageRouteParamsSchema, {
packageName: rawPackageName,
packageName: decodeURIComponent(rawPackageName),
version: rawVersion,
})

Expand Down
42 changes: 42 additions & 0 deletions test/e2e/interactions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,48 @@ test.describe('Compare Page', () => {
const noDepColumn = grid.locator('.comparison-cell-nodep')
await expect(noDepColumn).toBeVisible()
})

test('loads install-size data for a scoped package', async ({ page, goto }) => {
// Intercept the internal API call the browser makes for install-size.
// The browser will request /api/registry/install-size/@nuxt%2Fkit (encoded slash).
// Before the fix this would fail to parse and return an error; after it returns 200.
const installSizeResponse = page.waitForResponse(
res =>
res.url().includes('/api/registry/install-size/') &&
res.url().includes('nuxt') &&
res.request().method() === 'GET',
{ timeout: 20_000 },
)

await goto('/compare?packages=@nuxt/kit,vue', { waitUntil: 'hydration' })

const response = await installSizeResponse
expect(response.status()).toBe(200)

const body = await response.json()
// The API should return a valid install size object, not an error
expect(body).toHaveProperty('selfSize')
expect(body).toHaveProperty('totalSize')
})

test('loads analysis data for a scoped package', async ({ page, goto }) => {
const analysisResponse = page.waitForResponse(
res =>
res.url().includes('/api/registry/analysis/') &&
res.url().includes('nuxt') &&
res.request().method() === 'GET',
{ timeout: 20_000 },
)

await goto('/compare?packages=@nuxt/kit,vue', { waitUntil: 'hydration' })

const response = await analysisResponse
expect(response.status()).toBe(200)

const body = await response.json()
expect(body).toHaveProperty('package', '@nuxt/kit')
expect(body).toHaveProperty('moduleFormat', 'esm')
})
})

test.describe('Search Pages', () => {
Expand Down
53 changes: 53 additions & 0 deletions test/unit/server/utils/parse-package-params.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { describe, expect, it } from 'vitest'
import { parsePackageParams } from '#server/utils/parse-package-params'

describe('parsePackageParams', () => {
describe('unscoped packages', () => {
it('parses package name without version', () => {
const segments = ['vue']
const result = parsePackageParams(segments)
expect(result).toEqual({
rawPackageName: 'vue',
rawVersion: undefined,
})
})

it('parses package name with version', () => {
const segments = ['vue', 'v', '3.4.0']
const result = parsePackageParams(segments)
expect(result).toEqual({
rawPackageName: 'vue',
rawVersion: '3.4.0',
})
})

it('parses package name with prerelease version', () => {
const segments = ['nuxt', 'v', '4.0.0-rc.1']
const result = parsePackageParams(segments)
expect(result).toEqual({
rawPackageName: 'nuxt',
rawVersion: '4.0.0-rc.1',
})
})
})

describe('scoped packages', () => {
it('parses scoped package name without version', () => {
const segments = ['@nuxt', 'kit']
const result = parsePackageParams(segments)
expect(result).toEqual({
rawPackageName: '@nuxt/kit',
rawVersion: undefined,
})
})

it('parses scoped package name with version', () => {
const segments = ['@nuxt', 'kit', 'v', '1.0.0']
const result = parsePackageParams(segments)
expect(result).toEqual({
rawPackageName: '@nuxt/kit',
rawVersion: '1.0.0',
})
})
})
})
Loading