{count}
/* eslint-env jest */
import { sandbox } from './helpers'
jest.setTimeout(1000 * 60 * 5)
test('logbox: can recover from a syntax error without losing state', async () => {
const [session, cleanup] = await sandbox()
await session.patch(
'index.js',
`
import { useCallback, useState } from 'react'
export default function Index() {
const [count, setCount] = useState(0)
const increment = useCallback(() => setCount(c => c + 1), [setCount])
return (
{count}
Count: {count}
{count}
Count: {count}
Hello
; } ` ) await session.patch( 'index.js', ` import Child from './child' export default function Index() { return (Hello
; } ` ) expect(didNotReload).toBe(true) expect(await session.hasRedbox()).toBe(false) expect( await session.evaluate(() => document.querySelector('p').textContent) ).toBe('Hello') await cleanup() }) // https://github.com/pmmmwh/react-refresh-webpack-plugin/pull/3#issuecomment-554137262 test('render error not shown right after syntax error', async () => { const [session, cleanup] = await sandbox() // Starting here: await session.patch( 'index.js', ` class ClassDefault extends React.Component { render() { returnlol
lol
div ) } ` ) expect(await session.hasRedbox(true)).toBe(true) const source = await session.getRedboxSource() expect(source).toMatchInlineSnapshot(` "./index.js:5:22 Syntax error: Unterminated JSX contents 3 | return ( 4 |lol
| ^ 6 | div 7 | ) 8 | }" `) await cleanup() }) test('conversion to class component (1)', async () => { const [session, cleanup] = await sandbox() await session.write( 'Child.js', ` export default function ClickCount() { returnhello
} ` ) await session.patch( 'index.js', ` import Child from './Child'; export default function Home() { return (hello new
} } ` ) expect(await session.hasRedbox()).toBe(false) expect( await session.evaluate(() => document.querySelector('p').textContent) ).toBe('hello new') await cleanup() }) test('css syntax errors', async () => { const [session, cleanup] = await sandbox() await session.write('index.module.css', `.button {}`) await session.patch( 'index.js', ` import './index.module.css'; export default () => { return (lol
lol