Skip to content

Commit

Permalink
Remove hasRedbox()
Browse files Browse the repository at this point in the history
in favor of `assertHasRedbox` and `assertNoRedbox`.

hasRedbox() has a hardcoded timeout of 5s that is only used for the negative assertion.
Instead, we now have dedicated assertions for the positive (`assertHasRedbox`) and negative case (`assertNoRedbox`).
The negative assertion still has the hardcoded timeout.
But the positive assertion just retries until we find the Redbox.

This speeds up tests using the positive assertion.
Removing `hasRedbox` also uncovered some unused expressions e.g. `await hasRedbox(browser)`.
These expressions probably wanted to use `expect(await hasRedbox(browser)).toBe(true)`
  • Loading branch information
eps1lon committed Jun 19, 2024
1 parent 9ff5c44 commit 7316adc
Show file tree
Hide file tree
Showing 86 changed files with 553 additions and 503 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
}
`
)
expect(await session.hasRedbox()).toBe(true)
await session.assertHasRedbox()
if (process.env.TURBOPACK) {
expect(await session.getRedboxSource()).toMatchInlineSnapshot(`
"./node_modules/my-package/index.js:1:13
Expand Down Expand Up @@ -92,7 +92,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
`
)

expect(await session.hasRedbox()).toBe(true)
await session.assertHasRedbox()

const source = await session.getRedboxSource()
if (process.env.TURBOPACK) {
Expand Down Expand Up @@ -145,7 +145,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
`
)

expect(await session.hasRedbox()).toBe(true)
await session.assertHasRedbox()

const source = await session.getRedboxSource()
if (process.env.TURBOPACK) {
Expand Down Expand Up @@ -195,7 +195,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
],
])
)
expect(await session.hasRedbox()).toBe(true)
await session.assertHasRedbox()

const source = await session.getRedboxSource()
if (process.env.TURBOPACK) {
Expand Down Expand Up @@ -234,7 +234,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
}
`
)
expect(await session.hasRedbox()).toBe(false)
await session.assertNoRedbox()
expect(
await session.evaluate(() => document.documentElement.innerHTML)
).toContain('index page')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ describe.skip('ReactRefreshLogBox scss app', () => {
`
)

expect(await session.hasRedbox()).toBe(false)
await session.assertNoRedbox()

// Syntax error
await session.patch('index.module.scss', `.button { font-size: :5px; }`)
expect(await session.hasRedbox()).toBe(true)
await session.assertHasRedbox()
const source = await session.getRedboxSource()
expect(source).toMatchSnapshot()

// Fix syntax error
await session.patch('index.module.scss', `.button { font-size: 5px; }`)
expect(await session.hasRedbox()).toBe(false)
await session.assertNoRedbox()

await cleanup()
})
Expand All @@ -69,7 +69,7 @@ describe.skip('ReactRefreshLogBox scss app', () => {
// Checks for selectors that can't be prefixed.
// Selector "button" is not pure (pure selectors must contain at least one local class or id)
await session.patch('index.module.scss', `button { font-size: 5px; }`)
expect(await session.hasRedbox()).toBe(true)
await session.assertHasRedbox()
const source2 = await session.getRedboxSource()
expect(source2).toMatchSnapshot()

Expand Down
60 changes: 30 additions & 30 deletions test/development/acceptance-app/ReactRefreshLogBox.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
`
)

expect(await session.hasRedbox()).toBe(true)
await session.assertHasRedbox()
if (process.platform === 'win32') {
expect(await session.getRedboxSource()).toMatchSnapshot()
} else {
Expand Down Expand Up @@ -175,7 +175,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
`
)

expect(await session.hasRedbox()).toBe(true)
await session.assertHasRedbox()
// We internally only check the script path, not including the line number
// and error message because the error comes from an external library.
// This test ensures that the errored script path is correctly resolved.
Expand All @@ -202,7 +202,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
`
)

expect(await session.hasRedbox()).toBe(false)
await session.assertNoRedbox()

await session.patch(
'index.js',
Expand All @@ -217,7 +217,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
`
)

expect(await session.hasRedbox()).toBe(true)
await session.assertHasRedbox()

const source = next.normalizeTestDirContent(await session.getRedboxSource())
if (IS_TURBOPACK) {
Expand Down Expand Up @@ -292,7 +292,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
`
)

expect(await session.hasRedbox()).toBe(false)
await session.assertNoRedbox()
expect(
await session.evaluate(() => document.querySelector('p').textContent)
).toBe('hello')
Expand All @@ -309,7 +309,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
`
)

expect(await session.hasRedbox()).toBe(true)
await session.assertHasRedbox()
expect(await session.getRedboxSource()).toMatchSnapshot()

await session.patch(
Expand All @@ -324,7 +324,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
`
)

expect(await session.hasRedbox()).toBe(false)
await session.assertNoRedbox()
expect(
await session.evaluate(() => document.querySelector('p').textContent)
).toBe('hello new')
Expand All @@ -350,11 +350,11 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
`
)

expect(await session.hasRedbox()).toBe(false)
await session.assertNoRedbox()

// Syntax error
await session.patch('index.module.css', `.button`)
expect(await session.hasRedbox()).toBe(true)
await session.assertHasRedbox()
const source = await session.getRedboxSource()
expect(source).toMatch(
IS_TURBOPACK ? './index.module.css:1:9' : './index.module.css:1:1'
Expand All @@ -369,7 +369,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
// Checks for selectors that can't be prefixed.
// Selector "button" is not pure (pure selectors must contain at least one local class or id)
await session.patch('index.module.css', `button {}`)
expect(await session.hasRedbox()).toBe(true)
await session.assertHasRedbox()
const source2 = await session.getRedboxSource()
expect(source2).toMatchSnapshot()

Expand Down Expand Up @@ -593,7 +593,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
`
)

expect(await session.hasRedbox()).toBe(true)
await session.assertHasRedbox()
expect(await session.getRedboxDescription()).toMatchInlineSnapshot(
`"Error: {"a":1,"b":"x"}"`
)
Expand All @@ -609,7 +609,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
}
`
)
expect(await session.hasRedbox()).toBe(false)
await session.assertNoRedbox()
await session.patch(
'index.js',
outdent`
Expand All @@ -623,7 +623,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
}
`
)
expect(await session.hasRedbox()).toBe(true)
await session.assertHasRedbox()
expect(await session.getRedboxDescription()).toContain(
`Error: class Hello {`
)
Expand All @@ -639,7 +639,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
}
`
)
expect(await session.hasRedbox()).toBe(false)
await session.assertNoRedbox()
await session.patch(
'index.js',
outdent`
Expand All @@ -651,7 +651,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
}
`
)
expect(await session.hasRedbox()).toBe(true)
await session.assertHasRedbox()
expect(await session.getRedboxDescription()).toMatchInlineSnapshot(
`"Error: string error"`
)
Expand All @@ -667,7 +667,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
}
`
)
expect(await session.hasRedbox()).toBe(false)
await session.assertNoRedbox()
await session.patch(
'index.js',
outdent`
Expand All @@ -679,7 +679,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
}
`
)
expect(await session.hasRedbox()).toBe(true)
await session.assertHasRedbox()
expect(await session.getRedboxDescription()).toContain(
`Error: A null error was thrown`
)
Expand All @@ -703,7 +703,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
`
)

expect(await session.hasRedbox()).toBe(true)
await session.assertHasRedbox()
expect(await session.getRedboxSource()).toMatchSnapshot()

await cleanup()
Expand Down Expand Up @@ -764,7 +764,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
() => browser.elementByCss('.nextjs-toast-errors').text(),
/4 errors/
)
expect(await session.hasRedbox()).toBe(false)
await session.assertNoRedbox()

// Add Component error
await session.patch(
Expand All @@ -776,7 +776,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
)

// Render error should "win" and show up in fullscreen
expect(await session.hasRedbox()).toBe(true)
await session.assertHasRedbox()

await cleanup()
})
Expand Down Expand Up @@ -815,7 +815,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
])('Call stack count is correct for %s error', async (_, fixture) => {
const { session, browser, cleanup } = await sandbox(next, fixture)

expect(await session.hasRedbox()).toBe(true)
await session.assertHasRedbox()

await expandCallStack(browser)

Expand Down Expand Up @@ -856,7 +856,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
],
])
)
expect(await session.hasRedbox()).toBe(true)
await session.assertHasRedbox()
await expandCallStack(browser)
let callStackFrames = await browser.elementsByCss(
'[data-nextjs-call-stack-frame]'
Expand Down Expand Up @@ -884,7 +884,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
])
)

expect(await session.hasRedbox()).toBe(true)
await session.assertHasRedbox()
await expandCallStack(browser)

// Should still show the errored line in source code
Expand Down Expand Up @@ -919,7 +919,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
],
])
)
expect(await session.hasRedbox()).toBe(true)
await session.assertHasRedbox()

// Remove error
await session.patch(
Expand All @@ -933,7 +933,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
expect(await browser.waitForElementByCss('#text').text()).toBe(
'Hello world'
)
expect(await session.hasRedbox()).toBe(false)
await session.assertNoRedbox()

// Re-add error
await session.patch(
Expand All @@ -946,7 +946,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
`
)

expect(await session.hasRedbox()).toBe(true)
await session.assertHasRedbox()

await cleanup()
})
Expand Down Expand Up @@ -974,7 +974,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
`
)

expect(await session.hasRedbox()).toBe(true)
await session.assertHasRedbox()
expect(await session.getRedboxSource()).toMatchSnapshot()

await cleanup()
Expand Down Expand Up @@ -1005,7 +1005,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
`
)

expect(await session.hasRedbox()).toBe(true)
await session.assertHasRedbox()
expect(await session.getRedboxSource()).toMatchSnapshot()

await cleanup()
Expand All @@ -1017,12 +1017,12 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
const { session, cleanup } = await sandbox(next, undefined, '/' + type)

await next.patchFile('index.js', "throw new Error('module error')")
expect(await session.hasRedbox()).toBe(true)
await session.assertHasRedbox()
await next.patchFile(
'index.js',
'export default function Page() {return <p>hello world</p>}'
)
expect(await session.hasRedbox()).toBe(false)
await session.assertNoRedbox()

await cleanup()
})
Expand Down
Loading

0 comments on commit 7316adc

Please sign in to comment.