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