|
| 1 | +/* eslint-env jest */ |
| 2 | + |
| 3 | +import { |
| 4 | + findPort, |
| 5 | + killApp, |
| 6 | + launchApp, |
| 7 | + nextBuild, |
| 8 | + nextStart, |
| 9 | +} from 'next-test-utils' |
| 10 | +import webdriver from 'next-webdriver' |
| 11 | +//import fetch from 'node-fetch' |
| 12 | +import { join } from 'path' |
| 13 | + |
| 14 | +jest.setTimeout(1000 * 60) |
| 15 | + |
| 16 | +const appDir = join(__dirname, '../') |
| 17 | + |
| 18 | +let appPort |
| 19 | +let app |
| 20 | +let browser |
| 21 | + |
| 22 | +function runTests() { |
| 23 | + it('should load static unicode image', async () => { |
| 24 | + const src = await browser.elementById('static').getAttribute('src') |
| 25 | + expect(src).toMatch( |
| 26 | + /_next%2Fstatic%2Fimage%2Fpublic%2F%C3%A4%C3%B6%C3%BC(.+)png/ |
| 27 | + ) |
| 28 | + const res = await fetch(src) |
| 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('/_next/image?url=%2F%C3%A4%C3%B6%C3%BC.png') |
| 35 | + const res = await fetch(src) |
| 36 | + expect(res.status).toBe(200) |
| 37 | + }) |
| 38 | + |
| 39 | + it('should load external unicode image', async () => { |
| 40 | + const src = await browser.elementById('external').getAttribute('src') |
| 41 | + expect(src).toMatch( |
| 42 | + '/_next/image?url=https%3A%2F%2Fimage-optimization-test.vercel.app%2F%C3%A4%C3%B6%C3%BC.png' |
| 43 | + ) |
| 44 | + const res = await fetch(src) |
| 45 | + expect(res.status).toBe(200) |
| 46 | + }) |
| 47 | +} |
| 48 | + |
| 49 | +describe('Image Component Unicode Image URL', () => { |
| 50 | + describe('dev mode', () => { |
| 51 | + beforeAll(async () => { |
| 52 | + appPort = await findPort() |
| 53 | + app = await launchApp(appDir, appPort) |
| 54 | + browser = await webdriver(appPort, '/') |
| 55 | + }) |
| 56 | + afterAll(() => { |
| 57 | + killApp(app) |
| 58 | + if (browser) { |
| 59 | + browser.close() |
| 60 | + } |
| 61 | + }) |
| 62 | + runTests() |
| 63 | + }) |
| 64 | + |
| 65 | + describe('server mode', () => { |
| 66 | + beforeAll(async () => { |
| 67 | + await nextBuild(appDir) |
| 68 | + appPort = await findPort() |
| 69 | + app = await nextStart(appDir, appPort) |
| 70 | + browser = await webdriver(appPort, '/') |
| 71 | + }) |
| 72 | + afterAll(() => { |
| 73 | + killApp(app) |
| 74 | + if (browser) { |
| 75 | + browser.close() |
| 76 | + } |
| 77 | + }) |
| 78 | + runTests() |
| 79 | + }) |
| 80 | +}) |
0 commit comments