MCPcopy
hub / github.com/vercel/next.js / runTests

Function runTests

test/integration/image-optimizer/test/util.ts:195–1702  ·  view source on GitHub ↗
(ctx: RunTestsCtx)

Source from the content-addressed store, hash-verified

193}
194
195export function runTests(ctx: RunTestsCtx) {
196 const { isDev, nextConfigImages, imagesDir } = ctx
197 const {
198 contentDispositionType = 'attachment',
199 domains = [],
200 formats = [],
201 minimumCacheTTL = 14400,
202 maximumRedirects = 3,
203 dangerouslyAllowLocalIP,
204 } = nextConfigImages || {}
205 const avifEnabled = formats[0] === 'image/avif'
206 let slowImageServer: Awaited<ReturnType<typeof serveSlowImage>>
207 beforeAll(async () => {
208 slowImageServer = await serveSlowImage()
209 })
210 afterAll(async () => {
211 slowImageServer.stop()
212 })
213
214 if (domains.length > 0 && dangerouslyAllowLocalIP) {
215 it('should normalize invalid status codes', async () => {
216 const url = `http://localhost:${slowImageServer.port}/slow.png?status=399`
217 const query = { url, w: ctx.w, q: ctx.q }
218 const opts: RequestInit = {
219 headers: { accept: 'image/webp' },
220 redirect: 'manual',
221 }
222
223 const res = await fetchViaHTTP(ctx.appPort, '/_next/image', query, opts)
224 expect(res.status).toBe(500)
225 })
226
227 it('should timeout for upstream image exceeding 7 seconds', async () => {
228 const url = `http://localhost:${slowImageServer.port}/slow.png?delay=${8000}`
229 const query = { url, w: ctx.w, q: ctx.q }
230 const res = await fetchViaHTTP(ctx.appPort, '/_next/image', query, {})
231 expect(res.status).toBe(504)
232 })
233 }
234
235 if (domains.length > 0) {
236 it('should follow redirect from http to https when maximumRedirects > 0', async () => {
237 const url = `http://image-optimization-test.vercel.app/frog.png`
238 const query = { url, w: ctx.w, q: ctx.q }
239 const res = await fetchViaHTTP(ctx.appPort, '/_next/image', query, {})
240 expect(res.status).toBe(maximumRedirects > 0 ? 200 : 508)
241 })
242
243 it('should follow redirect when dangerouslyAllowLocalIP enabled', async () => {
244 const url = `http://localhost:${slowImageServer.port}?status=301&location=%2Fslow.png`
245 const query = { url, w: ctx.w, q: ctx.q }
246 const res = await fetchViaHTTP(ctx.appPort, '/_next/image', query, {})
247 let expectedStatus = dangerouslyAllowLocalIP ? 200 : 400
248 if (maximumRedirects === 0) {
249 expectedStatus = 508
250 }
251 expect(res.status).toBe(expectedStatus)
252 })

Callers 1

setupTestsFunction · 0.70

Calls 15

fetchViaHTTPFunction · 0.90
joinFunction · 0.90
checkFunction · 0.90
waitForFunction · 0.90
getDeploymentIdFunction · 0.90
retryFunction · 0.90
serveSlowImageFunction · 0.85
expectWidthFunction · 0.85
cleanImagesDirFunction · 0.85
fetchWithDurationFunction · 0.85
fsToJsonFunction · 0.85

Tested by

no test coverage detected