Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
53 changes: 53 additions & 0 deletions test/e2e/interactions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,59 @@ 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 },
Comment thread
gameroman marked this conversation as resolved.
)

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('installSize')
})

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')
})

test('compare grid shows data (not all dashes) for a scoped package', async ({ page, goto }) => {
await goto('/compare?packages=@nuxt/kit,vue', { waitUntil: 'hydration' })

const grid = page.locator('.comparison-grid')
await expect(grid).toBeVisible({ timeout: 20_000 })

// Package size row should have a value for the scoped package column,
// not a dash, which would indicate the API call failed before the fix.
const packageSizeRow = grid.locator('[data-facet="packageSize"]')
await expect(packageSizeRow).toBeVisible({ timeout: 15_000 })
await expect(packageSizeRow.locator('.comparison-cell').first()).not.toContainText('-')
})
})

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