Skip to content

Commit d347112

Browse files
committed
test: reduce fixtures
1 parent 13da1ec commit d347112

36 files changed

Lines changed: 1733 additions & 77741 deletions

modules/runtime/server/cache.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ async function handleFastNpmMeta(
124124
const fixturePath = getFixturePath('packument', packageName)
125125
const packument = await storage.getItem<any>(fixturePath)
126126

127-
if (!packument) return null
127+
if (!packument) {
128+
return { data: null }
129+
}
128130

129131
let version: string | undefined
130132
if (specifier === 'latest' || !specifier) {
@@ -172,6 +174,7 @@ function matchUrlToFixture(url: string): FixtureMatch | null {
172174
}
173175
return { type: 'search', name: query }
174176
}
177+
return { type: 'search', name: '' }
175178
}
176179

177180
// Org packages
@@ -272,9 +275,9 @@ export default defineNitroPlugin(nitroApp => {
272275
const data = await storage.getItem<T>(fixturePath)
273276

274277
if (data === null) {
275-
// For user searches, return empty results (valid behavior)
276-
if (match.type === 'user') {
277-
if (VERBOSE) process.stdout.write(`[test-fixtures] Empty user: ${match.name}\n`)
278+
// For user searches or search queries without fixtures, return empty results
279+
if (match.type === 'user' || match.type === 'search') {
280+
if (VERBOSE) process.stdout.write(`[test-fixtures] Empty ${match.type}: ${match.name}\n`)
278281
return {
279282
data: { objects: [], total: 0, time: new Date().toISOString() } as T,
280283
isStale: false,

scripts/generate-fixtures.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,30 @@ const NPM_API = 'https://api.npmjs.org'
2525

2626
/**
2727
* Packages required by E2E tests.
28-
* These are the packages that tests navigate to or expect data from.
28+
* Keep this list minimal - only add packages that are directly used in tests.
29+
*
30+
* To find what's needed, check:
31+
* - goto() calls in test/e2e/*.spec.ts
32+
* - API endpoint tests (badges, vulnerabilities)
33+
* - create-command tests (need create-* packages)
2934
*/
3035
const REQUIRED_PACKAGES = [
31-
// Unscoped packages
32-
'nuxt',
33-
'vue',
34-
'lodash',
35-
'vite',
36-
'next',
37-
'color',
38-
'ufo',
39-
'is-odd',
40-
'date-fns',
36+
// Core packages for various tests
37+
'vue', // search, badges, vulnerabilities, version test (3.5.27)
38+
'nuxt', // org tests, badges, create-command
39+
'vite', // create-command test
40+
'next', // create-command test
41+
'@nuxt/kit', // scoped package tests, version test (3.20.0)
42+
'@types/node', // scoped package tests
43+
// Docs page tests
44+
'ufo', // docs test with version 1.6.3
45+
'is-odd', // docs test (3.0.1), install copy test, "no create" test, hyphen-in-name test
46+
// Edge case: package name with dots
4147
'lodash.merge',
42-
// Create packages (checked via relationship from main packages)
48+
// Create-command feature (checks if create-* package exists)
4349
'create-vite',
4450
'create-next-app',
4551
'create-nuxt',
46-
// Scoped packages
47-
'@nuxt/kit',
48-
'@vitejs/plugin-vue',
49-
'@babel/core',
50-
'@types/node',
5152
] as const
5253

5354
/**
@@ -62,8 +63,9 @@ const REQUIRED_ORGS = ['nuxt'] as const
6263

6364
/**
6465
* Users whose package lists are needed.
66+
* Use users with few packages to keep fixtures small.
6567
*/
66-
const REQUIRED_USERS = ['sindresorhus'] as const
68+
const REQUIRED_USERS = ['qwerzl'] as const
6769

6870
// ============================================================================
6971
// Utility Functions

test/e2e/badge.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ test.describe('badge API', () => {
8787

8888
test.describe('specific scenarios', () => {
8989
test('downloads-year handles large numbers', async ({ page, baseURL }) => {
90-
const url = toLocalUrl(baseURL, '/api/registry/badge/downloads-year/lodash')
90+
const url = toLocalUrl(baseURL, '/api/registry/badge/downloads-year/vue')
9191
const { body } = await fetchBadge(page, url)
9292

9393
expect(body).toContain('downloads/yr')

test/e2e/create-command.spec.ts

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,31 +45,16 @@ test.describe('Create Command', () => {
4545
await expect(createCommandSection.locator('code')).toContainText(/create nuxt/i)
4646
})
4747

48-
test('/color - should NOT show create command (different maintainers)', async ({
48+
test('/is-odd - should NOT show create command (no create-is-odd exists)', async ({
4949
page,
5050
goto,
5151
}) => {
52-
await goto('/package/color', { waitUntil: 'domcontentloaded' })
52+
await goto('/package/is-odd', { waitUntil: 'domcontentloaded' })
5353

5454
// Wait for package to load
55-
await expect(page.locator('h1').filter({ hasText: 'color' })).toBeVisible()
55+
await expect(page.locator('h1').filter({ hasText: 'is-odd' })).toBeVisible()
5656

57-
// Create command section should NOT be visible (different maintainers)
58-
// Use .first() for consistency, though none should exist
59-
const createCommandSection = page.locator('.group\\/createcmd').first()
60-
await expect(createCommandSection).not.toBeVisible()
61-
})
62-
63-
test('/lodash - should NOT show create command (no create-lodash exists)', async ({
64-
page,
65-
goto,
66-
}) => {
67-
await goto('/package/lodash', { waitUntil: 'domcontentloaded' })
68-
69-
// Wait for package to load
70-
await expect(page.locator('h1').filter({ hasText: 'lodash' })).toBeVisible()
71-
72-
// Create command section should NOT be visible (no create-lodash exists)
57+
// Create command section should NOT be visible (no create-is-odd exists)
7358
// Use .first() for consistency, though none should exist
7459
const createCommandSection = page.locator('.group\\/createcmd').first()
7560
await expect(createCommandSection).not.toBeVisible()
@@ -139,7 +124,7 @@ test.describe('Create Command', () => {
139124

140125
test.describe('Install Command Copy', () => {
141126
test('hovering install command shows copy button', async ({ page, goto }) => {
142-
await goto('/package/lodash', { waitUntil: 'hydration' })
127+
await goto('/package/is-odd', { waitUntil: 'hydration' })
143128

144129
// Find the install command container
145130
const installCommandContainer = page.locator('.group\\/installcmd').first()
@@ -164,7 +149,7 @@ test.describe('Create Command', () => {
164149
// Grant clipboard permissions
165150
await context.grantPermissions(['clipboard-read', 'clipboard-write'])
166151

167-
await goto('/package/lodash', { waitUntil: 'hydration' })
152+
await goto('/package/is-odd', { waitUntil: 'hydration' })
168153

169154
// Find and hover over the install command container
170155
const installCommandContainer = page.locator('.group\\/installcmd').first()
@@ -179,7 +164,7 @@ test.describe('Create Command', () => {
179164

180165
// Verify clipboard content contains the install command
181166
const clipboardContent = await page.evaluate(() => navigator.clipboard.readText())
182-
expect(clipboardContent).toMatch(/install lodash|add lodash/i)
167+
expect(clipboardContent).toMatch(/install is-odd|add is-odd/i)
183168

184169
await expect(copyButton).toContainText(/copy/i, { timeout: 5000 })
185170
await expect(copyButton).not.toContainText(/copied/i)

test/e2e/url-compatibility.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ test.describe('npmjs.com URL Compatibility', () => {
7575
})
7676

7777
test.describe('User Profile Pages', () => {
78-
test('/~sindresorhus → user profile', async ({ page, goto }) => {
79-
await goto('/~sindresorhus', { waitUntil: 'hydration' })
78+
test('/~qwerzl → user profile', async ({ page, goto }) => {
79+
await goto('/~qwerzl', { waitUntil: 'hydration' })
8080

8181
// Should show username
82-
await expect(page.locator('h1')).toContainText('~sindresorhus')
82+
await expect(page.locator('h1')).toContainText('~qwerzl')
8383

8484
await expect(page.locator('text=/\\d+\\s+public\\s+package/i').first()).toBeVisible({
8585
timeout: 15000,
@@ -121,10 +121,10 @@ test.describe('npmjs.com URL Compatibility', () => {
121121
await expect(page.locator('h1')).toContainText('lodash.merge')
122122
})
123123

124-
test('package name with hyphens: /package/date-fns', async ({ page, goto }) => {
125-
await goto('/package/date-fns', { waitUntil: 'domcontentloaded' })
124+
test('package name with hyphens: /package/is-odd', async ({ page, goto }) => {
125+
await goto('/package/is-odd', { waitUntil: 'domcontentloaded' })
126126

127-
await expect(page.locator('h1')).toContainText('date-fns')
127+
await expect(page.locator('h1')).toContainText('is-odd')
128128
})
129129

130130
test('scoped package with hyphens: /package/@types/node', async ({ page, goto }) => {

test/e2e/vulnerabilities.spec.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,23 @@ test.describe('vulnerabilities API', () => {
2727
})
2828

2929
test('scoped package vulnerabilities with URL encoding', async ({ page, baseURL }) => {
30-
const url = toLocalUrl(baseURL, '/api/registry/vulnerabilities/@vitejs%2Fplugin-vue')
30+
const url = toLocalUrl(baseURL, '/api/registry/vulnerabilities/@nuxt%2Fkit')
3131
const { response, body } = await fetchVulnerabilities(page, url)
3232

3333
expect(response.status()).toBe(200)
3434
expect(response.headers()['content-type']).toContain('application/json')
35-
expect(body).toHaveProperty('package', '@vitejs/plugin-vue')
35+
expect(body).toHaveProperty('package', '@nuxt/kit')
3636
expect(body).toHaveProperty('version')
3737
})
3838

3939
test('scoped package with explicit version and URL encoding', async ({ page, baseURL }) => {
40-
const url = toLocalUrl(baseURL, '/api/registry/vulnerabilities/@vitejs%2Fplugin-vue/v/6.0.3')
40+
const url = toLocalUrl(baseURL, '/api/registry/vulnerabilities/@nuxt%2Fkit/v/3.20.0')
4141
const { response, body } = await fetchVulnerabilities(page, url)
4242

4343
expect(response.status()).toBe(200)
4444
expect(response.headers()['content-type']).toContain('application/json')
45-
expect(body).toHaveProperty('package', '@vitejs/plugin-vue')
46-
expect(body).toHaveProperty('version', '6.0.3')
45+
expect(body).toHaveProperty('package', '@nuxt/kit')
46+
expect(body).toHaveProperty('version', '3.20.0')
4747
})
4848

4949
test('scoped package without URL encoding (for comparison)', async ({ page, baseURL }) => {
@@ -56,13 +56,13 @@ test.describe('vulnerabilities API', () => {
5656
expect(body).toHaveProperty('version')
5757
})
5858

59-
test('complex scoped package name with URL encoding', async ({ page, baseURL }) => {
60-
const url = toLocalUrl(baseURL, '/api/registry/vulnerabilities/@babel%2Fcore')
59+
test('scoped package with different scope', async ({ page, baseURL }) => {
60+
const url = toLocalUrl(baseURL, '/api/registry/vulnerabilities/@types%2Fnode')
6161
const { response, body } = await fetchVulnerabilities(page, url)
6262

6363
expect(response.status()).toBe(200)
6464
expect(response.headers()['content-type']).toContain('application/json')
65-
expect(body).toHaveProperty('package', '@babel/core')
65+
expect(body).toHaveProperty('package', '@types/node')
6666
expect(body).toHaveProperty('version')
6767
})
6868

test/fixtures/npm-api/downloads/@babel/core.json

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"downloads": 3794426,
3-
"start": "2026-01-26",
4-
"end": "2026-02-01",
2+
"downloads": 3744387,
3+
"start": "2026-01-27",
4+
"end": "2026-02-02",
55
"package": "@nuxt/kit"
66
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"downloads": 214268676,
3-
"start": "2026-01-26",
4-
"end": "2026-02-01",
2+
"downloads": 217871651,
3+
"start": "2026-01-27",
4+
"end": "2026-02-02",
55
"package": "@types/node"
66
}

test/fixtures/npm-api/downloads/@vitejs/plugin-vue.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)