(mode: 'dev' | 'server')
| 52 | } |
| 53 | |
| 54 | function runTests(mode: 'dev' | 'server') { |
| 55 | it('should load the images', async () => { |
| 56 | let browser |
| 57 | try { |
| 58 | browser = await webdriver(appPort, '/docs') |
| 59 | |
| 60 | await check(async () => { |
| 61 | const result = await browser.eval( |
| 62 | `document.getElementById('basic-image').naturalWidth` |
| 63 | ) |
| 64 | |
| 65 | if (result === 0) { |
| 66 | throw new Error('Incorrectly loaded image') |
| 67 | } |
| 68 | |
| 69 | return 'result-correct' |
| 70 | }, /result-correct/) |
| 71 | |
| 72 | expect(await getImageUrls(browser)).toContain( |
| 73 | `http://localhost:${appPort}/docs/_next/image?url=%2Fdocs%2Ftest.jpg&w=828&q=75${getDeploymentId(appDir, mode === 'dev').getDeploymentIdQuery(true)}` |
| 74 | ) |
| 75 | } finally { |
| 76 | if (browser) { |
| 77 | await browser.close() |
| 78 | } |
| 79 | } |
| 80 | }) |
| 81 | |
| 82 | it('should update the image on src change', async () => { |
| 83 | let browser |
| 84 | try { |
| 85 | browser = await webdriver(appPort, '/docs/update') |
| 86 | |
| 87 | await check( |
| 88 | () => browser.eval(`document.getElementById("update-image").src`), |
| 89 | /test\.jpg/ |
| 90 | ) |
| 91 | |
| 92 | await browser.eval(`document.getElementById("toggle").click()`) |
| 93 | |
| 94 | await check( |
| 95 | () => browser.eval(`document.getElementById("update-image").src`), |
| 96 | /test\.png/ |
| 97 | ) |
| 98 | } finally { |
| 99 | if (browser) { |
| 100 | await browser.close() |
| 101 | } |
| 102 | } |
| 103 | }) |
| 104 | |
| 105 | it('should work when using flexbox', async () => { |
| 106 | let browser |
| 107 | try { |
| 108 | browser = await webdriver(appPort, '/docs/flex') |
| 109 | await check(async () => { |
| 110 | const result = await browser.eval( |
| 111 | `document.getElementById('basic-image').width` |
no test coverage detected