(mode: 'server' | 'dev')
| 19 | let browser |
| 20 | |
| 21 | function runTests(mode: 'server' | 'dev') { |
| 22 | it('should load static unicode image', async () => { |
| 23 | const src = await browser.elementById('static').getAttribute('src') |
| 24 | expect(src).toMatch( |
| 25 | /_next%2Fstatic%2Fmedia%2F%C3%A4%C3%B6%C3%BC%C5%A1%C4%8D%C5%99%C3%AD(.+)png/ |
| 26 | ) |
| 27 | const fullSrc = new URL(src, `http://localhost:${appPort}`) |
| 28 | const res = await fetch(fullSrc) |
| 29 | expect(res.status).toBe(200) |
| 30 | }) |
| 31 | |
| 32 | it('should load internal unicode image', async () => { |
| 33 | const src = await browser.elementById('internal').getAttribute('src') |
| 34 | expect(src).toMatch( |
| 35 | '/_next/image?url=%2F%C3%A4%C3%B6%C3%BC%C5%A1%C4%8D%C5%99%C3%AD.png' |
| 36 | ) |
| 37 | const fullSrc = new URL(src, `http://localhost:${appPort}`) |
| 38 | const res = await fetch(fullSrc) |
| 39 | expect(res.status).toBe(200) |
| 40 | }) |
| 41 | |
| 42 | it('should load external unicode image', async () => { |
| 43 | const src = await browser.elementById('external').getAttribute('src') |
| 44 | expect(src).toMatch( |
| 45 | '/_next/image?url=https%3A%2F%2Fimage-optimization-test.vercel.app%2F%C3%A4%C3%B6%C3%BC%C5%A1%C4%8D%C5%99%C3%AD.png' |
| 46 | ) |
| 47 | const fullSrc = new URL(src, `http://localhost:${appPort}`) |
| 48 | const res = await fetch(fullSrc) |
| 49 | expect(res.status).toBe(200) |
| 50 | }) |
| 51 | |
| 52 | it('should load internal image with space', async () => { |
| 53 | const src = await browser.elementById('internal-space').getAttribute('src') |
| 54 | expect(src).toMatch('/_next/image?url=%2Fhello%2520world.jpg') |
| 55 | const fullSrc = new URL(src, `http://localhost:${appPort}`) |
| 56 | const res = await fetch(fullSrc) |
| 57 | expect(res.status).toBe(200) |
| 58 | }) |
| 59 | |
| 60 | it('should load external image with space', async () => { |
| 61 | const src = await browser.elementById('external-space').getAttribute('src') |
| 62 | expect(src).toMatch( |
| 63 | '/_next/image?url=https%3A%2F%2Fimage-optimization-test.vercel.app%2Fhello%2520world.jpg' |
| 64 | ) |
| 65 | const fullSrc = new URL(src, `http://localhost:${appPort}`) |
| 66 | const res = await fetch(fullSrc) |
| 67 | expect(res.status).toBe(200) |
| 68 | }) |
| 69 | if (mode === 'server') { |
| 70 | it('should build correct images-manifest.json', async () => { |
| 71 | const manifest = getImagesManifest(appDir) |
| 72 | expect(manifest).toEqual({ |
| 73 | version: 1, |
| 74 | images: { |
| 75 | contentDispositionType: 'attachment', |
| 76 | contentSecurityPolicy: |
| 77 | "script-src 'none'; frame-src 'none'; sandbox;", |
| 78 | dangerouslyAllowLocalIP: false, |
no test coverage detected