|
1 | 1 | // @vitest-environment node |
2 | 2 |
|
3 | | -import { readFile } from 'node:fs/promises'; |
4 | | -import { afterEach, describe, expect, it, vi } from 'vitest'; |
| 3 | +import { describe, expect, it } from 'vitest'; |
5 | 4 | import { NextRequest } from 'next/server'; |
6 | 5 |
|
7 | 6 | const PNG_SIGNATURE = [137, 80, 78, 71, 13, 10, 26, 10]; |
8 | 7 |
|
9 | | -afterEach(() => { |
10 | | - vi.unstubAllGlobals(); |
11 | | - vi.resetModules(); |
12 | | -}); |
13 | | - |
14 | 8 | describe('GET /api/og', () => { |
15 | | - it('returns a non-empty PNG using the bundled Korean font', async () => { |
16 | | - vi.stubGlobal( |
17 | | - 'fetch', |
18 | | - vi.fn(async (input: string | URL | Request) => { |
19 | | - const url = |
20 | | - input instanceof URL |
21 | | - ? input |
22 | | - : new URL(typeof input === 'string' ? input : input.url); |
23 | | - |
24 | | - if (url.protocol !== 'file:') { |
25 | | - throw new Error(`Unexpected external font request: ${url.href}`); |
26 | | - } |
27 | | - |
28 | | - return new Response(await readFile(url), { |
29 | | - status: 200, |
30 | | - headers: { 'Content-Type': 'font/ttf' }, |
31 | | - }); |
32 | | - }) |
33 | | - ); |
34 | | - |
35 | | - const { GET } = await import('./route'); |
| 9 | + it('returns a non-empty PNG from the Node.js runtime', async () => { |
| 10 | + const { GET, runtime } = await import('./route'); |
36 | 11 | const response = await GET( |
37 | 12 | new NextRequest( |
38 | 13 | 'https://ark-log.vercel.app/api/og?title=%ED%95%9C%EA%B8%80%20OG%20%EC%9D%B4%EB%AF%B8%EC%A7%80&tags=Next.js,Ark' |
39 | 14 | ) |
40 | 15 | ); |
41 | 16 | const bytes = new Uint8Array(await response.arrayBuffer()); |
42 | 17 |
|
| 18 | + expect(runtime).toBe('nodejs'); |
43 | 19 | expect(response.status).toBe(200); |
44 | 20 | expect(response.headers.get('content-type')).toBe('image/png'); |
45 | 21 | expect(bytes.byteLength).toBeGreaterThan(10_000); |
|
0 commit comments