Unverified Commit 5ff48177 authored by Leah's avatar Leah Committed by GitHub

fix app-hmr-changes.test.ts by updating next-tweet (#52046)

parent 9f6cf08f
import { FileRef, nextTestSetup } from 'e2e-utils'
import { check, hasRedbox, waitFor, retry } from 'next-test-utils'
import { sandbox } from 'development-sandbox'
import path from 'path'
describe('Error overlay - RSC build errors', () => {
......@@ -8,7 +8,7 @@ describe('Error overlay - RSC build errors', () => {
dependencies: {
'@next/mdx': 'canary',
'react-wrap-balancer': '^0.2.4',
'next-tweet': '^0.6.0',
'react-tweet': '^2.0.2',
'@mdx-js/react': '^2.3.0',
tailwindcss: '^3.2.6',
typescript: 'latest',
......@@ -20,44 +20,43 @@ describe('Error overlay - RSC build errors', () => {
})
it('should handle successive HMR changes with errors correctly', async () => {
const browser = await retry(
() => next.browser('/2020/develop-preview-test'),
1000,
500
const { session, cleanup } = await sandbox(
next,
undefined,
'/2020/develop-preview-test'
)
await check(
() => browser.eval('document.documentElement.innerHTML'),
/A few years ago I tweeted/
)
expect(
await session.evaluate('document.documentElement.innerHTML')
).toContain('A few years ago I tweeted')
const pagePath = 'app/(post)/2020/develop-preview-test/page.mdx'
const originalPage = await next.readFile(pagePath)
const break1 = originalPage.replace('break 1', '<Figure>')
await next.patchFile(pagePath, break1)
await session.patch(pagePath, break1)
const break2 = break1.replace('{/* break point 2 */}', '<Figure />')
await next.patchFile(pagePath, break2)
await session.patch(pagePath, break2)
for (let i = 0; i < 5; i++) {
await next.patchFile(pagePath, break2.replace('break 3', '<Hello />'))
await session.patch(pagePath, break2.replace('break 3', '<Hello />'))
await next.patchFile(pagePath, break2)
expect(await hasRedbox(browser, true)).toBe(true)
await session.patch(pagePath, break2)
expect(await session.hasRedbox(true)).toBe(true)
await next.patchFile(pagePath, break1)
await waitFor(100)
await session.patch(pagePath, break1)
await next.patchFile(pagePath, originalPage)
expect(await hasRedbox(browser, false)).toBe(false)
await session.patch(pagePath, originalPage)
expect(await session.hasRedbox(false)).toBe(false)
}
await check(
() => browser.eval('document.documentElement.innerHTML'),
/A few years ago I tweeted/
)
expect(
await session.evaluate('document.documentElement.innerHTML')
).toContain('A few years ago I tweeted')
await cleanup()
})
})
import { NextTweet } from 'next-tweet'
import { Caption } from './caption'
import type { ReactNode } from 'react'
import { Tweet as ReactTweet, TweetComponents } from 'react-tweet'
import Image from 'next/image'
import { Caption } from './caption'
const components: TweetComponents = {
AvatarImg: (props) => <Image {...props} />,
MediaImg: (props) => <Image {...props} fill unoptimized />,
}
// we import this globally in the top-most layout.tsx file
// until Next.js lands suspense-y CSS support
......@@ -16,7 +23,7 @@ export async function Tweet({ id, caption }: TweetArgs) {
<div className="my-6">
<div className="flex justify-center">
{/* @ts-ignore */}
<NextTweet id={id} />
<ReactTweet id={id} components={components} />
</div>
{caption && <Caption>{caption}</Caption>}
</div>
......
......@@ -95,14 +95,14 @@ export async function sandbox(
async remove(filename) {
await next.deleteFile(filename)
},
async evaluate(snippet: () => any) {
if (typeof snippet === 'function') {
async evaluate(snippet: string | Function) {
if (typeof snippet === 'function' || typeof snippet === 'string') {
const result = await browser.eval(snippet)
await waitFor(30)
return result
} else {
throw new Error(
`You must pass a function to be evaluated in the browser.`
`You must pass a string or function to be evaluated in the browser.`
)
}
},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment