Files
next.js/test/development/client-dev-overlay/index.test.ts
Arian Tron 61f56f997c
Some checks failed
Test examples / Test Examples (20) (push) Has been cancelled
Test examples / Test Examples (22) (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Trigger Release / start (push) Has been cancelled
Stale issue handler / stale (push) Has been cancelled
Update Font Data / create-pull-request (push) Has been cancelled
build-and-deploy / deploy-target (push) Has been cancelled
build-and-deploy / build (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / build-wasm (nodejs) (push) Has been cancelled
build-and-deploy / build-wasm (web) (push) Has been cancelled
build-and-deploy / Deploy preview tarball (push) Has been cancelled
build-and-deploy / Potentially publish release (push) Has been cancelled
build-and-deploy / publish-turbopack-npm-packages (push) Has been cancelled
build-and-deploy / Deploy examples (push) Has been cancelled
build-and-deploy / thank you, build (push) Has been cancelled
build-and-deploy / Upload Turbopack Bytesize metrics to Datadog (push) Has been cancelled
Rspack Next.js development integration tests / Rspack integration tests (push) Has been cancelled
Rspack Next.js production integration tests / Rspack integration tests (push) Has been cancelled
Turbopack Next.js development integration tests / Next.js integration tests (push) Has been cancelled
Turbopack Next.js production integration tests / Next.js integration tests (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack development test manifest (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack production test manifest (push) Has been cancelled
Upload bundler test manifests to areweturboyet.com / Upload test results (push) Has been cancelled
Update React / create-pull-request (push) Has been cancelled
test-e2e-project-reset-cron / reset-test-project (push) Has been cancelled
Notify about the top 15 issues/PRs/feature requests (most reacted) in the last 90 days / run (push) Has been cancelled
first commit
2026-03-10 19:37:31 +03:30

222 lines
6.5 KiB
TypeScript

import { FileRef } from 'e2e-utils'
import { Playwright } from 'next-webdriver'
import { nextTestSetup } from 'e2e-utils'
import { join } from 'path'
import { waitForDevToolsIndicator, retry } from 'next-test-utils'
describe('client-dev-overlay', () => {
const { next, isTurbopack } = nextTestSetup({
files: {
pages: new FileRef(join(__dirname, 'pages')),
},
env: {
// Disable the cooldown period for the dev indicator so that hiding the indicator in a test doesn't
// impact subsequent tests.
__NEXT_DEV_INDICATOR_COOLDOWN_MS: '0',
},
})
// The `Playwright.hasElementByCssSelector` cannot be used for elements inside a shadow DOM.
function elementExistsInNextJSPortalShadowDOM(
browser: Playwright,
selector: string
) {
return browser.eval(
`!!document.querySelector('nextjs-portal').shadowRoot.querySelector('${selector}')`
) as any
}
const selectors = {
fullScreenDialog: '[data-nextjs-dialog]',
toast: '[data-nextjs-toast]',
popover: '[data-nextjs-dev-tools-button]',
indicator: '[data-next-badge-root]',
minimizeButton: 'body',
preferencesButton: '[data-preferences]',
hideButton: '[data-hide-dev-tools]',
}
function getToast(browser: Playwright) {
return browser.elementByCss(selectors.toast)
}
function getPopover(browser: Playwright) {
return browser.elementByCss(selectors.popover)
}
function getMinimizeButton(browser: Playwright) {
return browser.elementByCss(selectors.minimizeButton)
}
function getHideButton(browser: Playwright) {
return browser.elementByCss(selectors.hideButton)
}
function getPreferencesButton(browser: Playwright) {
return browser.elementByCss(selectors.preferencesButton)
}
it('should be able to fullscreen the minimized overlay', async () => {
const browser = await next.browser('/')
await getMinimizeButton(browser).click()
await getToast(browser).click()
await retry(async () => {
expect(
await elementExistsInNextJSPortalShadowDOM(
browser,
selectors.fullScreenDialog
)
).toBe(true)
})
})
it('should be able to minimize the fullscreen overlay', async () => {
const browser = await next.browser('/')
await getMinimizeButton(browser).click()
expect(
await elementExistsInNextJSPortalShadowDOM(browser, selectors.toast)
).toBe(true)
})
it('should keep the error indicator visible when there are errors', async () => {
const browser = await next.browser('/')
await getMinimizeButton(browser).click()
await getPopover(browser).click()
await getPreferencesButton(browser).click()
await getHideButton(browser).click()
await retry(async () => {
const display = await browser.eval(
`getComputedStyle(document.querySelector('nextjs-portal').shadowRoot.querySelector('${selectors.indicator}')).display`
)
expect(display).toBe('block')
})
})
it('should be possible to hide the minimized overlay when there are no errors', async () => {
const browser = await next.browser('/')
const originalContent = await next.readFile('pages/index.js')
try {
await next.patchFile('pages/index.js', (content) => {
return content.replace(`throw Error('example runtime error')`, '')
})
await getMinimizeButton(browser).click()
await getPopover(browser).click()
await getPreferencesButton(browser).click()
await getHideButton(browser).click()
await retry(async () => {
const display = await browser.eval(
`getComputedStyle(document.querySelector('nextjs-portal').shadowRoot.querySelector('${selectors.indicator}')).display`
)
expect(display).toBe('none')
})
} finally {
await next.patchFile('pages/index.js', originalContent)
}
})
it('should have a role of "dialog" if the page is focused', async () => {
const browser = await next.browser('/')
await retry(async () => {
expect(
await elementExistsInNextJSPortalShadowDOM(browser, '[role="dialog"]')
).toBe(true)
})
})
it('should nudge to use Turbopack unless Turbopack is disabled', async () => {
const browser = await next.browser('/')
// Don't use toggleDevToolsIndicatorPopover because this is asserting something in the old dev tools menu which isn't preset yet in the new UI.
const devToolsIndicator = await waitForDevToolsIndicator(browser)
try {
await devToolsIndicator.click()
} catch (cause) {
const error = new Error('No DevTools Indicator to open.', { cause })
throw error
}
const devtoolsMenu = await browser.elementByCss('#nextjs-dev-tools-menu')
if (isTurbopack) {
expect(await devtoolsMenu.innerText()).toMatchInlineSnapshot(`
"Issues
1
Route
Static
Bundler
Turbopack
Preferences"
`)
} else {
expect(await devtoolsMenu.innerText()).toMatchInlineSnapshot(`
"Issues
1
Route
Static
Bundler
Webpack
Preferences"
`)
}
})
})
describe('client-dev-overlay with Cache Components', () => {
const { next, isTurbopack } = nextTestSetup({
files: {
pages: new FileRef(join(__dirname, 'pages')),
'next.config.js': `
module.exports = {
cacheComponents: true,
}
`,
},
env: {
__NEXT_DEV_INDICATOR_COOLDOWN_MS: '0',
},
})
it('should show Cache Components as enabled in the devtools menu', async () => {
const browser = await next.browser('/')
const devToolsIndicator = await waitForDevToolsIndicator(browser)
try {
await devToolsIndicator.click()
} catch (cause) {
const error = new Error('No DevTools Indicator to open.', { cause })
throw error
}
const devtoolsMenu = await browser.elementByCss('#nextjs-dev-tools-menu')
const menuText = await devtoolsMenu.innerText()
// Should include Cache Components
expect(menuText).toContain('Cache Components')
expect(menuText).toContain('Enabled')
// Should also include Turbopack info
if (isTurbopack) {
expect(menuText).toMatchInlineSnapshot(`
"Issues
1
Route
Static
Bundler
Turbopack
Cache Components
Enabled
Preferences"
`)
} else {
expect(menuText).toMatchInlineSnapshot(`
"Issues
1
Route
Static
Bundler
Webpack
Cache Components
Enabled
Preferences"
`)
}
})
})