Files
next.js/test/integration/sharp-api/test/sharp-api.test.ts
StevenandGitHub a90827bef9 chore(test): update sharp api test (#82740)
Testing to see if sharp works with turbopack
2025-08-18 22:43:55 +02:00

50 lines
1.2 KiB
TypeScript

/* eslint-env jest */
import {
fetchViaHTTP,
findPort,
killApp,
nextBuild,
nextStart,
} from 'next-test-utils'
import execa from 'execa'
import fs from 'fs-extra'
import { join } from 'path'
const appDir = join(__dirname, '../app')
let app, appPort
describe('sharp api', () => {
beforeAll(async () => {
await execa('npm', ['install'], { cwd: appDir, stdio: 'inherit' })
await nextBuild(appDir)
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(async () => {
if (app) {
await killApp(app)
}
await fs.remove(join(appDir, '.next'))
await fs.remove(join(appDir, 'node_modules'))
})
it('should handle custom sharp usage', async () => {
const res = await fetchViaHTTP(appPort, '/api/custom-sharp')
expect(res.status).toBe(200)
expect(res.headers.get('content-type')).toBe('image/png')
expect((await res.arrayBuffer()).byteLength).toBeGreaterThan(0)
const traceFile = await fs.readJson(
join(
appDir,
'.next',
'server',
'pages',
'api',
'custom-sharp.js.nft.json'
)
)
expect(traceFile.files.some((file) => file.includes('sharp/'))).toBe(true)
})
})