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