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 { FileRef, nextTestSetup } from 'e2e-utils'
import { check, hasRedbox, waitFor, retry } from 'next-test-utils' import { sandbox } from 'development-sandbox'
import path from 'path' import path from 'path'
describe('Error overlay - RSC build errors', () => { describe('Error overlay - RSC build errors', () => {
...@@ -8,7 +8,7 @@ describe('Error overlay - RSC build errors', () => { ...@@ -8,7 +8,7 @@ describe('Error overlay - RSC build errors', () => {
dependencies: { dependencies: {
'@next/mdx': 'canary', '@next/mdx': 'canary',
'react-wrap-balancer': '^0.2.4', 'react-wrap-balancer': '^0.2.4',
'next-tweet': '^0.6.0', 'react-tweet': '^2.0.2',
'@mdx-js/react': '^2.3.0', '@mdx-js/react': '^2.3.0',
tailwindcss: '^3.2.6', tailwindcss: '^3.2.6',
typescript: 'latest', typescript: 'latest',
...@@ -20,44 +20,43 @@ describe('Error overlay - RSC build errors', () => { ...@@ -20,44 +20,43 @@ describe('Error overlay - RSC build errors', () => {
}) })
it('should handle successive HMR changes with errors correctly', async () => { it('should handle successive HMR changes with errors correctly', async () => {
const browser = await retry( const { session, cleanup } = await sandbox(
() => next.browser('/2020/develop-preview-test'), next,
1000, undefined,
500 '/2020/develop-preview-test'
) )
await check( expect(
() => browser.eval('document.documentElement.innerHTML'), await session.evaluate('document.documentElement.innerHTML')
/A few years ago I tweeted/ ).toContain('A few years ago I tweeted')
)
const pagePath = 'app/(post)/2020/develop-preview-test/page.mdx' const pagePath = 'app/(post)/2020/develop-preview-test/page.mdx'
const originalPage = await next.readFile(pagePath) const originalPage = await next.readFile(pagePath)
const break1 = originalPage.replace('break 1', '<Figure>') 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 />') 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++) { 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) await session.patch(pagePath, break2)
expect(await hasRedbox(browser, true)).toBe(true) expect(await session.hasRedbox(true)).toBe(true)
await next.patchFile(pagePath, break1) await session.patch(pagePath, break1)
await waitFor(100)
await next.patchFile(pagePath, originalPage) await session.patch(pagePath, originalPage)
expect(await hasRedbox(browser, false)).toBe(false) expect(await session.hasRedbox(false)).toBe(false)
} }
await check( expect(
() => browser.eval('document.documentElement.innerHTML'), await session.evaluate('document.documentElement.innerHTML')
/A few years ago I tweeted/ ).toContain('A few years ago I tweeted')
)
await cleanup()
}) })
}) })
import { NextTweet } from 'next-tweet'
import { Caption } from './caption'
import type { ReactNode } from 'react' 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 // we import this globally in the top-most layout.tsx file
// until Next.js lands suspense-y CSS support // until Next.js lands suspense-y CSS support
...@@ -16,7 +23,7 @@ export async function Tweet({ id, caption }: TweetArgs) { ...@@ -16,7 +23,7 @@ export async function Tweet({ id, caption }: TweetArgs) {
<div className="my-6"> <div className="my-6">
<div className="flex justify-center"> <div className="flex justify-center">
{/* @ts-ignore */} {/* @ts-ignore */}
<NextTweet id={id} /> <ReactTweet id={id} components={components} />
</div> </div>
{caption && <Caption>{caption}</Caption>} {caption && <Caption>{caption}</Caption>}
</div> </div>
......
...@@ -95,14 +95,14 @@ export async function sandbox( ...@@ -95,14 +95,14 @@ export async function sandbox(
async remove(filename) { async remove(filename) {
await next.deleteFile(filename) await next.deleteFile(filename)
}, },
async evaluate(snippet: () => any) { async evaluate(snippet: string | Function) {
if (typeof snippet === 'function') { if (typeof snippet === 'function' || typeof snippet === 'string') {
const result = await browser.eval(snippet) const result = await browser.eval(snippet)
await waitFor(30) await waitFor(30)
return result return result
} else { } else {
throw new Error( 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