[READ-ONLY] a fast, modern browser for the npm registry

test: move nuxt unit tests to `test/nuxt` (#676)

authored by

James Garbutt and committed by
GitHub
f824e778 4dd98d5f

+17 -14
+5
nuxt.config.ts
··· 163 163 base: './.cache/atproto-oauth/session', 164 164 }, 165 165 }, 166 + typescript: { 167 + tsConfig: { 168 + include: ['../test/unit/server/**/*.ts'], 169 + }, 170 + }, 166 171 }, 167 172 168 173 fonts: {
+1 -4
test/unit/search-operators.spec.ts test/nuxt/composables/useStructuredFilters.spec.ts
··· 1 1 import { describe, expect, it } from 'vitest' 2 - import { 3 - hasSearchOperators, 4 - parseSearchOperators, 5 - } from '../../app/composables/useStructuredFilters' 2 + import { hasSearchOperators, parseSearchOperators } from '~/composables/useStructuredFilters' 6 3 7 4 describe('parseSearchOperators', () => { 8 5 describe('basic operator parsing', () => {
+4 -3
test/unit/server/utils/dependency-analysis.spec.ts
··· 2 2 3 3 // Mock Nitro globals before importing the module 4 4 vi.stubGlobal('defineCachedFunction', (fn: Function) => fn) 5 - vi.stubGlobal('$fetch', vi.fn()) 5 + const $fetchMock = vi.fn() 6 + vi.stubGlobal('$fetch', $fetchMock) 6 7 7 8 // Import module under test 8 9 const { analyzeDependencyTree } = await import('../../../../server/utils/dependency-analysis') ··· 26 27 batchResults: Array<{ vulns?: Array<{ id: string; modified: string }> }>, 27 28 detailResults: Map<string, { vulns?: Array<Record<string, unknown>> }> = new Map(), 28 29 ) { 29 - vi.mocked($fetch).mockImplementation(async (url: string, options?: { body?: unknown }) => { 30 + $fetchMock.mockImplementation(async (url: string, options?: { body?: unknown }) => { 30 31 if (url === 'https://api.osv.dev/v1/querybatch') { 31 32 return { results: batchResults } 32 33 } ··· 102 103 vi.mocked(resolveDependencyTree).mockResolvedValue(mockResolved) 103 104 104 105 // Batch query fails entirely 105 - vi.mocked($fetch).mockRejectedValue(new Error('OSV API error')) 106 + $fetchMock.mockRejectedValue(new Error('OSV API error')) 106 107 107 108 const result = await analyzeDependencyTree('test-pkg', '1.0.0') 108 109
+7 -7
test/unit/server/utils/readme.spec.ts
··· 47 47 const result = await renderReadmeHtml(markdown, 'test-pkg') 48 48 49 49 expect(result.playgroundLinks).toHaveLength(1) 50 - expect(result.playgroundLinks[0].provider).toBe('codesandbox') 50 + expect(result.playgroundLinks[0]!.provider).toBe('codesandbox') 51 51 }) 52 52 }) 53 53 ··· 56 56 const markdown = `[Pen](https://codepen.io/user/pen/abc123)` 57 57 const result = await renderReadmeHtml(markdown, 'test-pkg') 58 58 59 - expect(result.playgroundLinks[0].provider).toBe('codepen') 59 + expect(result.playgroundLinks[0]!.provider).toBe('codepen') 60 60 }) 61 61 62 62 it('extracts Replit links', async () => { 63 63 const markdown = `[Repl](https://replit.com/@user/project)` 64 64 const result = await renderReadmeHtml(markdown, 'test-pkg') 65 65 66 - expect(result.playgroundLinks[0].provider).toBe('replit') 66 + expect(result.playgroundLinks[0]!.provider).toBe('replit') 67 67 }) 68 68 69 69 it('extracts Gitpod links', async () => { 70 70 const markdown = `[Open in Gitpod](https://gitpod.io/#https://github.com/user/repo)` 71 71 const result = await renderReadmeHtml(markdown, 'test-pkg') 72 72 73 - expect(result.playgroundLinks[0].provider).toBe('gitpod') 73 + expect(result.playgroundLinks[0]!.provider).toBe('gitpod') 74 74 }) 75 75 }) 76 76 ··· 83 83 const result = await renderReadmeHtml(markdown, 'test-pkg') 84 84 85 85 expect(result.playgroundLinks).toHaveLength(2) 86 - expect(result.playgroundLinks[0].provider).toBe('stackblitz') 87 - expect(result.playgroundLinks[1].provider).toBe('codesandbox') 86 + expect(result.playgroundLinks[0]!.provider).toBe('stackblitz') 87 + expect(result.playgroundLinks[1]!.provider).toBe('codesandbox') 88 88 }) 89 89 90 90 it('deduplicates same URL', async () => { ··· 127 127 const result = await renderReadmeHtml(markdown, 'test-pkg') 128 128 129 129 expect(result.playgroundLinks).toHaveLength(1) 130 - expect(result.playgroundLinks[0].provider).toBe('stackblitz') 130 + expect(result.playgroundLinks[0]!.provider).toBe('stackblitz') 131 131 }) 132 132 }) 133 133 })