Skip to content

Commit

Permalink
Fix broken BrowserInterface type (vercel#66461)
Browse files Browse the repository at this point in the history
  • Loading branch information
unstubbable authored Jun 3, 2024
1 parent 48e9cd9 commit 994d8ee
Show file tree
Hide file tree
Showing 21 changed files with 112 additions and 133 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { type BrowserInterface } from 'next-webdriver'
import { nextTestSetup } from 'e2e-utils'
import { check } from 'next-test-utils'

Expand All @@ -8,7 +7,7 @@ describe('Strict Mode enabled by default', () => {
})
// TODO: modern StrictMode does not double invoke effects during hydration: https://github.com/facebook/react/pull/28951
it.skip('should work using browser', async () => {
const browser: BrowserInterface = await next.browser('/')
const browser = await next.browser('/')
await check(async () => {
const text = await browser.elementByCss('p').text()
// FIXME: Bug in React. Strict Effects no longer work in current beta.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('useDefineForClassFields SWC option', () => {
let data_foundLog = false
let name_foundLog = false

const browserLogs = await browser.log('browser')
const browserLogs = await browser.log()

browserLogs.forEach((log) => {
if (log.message.includes('data changed')) {
Expand Down
2 changes: 1 addition & 1 deletion test/development/basic/misc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe.each([[''], ['/docs']])(
let browser
try {
browser = await webdriver(next.url, path)
const browserLogs = await browser.log('browser')
const browserLogs = await browser.log()

browserLogs.forEach((log) => {
if (log.message.includes('Next.js auto-prefetches automatically')) {
Expand Down
2 changes: 1 addition & 1 deletion test/development/basic/next-dynamic/next-dynamic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ describe('next/dynamic', () => {
)

if ((global as any).browserName === 'chrome') {
const logs = await browser.log('browser')
const logs = await browser.log()

logs.forEach((logItem) => {
expect(logItem.message).not.toMatch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('styled-components SWC transform', () => {
async function matchLogs$(browser) {
let foundLog = false

const browserLogs = await browser.log('browser')
const browserLogs = await browser.log()

browserLogs.forEach((log) => {
if (log.message.includes('Warning: Prop `%s` did not match.')) {
Expand Down
8 changes: 4 additions & 4 deletions test/development/pages-dir/client-navigation/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ describe('Client Navigation', () => {
describe('check hydration mis-match', () => {
it('should not have hydration mis-match for hash link', async () => {
const browser = await webdriver(next.appPort, '/nav/hash-changes')
const browserLogs = await browser.log('browser')
const browserLogs = await browser.log()
let found = false
browserLogs.forEach((log) => {
console.log('log.message', log.message)
Expand Down Expand Up @@ -1717,7 +1717,7 @@ describe.each([[false], [true]])(

await browser.waitForElementByCss('h1')
await waitFor(1000)
const browserLogs = await browser.log('browser')
const browserLogs = await browser.log()
let foundStyles = false
let foundScripts = false
const logs = []
Expand Down Expand Up @@ -1750,7 +1750,7 @@ describe.each([[false], [true]])(
browser = await webdriver(next.appPort, '/head')
await browser.waitForElementByCss('h1')
await waitFor(1000)
const browserLogs = await browser.log('browser')
const browserLogs = await browser.log()
let found = false
browserLogs.forEach((log) => {
if (log.message.includes('Use next/script instead')) {
Expand All @@ -1771,7 +1771,7 @@ describe.each([[false], [true]])(
browser = await webdriver(next.appPort, '/head-with-json-ld-snippet')
await browser.waitForElementByCss('h1')
await waitFor(1000)
const browserLogs = await browser.log('browser')
const browserLogs = await browser.log()
let found = false
browserLogs.forEach((log) => {
if (log.message.includes('Use next/script instead')) {
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/app-dir/autoscroll-with-css-modules/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('router autoscrolling on navigation with css modules', () => {

describe('vertical scroll when page imports css modules', () => {
it('should scroll to top of document when navigating between to pages without layout when', async () => {
const browser: BrowserInterface = await next.browser('/1')
const browser = await next.browser('/1')

await scrollTo(browser, { x: 0, y: 1000 })
expect(await getTopScroll(browser)).toBe(1000)
Expand All @@ -46,7 +46,7 @@ describe('router autoscrolling on navigation with css modules', () => {
})

it('should scroll when clicking in JS', async () => {
const browser: BrowserInterface = await next.browser('/1')
const browser = await next.browser('/1')

await scrollTo(browser, { x: 0, y: 1000 })
expect(await getTopScroll(browser)).toBe(1000)
Expand Down
3 changes: 1 addition & 2 deletions test/e2e/app-dir/next-after-app/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import * as fs from 'fs'
import * as path from 'path'
import * as os from 'os'
import * as Log from './utils/log'
import { BrowserInterface } from '../../../lib/next-webdriver'

const runtimes = ['nodejs', 'edge']

Expand Down Expand Up @@ -257,7 +256,7 @@ describe.each(runtimes)('unstable_after() in %s runtime', (runtimeValue) => {
const EXPECTED_ERROR =
/An error occurred in a function passed to `unstable_after\(\)`: .+?: Cookies can only be modified in a Server Action or Route Handler\./

const browser: BrowserInterface = await next.browser('/123/setting-cookies')
const browser = await next.browser('/123/setting-cookies')
// after() from render
expect(next.cliOutput).toMatch(EXPECTED_ERROR)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('root-layout-redirect', () => {
.text()
).toBe('Result Page')

const browserLogs = await browser.log('browser')
const browserLogs = await browser.log()

let foundErrors = false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ describe('app dir - search params keys', () => {
it('should keep the React router instance the same when changing the search params', async () => {
const browser = await next.browser('/')

const searchParams = browser.waitForElementByCss('#search-params').text()
const searchParams = await browser
.waitForElementByCss('#search-params')
.text()

await browser.elementByCss('#increment').click()
await browser.elementByCss('#increment').click()

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/new-link-behavior/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import path from 'path'
async function matchLogs(browser, includes: string) {
let found = false

const browserLogs = await browser.log('browser')
const browserLogs = await browser.log()

browserLogs.forEach((log) => {
if (log.message.includes(includes)) {
Expand Down
4 changes: 2 additions & 2 deletions test/integration/app-document/test/csp.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default (context, render) => {
it('should load inline script by hash', async () => {
const browser = await webdriver(context.appPort, '/?withCSP=hash')
if (global.browserName === 'chrome') {
const errLog = await browser.log('browser')
const errLog = await browser.log()
expect(errLog.filter((e) => e.source === 'security')).toEqual([])
}
await browser.close()
Expand All @@ -15,7 +15,7 @@ export default (context, render) => {
it('should load inline script by nonce', async () => {
const browser = await webdriver(context.appPort, '/?withCSP=nonce')
if (global.browserName === 'chrome') {
const errLog = await browser.log('browser')
const errLog = await browser.log()
expect(errLog.filter((e) => e.source === 'security')).toEqual([])
}
await browser.close()
Expand Down
14 changes: 7 additions & 7 deletions test/integration/next-image-new/app-dir/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ function runTests(mode) {
await browser.elementById('belowthefold').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(
Expand Down Expand Up @@ -381,7 +381,7 @@ function runTests(mode) {
)

if (mode === 'dev') {
const warnings = (await browser.log('browser'))
const warnings = (await browser.log())
.map((log) => log.message)
.join('\n')
expect(warnings).toMatch(
Expand Down Expand Up @@ -657,7 +657,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(
Expand Down Expand Up @@ -1064,7 +1064,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)
Expand Down Expand Up @@ -1353,7 +1353,7 @@ function runTests(mode) {
if (mode === 'dev') {
it('should not log incorrect warnings', async () => {
await waitFor(1000)
const warnings = (await browser.log('browser'))
const warnings = (await browser.log())
.map((log) => log.message)
.join('\n')
expect(warnings).not.toMatch(/Image with src (.*) has "fill"/gm)
Expand All @@ -1364,7 +1364,7 @@ function runTests(mode) {
it('should log warnings when using fill mode incorrectly', async () => {
browser = await webdriver(appPort, '/fill-warnings')
await waitFor(1000)
const warnings = (await browser.log('browser'))
const warnings = (await browser.log())
.map((log) => log.message)
.join('\n')
expect(warnings).toContain(
Expand All @@ -1383,7 +1383,7 @@ function runTests(mode) {
it('should not log warnings when image unmounts', async () => {
browser = await webdriver(appPort, '/should-not-warn-unmount')
await waitFor(1000)
const warnings = (await browser.log('browser'))
const warnings = (await browser.log())
.map((log) => log.message)
.join('\n')
expect(warnings).not.toContain(
Expand Down
4 changes: 1 addition & 3 deletions test/integration/next-image-new/base-path/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,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)
})

Expand Down
12 changes: 6 additions & 6 deletions test/integration/next-image-new/default/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ function runTests(mode) {
await browser.elementById('belowthefold').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(
Expand Down Expand Up @@ -382,7 +382,7 @@ function runTests(mode) {
)

if (mode === 'dev') {
const warnings = (await browser.log('browser'))
const warnings = (await browser.log())
.map((log) => log.message)
.join('\n')
expect(warnings).toMatch(
Expand Down Expand Up @@ -658,7 +658,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(
Expand Down Expand Up @@ -1355,7 +1355,7 @@ function runTests(mode) {
if (mode === 'dev') {
it('should not log incorrect warnings', async () => {
await waitFor(1000)
const warnings = (await browser.log('browser'))
const warnings = (await browser.log())
.map((log) => log.message)
.join('\n')
expect(warnings).not.toMatch(/Image with src (.*) has "fill"/gm)
Expand All @@ -1366,7 +1366,7 @@ function runTests(mode) {
it('should log warnings when using fill mode incorrectly', async () => {
browser = await webdriver(appPort, '/fill-warnings')
await waitFor(1000)
const warnings = (await browser.log('browser'))
const warnings = (await browser.log())
.map((log) => log.message)
.join('\n')
expect(warnings).toContain(
Expand All @@ -1385,7 +1385,7 @@ function runTests(mode) {
it('should not log warnings when image unmounts', async () => {
browser = await webdriver(appPort, '/should-not-warn-unmount')
await waitFor(1000)
const warnings = (await browser.log('browser'))
const warnings = (await browser.log())
.map((log) => log.message)
.join('\n')
expect(warnings).not.toContain(
Expand Down
2 changes: 1 addition & 1 deletion test/integration/script-loader/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const runTests = (isDev) => {
await browser.waitForElementByCss('#onload-div')
await waitFor(1000)

const logs = await browser.log('browser')
const logs = await browser.log()
const filteredLogs = logs.filter(
(log) =>
!log.message.includes('Failed to load resource') &&
Expand Down
Loading

0 comments on commit 994d8ee

Please sign in to comment.