diff --git a/package.json b/package.json index cea308b687b..698760d043c 100644 --- a/package.json +++ b/package.json @@ -74,7 +74,7 @@ "@testing-library/react": "13.0.0", "@types/cheerio": "0.22.16", "@types/fs-extra": "8.1.0", - "@types/html-validator": "5.0.2", + "@types/html-validator": "5.0.3", "@types/http-proxy": "1.17.3", "@types/jest": "24.0.13", "@types/node": "13.11.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 51bd7f91bd0..70af320d27c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -37,7 +37,7 @@ importers: '@testing-library/react': 13.0.0 '@types/cheerio': 0.22.16 '@types/fs-extra': 8.1.0 - '@types/html-validator': 5.0.2 + '@types/html-validator': 5.0.3 '@types/http-proxy': 1.17.3 '@types/jest': 24.0.13 '@types/node': 13.11.0 @@ -191,7 +191,7 @@ importers: '@testing-library/react': 13.0.0_biqbaboplfbrettd7655fr4n2y '@types/cheerio': 0.22.16 '@types/fs-extra': 8.1.0 - '@types/html-validator': 5.0.2 + '@types/html-validator': 5.0.3 '@types/http-proxy': 1.17.3 '@types/jest': 24.0.13 '@types/node': 13.11.0 @@ -5635,8 +5635,8 @@ packages: '@types/unist': 2.0.3 dev: true - /@types/html-validator/5.0.2: - resolution: {integrity: sha512-10KDAqGQ29BTEdOOWTYyJF6R1oSLDtFlSgDc6P02Y6CXo8kA0SHeRPoieX/EXiMOLpM1e6G1QlKgFCbhxrtxuQ==} + /@types/html-validator/5.0.3: + resolution: {integrity: sha512-QcKpR0cAWhLy7T3J24dwCuviRyS8xj/gVtFxcfZer9lfRgHdSAUFvE02nI/rsgIxSr71Z/2moXVYvWl2fTAzHQ==} dependencies: '@types/node': 17.0.21 dev: true diff --git a/test/integration/image-component/asset-prefix/test/index.test.js b/test/integration/image-component/asset-prefix/test/index.test.ts similarity index 100% rename from test/integration/image-component/asset-prefix/test/index.test.js rename to test/integration/image-component/asset-prefix/test/index.test.ts diff --git a/test/integration/image-component/base-path/test/index.test.js b/test/integration/image-component/base-path/test/index.test.ts similarity index 98% rename from test/integration/image-component/base-path/test/index.test.js rename to test/integration/image-component/base-path/test/index.test.ts index c26a714fde1..e85b1e3f3a8 100644 --- a/test/integration/image-component/base-path/test/index.test.js +++ b/test/integration/image-component/base-path/test/index.test.ts @@ -308,16 +308,16 @@ function runTests(mode) { expect(await getComputed(browser, id, 'width')).toBe(width) expect(await getComputed(browser, id, 'height')).toBe(height) const delta = 150 - const largeWidth = width + delta - const largeHeight = height + delta + const largeWidth = Number(width) + delta + const largeHeight = Number(height) + delta await browser.setDimensions({ width: largeWidth, height: largeHeight, }) expect(await getComputed(browser, id, 'width')).toBe(largeWidth) expect(await getComputed(browser, id, 'height')).toBe(largeHeight) - const smallWidth = width - delta - const smallHeight = height - delta + const smallWidth = Number(width) - delta + const smallHeight = Number(height) - delta await browser.setDimensions({ width: smallWidth, height: smallHeight, @@ -389,9 +389,7 @@ function runTests(mode) { expect(await hasRedbox(browser)).toBe(false) await check(async () => { - return (await browser.log('browser')) - .map((log) => log.message) - .join('\n') + return (await browser.log()).map((log) => log.message).join('\n') }, /Image is missing required "src" property/gm) }) diff --git a/test/integration/image-component/base-path/test/static.test.js b/test/integration/image-component/base-path/test/static.test.ts similarity index 100% rename from test/integration/image-component/base-path/test/static.test.js rename to test/integration/image-component/base-path/test/static.test.ts diff --git a/test/integration/image-component/basic/test/index.test.js b/test/integration/image-component/basic/test/index.test.ts similarity index 100% rename from test/integration/image-component/basic/test/index.test.js rename to test/integration/image-component/basic/test/index.test.ts diff --git a/test/integration/image-component/custom-resolver/test/index.test.js b/test/integration/image-component/custom-resolver/test/index.test.ts similarity index 100% rename from test/integration/image-component/custom-resolver/test/index.test.js rename to test/integration/image-component/custom-resolver/test/index.test.ts diff --git a/test/integration/image-component/default/test/index.test.js b/test/integration/image-component/default/test/index.test.ts similarity index 98% rename from test/integration/image-component/default/test/index.test.js rename to test/integration/image-component/default/test/index.test.ts index 4401c4fff93..ba142e17063 100644 --- a/test/integration/image-component/default/test/index.test.js +++ b/test/integration/image-component/default/test/index.test.ts @@ -151,7 +151,7 @@ function runTests(mode) { await browser.elementById('responsive2').getAttribute('loading') ).toBe(null) - const warnings = (await browser.log('browser')) + const warnings = (await browser.log()) .map((log) => log.message) .join('\n') expect(warnings).not.toMatch( @@ -607,16 +607,16 @@ function runTests(mode) { expect(await getComputed(browser, id, 'width')).toBe(width) expect(await getComputed(browser, id, 'height')).toBe(height) const delta = 150 - const largeWidth = width + delta - const largeHeight = height + delta + const largeWidth = Number(width) + delta + const largeHeight = Number(height) + delta await browser.setDimensions({ width: largeWidth, height: largeHeight, }) expect(await getComputed(browser, id, 'width')).toBe(largeWidth) expect(await getComputed(browser, id, 'height')).toBe(largeHeight) - const smallWidth = width - delta - const smallHeight = height - delta + const smallWidth = Number(width) - delta + const smallHeight = Number(height) - delta await browser.setDimensions({ width: smallWidth, height: smallHeight, @@ -722,7 +722,7 @@ function runTests(mode) { if (mode === 'dev') { await waitFor(1000) - const warnings = (await browser.log('browser')) + const warnings = (await browser.log()) .map((log) => log.message) .join('\n') expect(warnings).toMatch( @@ -749,9 +749,7 @@ function runTests(mode) { expect(await hasRedbox(browser)).toBe(false) await check(async () => { - return (await browser.log('browser')) - .map((log) => log.message) - .join('\n') + return (await browser.log()).map((log) => log.message).join('\n') }, /Image is missing required "src" property/gm) }) @@ -807,9 +805,7 @@ function runTests(mode) { const browser = await webdriver(appPort, '/layout-responsive-inside-flex') await browser.eval(`document.getElementById("img").scrollIntoView()`) await check(async () => { - return (await browser.log('browser')) - .map((log) => log.message) - .join('\n') + return (await browser.log()).map((log) => log.message).join('\n') }, /Image with src (.*)jpg(.*) may not render properly as a child of a flex container. Consider wrapping the image with a div to configure the width/gm) expect(await hasRedbox(browser)).toBe(false) }) @@ -821,7 +817,7 @@ function runTests(mode) { ) await browser.eval(`document.querySelector("footer").scrollIntoView()`) await waitFor(1000) - const warnings = (await browser.log('browser')) + const warnings = (await browser.log()) .map((log) => log.message) .join('\n') expect(warnings).toMatch( @@ -842,7 +838,7 @@ function runTests(mode) { it('should warn when using a very small image with placeholder=blur', async () => { const browser = await webdriver(appPort, '/small-img-import') - const warnings = (await browser.log('browser')) + const warnings = (await browser.log()) .map((log) => log.message) .join('\n') expect(await hasRedbox(browser)).toBe(false) @@ -854,7 +850,7 @@ function runTests(mode) { it('should not warn when Image is child of p', async () => { const browser = await webdriver(appPort, '/inside-paragraph') - const warnings = (await browser.log('browser')) + const warnings = (await browser.log()) .map((log) => log.message) .join('\n') expect(await hasRedbox(browser)).toBe(false) @@ -879,7 +875,7 @@ function runTests(mode) { return 'done' }, 'done') await waitFor(1000) - const warnings = (await browser.log('browser')) + const warnings = (await browser.log()) .map((log) => log.message) .join('\n') expect(await hasRedbox(browser)).toBe(false) @@ -896,7 +892,7 @@ function runTests(mode) { it('should warn when loader is missing width', async () => { const browser = await webdriver(appPort, '/invalid-loader') await browser.eval(`document.querySelector("footer").scrollIntoView()`) - const warnings = (await browser.log('browser')) + const warnings = (await browser.log()) .map((log) => log.message) .join('\n') expect(await hasRedbox(browser)).toBe(false) @@ -920,7 +916,7 @@ function runTests(mode) { it('should warn when using sizes with incorrect layout', async () => { const browser = await webdriver(appPort, '/invalid-sizes') await browser.eval(`document.querySelector("footer").scrollIntoView()`) - const warnings = (await browser.log('browser')) + const warnings = (await browser.log()) .map((log) => log.message) .join('\n') expect(await hasRedbox(browser)).toBe(false) @@ -941,7 +937,7 @@ function runTests(mode) { it('should not warn when svg, even if with loader prop or without', async () => { const browser = await webdriver(appPort, '/loader-svg') await browser.eval(`document.querySelector("footer").scrollIntoView()`) - const warnings = (await browser.log('browser')) + const warnings = (await browser.log()) .map((log) => log.message) .join('\n') expect(await hasRedbox(browser)).toBe(false) @@ -981,7 +977,7 @@ function runTests(mode) { return 'done' }, 'done') await waitFor(1000) - const warnings = (await browser.log('browser')) + const warnings = (await browser.log()) .map((log) => log.message) .filter((log) => log.startsWith('Image with src')) expect(warnings[0]).toMatch( @@ -1397,12 +1393,12 @@ function runTests(mode) { await waitFor(1000) expect(await browser.hasElementByCssSelector('img')).toBeTruthy() const url = await browser.url() - const result = await validateHTML({ + const result = (await validateHTML({ url, format: 'json', isLocal: true, validator: 'whatwg', - }) + })) as any expect(result.isValid).toBe(true) expect(result.errors).toEqual([]) } finally { diff --git a/test/integration/image-component/default/test/static.test.js b/test/integration/image-component/default/test/static.test.ts similarity index 100% rename from test/integration/image-component/default/test/static.test.js rename to test/integration/image-component/default/test/static.test.ts diff --git a/test/integration/image-component/image-from-node-modules/test/index.test.js b/test/integration/image-component/image-from-node-modules/test/index.test.ts similarity index 100% rename from test/integration/image-component/image-from-node-modules/test/index.test.js rename to test/integration/image-component/image-from-node-modules/test/index.test.ts diff --git a/test/integration/image-component/no-intersection-observer-fallback/test/index.test.js b/test/integration/image-component/no-intersection-observer-fallback/test/index.test.ts similarity index 100% rename from test/integration/image-component/no-intersection-observer-fallback/test/index.test.js rename to test/integration/image-component/no-intersection-observer-fallback/test/index.test.ts diff --git a/test/integration/image-component/noscript/test/index.test.js b/test/integration/image-component/noscript/test/index.test.ts similarity index 100% rename from test/integration/image-component/noscript/test/index.test.js rename to test/integration/image-component/noscript/test/index.test.ts diff --git a/test/integration/image-future/react-virtualized/test/index.test.js b/test/integration/image-component/react-virtualized/test/index.test.ts similarity index 96% rename from test/integration/image-future/react-virtualized/test/index.test.js rename to test/integration/image-component/react-virtualized/test/index.test.ts index 6e98101e95e..84bdd65188f 100644 --- a/test/integration/image-future/react-virtualized/test/index.test.js +++ b/test/integration/image-component/react-virtualized/test/index.test.ts @@ -16,7 +16,7 @@ import http from 'http' const appDir = join(__dirname, '../') let appPort let app -let proxyServer +let proxyServer: http.Server let cancelCount = 0 describe('react-virtualized wrapping next/image', () => { describe('production', () => { @@ -51,7 +51,7 @@ describe('react-virtualized wrapping next/image', () => { console.warn('Failed to proxy', err) }) - await new Promise((resolve) => { + await new Promise((resolve) => { proxyServer.listen(appPort, () => resolve()) }) }) diff --git a/test/integration/image-component/svgo-webpack/test/index.test.js b/test/integration/image-component/svgo-webpack/test/index.test.ts similarity index 100% rename from test/integration/image-component/svgo-webpack/test/index.test.js rename to test/integration/image-component/svgo-webpack/test/index.test.ts diff --git a/test/integration/image-component/trailing-slash/test/index.test.js b/test/integration/image-component/trailing-slash/test/index.test.ts similarity index 100% rename from test/integration/image-component/trailing-slash/test/index.test.js rename to test/integration/image-component/trailing-slash/test/index.test.ts diff --git a/test/integration/image-component/typescript/test/index.test.js b/test/integration/image-component/typescript/test/index.test.ts similarity index 100% rename from test/integration/image-component/typescript/test/index.test.js rename to test/integration/image-component/typescript/test/index.test.ts diff --git a/test/integration/image-component/unicode/test/index.test.js b/test/integration/image-component/unicode/test/index.test.ts similarity index 100% rename from test/integration/image-component/unicode/test/index.test.js rename to test/integration/image-component/unicode/test/index.test.ts diff --git a/test/integration/image-component/unoptimized/test/index.test.js b/test/integration/image-component/unoptimized/test/index.test.ts similarity index 98% rename from test/integration/image-component/unoptimized/test/index.test.js rename to test/integration/image-component/unoptimized/test/index.test.ts index 55274903163..2ad21978a2e 100644 --- a/test/integration/image-component/unoptimized/test/index.test.js +++ b/test/integration/image-component/unoptimized/test/index.test.ts @@ -107,7 +107,7 @@ describe('Unoptimized Image Tests', () => { await killApp(app) }) - runTests('dev') + runTests() }) describe('server mode', () => { @@ -120,6 +120,6 @@ describe('Unoptimized Image Tests', () => { await killApp(app) }) - runTests('server') + runTests() }) }) diff --git a/test/integration/image-future/default/test/index.test.js b/test/integration/image-future/default/test/index.test.ts similarity index 98% rename from test/integration/image-future/default/test/index.test.js rename to test/integration/image-future/default/test/index.test.ts index 95570ddbd14..bf6a00d046e 100644 --- a/test/integration/image-future/default/test/index.test.js +++ b/test/integration/image-future/default/test/index.test.ts @@ -624,9 +624,7 @@ function runTests(mode) { expect(await hasRedbox(browser)).toBe(false) await check(async () => { - return (await browser.log('browser')) - .map((log) => log.message) - .join('\n') + return (await browser.log()).map((log) => log.message).join('\n') }, /Image is missing required "src" property/gm) }) @@ -726,7 +724,7 @@ function runTests(mode) { it('should warn when using a very small image with placeholder=blur', async () => { const browser = await webdriver(appPort, '/small-img-import') - const warnings = (await browser.log('browser')) + const warnings = (await browser.log()) .map((log) => log.message) .join('\n') expect(await hasRedbox(browser)).toBe(false) @@ -738,7 +736,7 @@ function runTests(mode) { it('should not warn when Image is child of p', async () => { const browser = await webdriver(appPort, '/inside-paragraph') - const warnings = (await browser.log('browser')) + const warnings = (await browser.log()) .map((log) => log.message) .join('\n') expect(await hasRedbox(browser)).toBe(false) @@ -780,7 +778,7 @@ function runTests(mode) { it('should warn when loader is missing width', async () => { const browser = await webdriver(appPort, '/invalid-loader') await browser.eval(`document.querySelector("footer").scrollIntoView()`) - const warnings = (await browser.log('browser')) + const warnings = (await browser.log()) .map((log) => log.message) .join('\n') expect(await hasRedbox(browser)).toBe(false) @@ -804,7 +802,7 @@ function runTests(mode) { it('should not warn when svg, even if with loader prop or without', async () => { const browser = await webdriver(appPort, '/loader-svg') await browser.eval(`document.querySelector("footer").scrollIntoView()`) - const warnings = (await browser.log('browser')) + const warnings = (await browser.log()) .map((log) => log.message) .join('\n') expect(await hasRedbox(browser)).toBe(false) @@ -844,7 +842,7 @@ function runTests(mode) { return 'done' }, 'done') await waitFor(1000) - const warnings = (await browser.log('browser')) + const warnings = (await browser.log()) .map((log) => log.message) .filter((log) => log.startsWith('Image with src')) expect(warnings[0]).toMatch( @@ -1120,12 +1118,12 @@ function runTests(mode) { await waitFor(1000) expect(await browser.hasElementByCssSelector('img')).toBeTruthy() const url = await browser.url() - const result = await validateHTML({ + const result = (await validateHTML({ url, format: 'json', isLocal: true, validator: 'whatwg', - }) + })) as any expect(result.isValid).toBe(true) expect(result.errors).toEqual([]) } finally { diff --git a/test/integration/image-future/default/test/static.test.js b/test/integration/image-future/default/test/static.test.ts similarity index 100% rename from test/integration/image-future/default/test/static.test.js rename to test/integration/image-future/default/test/static.test.ts diff --git a/test/integration/image-future/image-from-node-modules/test/index.test.js b/test/integration/image-future/image-from-node-modules/test/index.test.ts similarity index 100% rename from test/integration/image-future/image-from-node-modules/test/index.test.js rename to test/integration/image-future/image-from-node-modules/test/index.test.ts diff --git a/test/integration/image-future/noscript/test/index.test.js b/test/integration/image-future/noscript/test/index.test.ts similarity index 100% rename from test/integration/image-future/noscript/test/index.test.js rename to test/integration/image-future/noscript/test/index.test.ts diff --git a/test/integration/image-component/react-virtualized/test/index.test.js b/test/integration/image-future/react-virtualized/test/index.test.ts similarity index 96% rename from test/integration/image-component/react-virtualized/test/index.test.js rename to test/integration/image-future/react-virtualized/test/index.test.ts index 6e98101e95e..84bdd65188f 100644 --- a/test/integration/image-component/react-virtualized/test/index.test.js +++ b/test/integration/image-future/react-virtualized/test/index.test.ts @@ -16,7 +16,7 @@ import http from 'http' const appDir = join(__dirname, '../') let appPort let app -let proxyServer +let proxyServer: http.Server let cancelCount = 0 describe('react-virtualized wrapping next/image', () => { describe('production', () => { @@ -51,7 +51,7 @@ describe('react-virtualized wrapping next/image', () => { console.warn('Failed to proxy', err) }) - await new Promise((resolve) => { + await new Promise((resolve) => { proxyServer.listen(appPort, () => resolve()) }) }) diff --git a/test/integration/image-future/svgo-webpack/test/index.test.js b/test/integration/image-future/svgo-webpack/test/index.test.ts similarity index 100% rename from test/integration/image-future/svgo-webpack/test/index.test.js rename to test/integration/image-future/svgo-webpack/test/index.test.ts diff --git a/test/integration/image-future/trailing-slash/test/index.test.js b/test/integration/image-future/trailing-slash/test/index.test.ts similarity index 100% rename from test/integration/image-future/trailing-slash/test/index.test.js rename to test/integration/image-future/trailing-slash/test/index.test.ts diff --git a/test/integration/image-future/typescript/test/index.test.js b/test/integration/image-future/typescript/test/index.test.ts similarity index 100% rename from test/integration/image-future/typescript/test/index.test.js rename to test/integration/image-future/typescript/test/index.test.ts diff --git a/test/integration/image-future/unicode/test/index.test.js b/test/integration/image-future/unicode/test/index.test.ts similarity index 100% rename from test/integration/image-future/unicode/test/index.test.js rename to test/integration/image-future/unicode/test/index.test.ts diff --git a/test/integration/image-future/unoptimized/test/index.test.js b/test/integration/image-future/unoptimized/test/index.test.ts similarity index 98% rename from test/integration/image-future/unoptimized/test/index.test.js rename to test/integration/image-future/unoptimized/test/index.test.ts index 81c815ab244..cad697645aa 100644 --- a/test/integration/image-future/unoptimized/test/index.test.js +++ b/test/integration/image-future/unoptimized/test/index.test.ts @@ -102,7 +102,7 @@ describe('Unoptimized Image Tests', () => { await killApp(app) }) - runTests('dev') + runTests() }) describe('server mode', () => { @@ -115,6 +115,6 @@ describe('Unoptimized Image Tests', () => { await killApp(app) }) - runTests('server') + runTests() }) }) diff --git a/test/lib/browsers/base.ts b/test/lib/browsers/base.ts index 499f4855353..748270aca30 100644 --- a/test/lib/browsers/base.ts +++ b/test/lib/browsers/base.ts @@ -97,7 +97,9 @@ export class BrowserInterface { async hasElementByCssSelector(selector: string): Promise { return false } - async log(): Promise { + async log(): Promise< + { source: 'error' | 'info' | 'log'; message: string }[] + > { return [] } async websocketFrames(): Promise { diff --git a/test/lib/browsers/playwright.ts b/test/lib/browsers/playwright.ts index 772441482c4..cfa313108c0 100644 --- a/test/lib/browsers/playwright.ts +++ b/test/lib/browsers/playwright.ts @@ -27,7 +27,7 @@ export async function quit() { browser = undefined } -class Playwright extends BrowserInterface { +export class Playwright extends BrowserInterface { private activeTrace?: string private eventCallbacks: Record void>> = { request: new Set(), @@ -385,5 +385,3 @@ class Playwright extends BrowserInterface { return this.chain(() => page.evaluate('window.location.href')) as any } } - -export default Playwright diff --git a/test/lib/browsers/selenium.ts b/test/lib/browsers/selenium.ts index b85f0c6b148..e6e8c1aa001 100644 --- a/test/lib/browsers/selenium.ts +++ b/test/lib/browsers/selenium.ts @@ -42,7 +42,7 @@ export async function quit() { seleniumServer = undefined } -class Selenium extends BrowserInterface { +export class Selenium extends BrowserInterface { private browserName: string // TODO: support setting locale @@ -356,5 +356,3 @@ class Selenium extends BrowserInterface { return this.chain(() => browser.getCurrentUrl()) as any } } - -export default Selenium diff --git a/test/lib/next-webdriver.ts b/test/lib/next-webdriver.ts index dd3f7a67faa..a2d3ab21132 100644 --- a/test/lib/next-webdriver.ts +++ b/test/lib/next-webdriver.ts @@ -26,7 +26,7 @@ if (isBrowserStack) { } } -let browserQuit +let browserQuit: () => Promise if (typeof afterAll === 'function') { afterAll(async () => { @@ -81,13 +81,13 @@ export default async function webdriver( // we import only the needed interface if (USE_SELENIUM) { - const browserMod = require('./browsers/selenium') - CurrentInterface = browserMod.default - browserQuit = browserMod.quit + const { Selenium, quit } = await import('./browsers/selenium') + CurrentInterface = Selenium + browserQuit = quit } else { - const browserMod = require('./browsers/playwright') - CurrentInterface = browserMod.default - browserQuit = browserMod.quit + const { Playwright, quit } = await import('./browsers/playwright') + CurrentInterface = Playwright + browserQuit = quit } const browser = new CurrentInterface()