Skip to content

Commit

Permalink
fix: fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wyattjoh committed Aug 23, 2022
1 parent 88b54ad commit 48418d1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
17 changes: 13 additions & 4 deletions test/integration/image-optimizer/test/util.ts
Expand Up @@ -15,6 +15,7 @@ import {
waitFor,
} from 'next-test-utils'
import isAnimated from 'next/dist/compiled/is-animated'
import { RequestInit } from 'node-fetch'

const largeSize = 1080 // defaults defined in server/config.ts
const sharpMissingText = `For production Image Optimization with Next.js, the optional 'sharp' package is strongly recommended`
Expand Down Expand Up @@ -115,10 +116,15 @@ async function expectAvifSmallerThanWebp(w, q, appPort) {
expect(avif).toBeLessThanOrEqual(webp)
}

async function fetchWithDuration(...args) {
console.warn('Fetching', args[1], args[2])
async function fetchWithDuration(
appPort: string | number,
pathname: string,
query?: Record<string, any> | string,
opts?: RequestInit
) {
console.warn('Fetching', pathname, query)
const start = Date.now()
const res = await fetchViaHTTP(...args)
const res = await fetchViaHTTP(appPort, pathname, query, opts)
const buffer = await res.buffer()
const duration = Date.now() - start
return { duration, buffer, res }
Expand All @@ -140,7 +146,10 @@ export function runTests(ctx) {
slowImageServer.port
}/slow.png?delay=${1}&status=308`
const query = { url, w: ctx.w, q: 39 }
const opts = { headers: { accept: 'image/webp' }, redirect: 'manual' }
const opts: RequestInit = {
headers: { accept: 'image/webp' },
redirect: 'manual',
}

const res = await fetchViaHTTP(ctx.appPort, '/_next/image', query, opts)
expect(res.status).toBe(500)
Expand Down
2 changes: 1 addition & 1 deletion test/lib/next-test-utils.js
Expand Up @@ -117,7 +117,7 @@ export function renderViaAPI(app, pathname, query) {
}

/**
* @param {string} appPort
* @param {string | number} appPort
* @param {string} pathname
* @param {Record<string, any> | string | undefined} [query]
* @param {import('node-fetch').RequestInit} [opts]
Expand Down

0 comments on commit 48418d1

Please sign in to comment.