(mode: 'dev' | 'server')
| 70 | } |
| 71 | |
| 72 | function runTests(mode: 'dev' | 'server') { |
| 73 | let dpl: string |
| 74 | beforeAll(() => { |
| 75 | dpl = getDeploymentId(appDir, mode === 'dev').getDeploymentIdQuery(true) |
| 76 | }) |
| 77 | |
| 78 | it('should load the images', async () => { |
| 79 | let browser |
| 80 | try { |
| 81 | browser = await webdriver(appPort, '/') |
| 82 | |
| 83 | await check(async () => { |
| 84 | const result = await browser.eval( |
| 85 | `document.getElementById('basic-image').naturalWidth` |
| 86 | ) |
| 87 | |
| 88 | if (result === 0) { |
| 89 | throw new Error('Incorrectly loaded image') |
| 90 | } |
| 91 | |
| 92 | return 'result-correct' |
| 93 | }, /result-correct/) |
| 94 | |
| 95 | expect(await getImageUrls(browser)).toContain( |
| 96 | `http://localhost:${appPort}/_next/image?url=%2Ftest.jpg&w=828&q=75${dpl}` |
| 97 | ) |
| 98 | } finally { |
| 99 | if (browser) { |
| 100 | await browser.close() |
| 101 | } |
| 102 | } |
| 103 | }) |
| 104 | |
| 105 | it('should preload priority images', async () => { |
| 106 | let browser |
| 107 | try { |
| 108 | browser = await webdriver(appPort, '/priority') |
| 109 | |
| 110 | await check(async () => { |
| 111 | const result = await browser.eval( |
| 112 | `document.getElementById('basic-image').naturalWidth` |
| 113 | ) |
| 114 | |
| 115 | if (result === 0) { |
| 116 | throw new Error('Incorrectly loaded image') |
| 117 | } |
| 118 | |
| 119 | return 'result-correct' |
| 120 | }, /result-correct/) |
| 121 | |
| 122 | const links = await browser.elementsByCss('link[rel=preload][as=image]') |
| 123 | const entries = [] |
| 124 | for (const link of links) { |
| 125 | const imagesrcset = await link.getAttribute('imagesrcset') |
| 126 | const imagesizes = await link.getAttribute('imagesizes') |
| 127 | entries.push({ imagesrcset, imagesizes }) |
| 128 | } |
| 129 |
no test coverage detected