diff --git a/test/development/app-dir/server-components-hmr-cache/server-components-hmr-cache.test.ts b/test/development/app-dir/server-components-hmr-cache/server-components-hmr-cache.test.ts index 9bc62f47a9251..75237cdfd1839 100644 --- a/test/development/app-dir/server-components-hmr-cache/server-components-hmr-cache.test.ts +++ b/test/development/app-dir/server-components-hmr-cache/server-components-hmr-cache.test.ts @@ -18,27 +18,23 @@ describe('server-components-hmr-cache', () => { } describe.each(['edge', 'node'])('%s runtime', (runtime) => { - afterEach(async () => { - await next.patchFile('components/shared-page.tsx', (content) => - content.replace('bar', 'foo') - ) - }) - it('should use cached fetch calls for fast refresh requests', async () => { const browser = await next.browser(`/${runtime}`) const valueBeforePatch = await browser.elementById('value').text() - await next.patchFile('components/shared-page.tsx', (content) => - content.replace('foo', 'bar') - ) - - await retry(async () => { - const updatedContent = await browser.elementById('content').text() - expect(updatedContent).toBe('bar') - }) + await next.patchFile( + 'components/shared-page.tsx', + (content) => content.replace('foo', 'bar'), + async () => { + await retry(async () => { + const updatedContent = await browser.elementById('content').text() + expect(updatedContent).toBe('bar') + }, 5000) - const valueAfterPatch = await browser.elementById('value').text() - expect(valueBeforePatch).toEqual(valueAfterPatch) + const valueAfterPatch = await browser.elementById('value').text() + expect(valueBeforePatch).toEqual(valueAfterPatch) + } + ) }) it('should not use cached fetch calls for intentional refresh requests', async () => { @@ -49,7 +45,7 @@ describe('server-components-hmr-cache', () => { await retry(async () => { const valueAfterRefresh = await browser.elementById('value').text() expect(valueBeforeRefresh).not.toEqual(valueAfterRefresh) - }) + }, 5000) }) describe('in after()', () => { @@ -62,17 +58,19 @@ describe('server-components-hmr-cache', () => { const valueBeforePatch = getLoggedAfterValue() cliOutputLength = next.cliOutput.length - await next.patchFile('components/shared-page.tsx', (content) => - content.replace('foo', 'bar') + await next.patchFile( + 'components/shared-page.tsx', + (content) => content.replace('foo', 'bar'), + async () => { + await retry(async () => { + const updatedContent = await browser.elementById('content').text() + expect(updatedContent).toBe('bar') + }, 5000) + + const valueAfterPatch = getLoggedAfterValue() + expect(valueBeforePatch).toEqual(valueAfterPatch) + } ) - - await retry(async () => { - const updatedContent = await browser.elementById('content').text() - expect(updatedContent).toBe('bar') - }) - - const valueAfterPatch = getLoggedAfterValue() - expect(valueBeforePatch).toEqual(valueAfterPatch) }) it('should not use cached fetch calls for intentional refresh requests', async () => { @@ -85,7 +83,7 @@ describe('server-components-hmr-cache', () => { await retry(async () => { const valueAfterRefresh = getLoggedAfterValue() expect(valueBeforeRefresh).not.toEqual(valueAfterRefresh) - }) + }, 5000) }) }) @@ -112,17 +110,19 @@ describe('server-components-hmr-cache', () => { const browser = await next.browser(`/${runtime}`) const valueBeforePatch = await browser.elementById('value').text() - await next.patchFile('components/shared-page.tsx', (content) => - content.replace('foo', 'bar') + await next.patchFile( + 'components/shared-page.tsx', + (content) => content.replace('foo', 'bar'), + async () => { + await retry(async () => { + const updatedContent = await browser.elementById('content').text() + expect(updatedContent).toBe('bar') + }, 5000) + + const valueAfterPatch = await browser.elementById('value').text() + expect(valueBeforePatch).not.toEqual(valueAfterPatch) + } ) - - await retry(async () => { - const updatedContent = await browser.elementById('content').text() - expect(updatedContent).toBe('bar') - }) - - const valueAfterPatch = await browser.elementById('value').text() - expect(valueBeforePatch).not.toEqual(valueAfterPatch) }) describe('in after()', () => { @@ -135,17 +135,21 @@ describe('server-components-hmr-cache', () => { const valueBeforePatch = await retry(() => getLoggedAfterValue()) cliOutputLength = next.cliOutput.length - await next.patchFile('components/shared-page.tsx', (content) => - content.replace('foo', 'bar') + await next.patchFile( + 'components/shared-page.tsx', + (content) => content.replace('foo', 'bar'), + async () => { + await retry(async () => { + const updatedContent = await browser + .elementById('content') + .text() + expect(updatedContent).toBe('bar') + }, 5000) + + const valueAfterPatch = await retry(() => getLoggedAfterValue()) + expect(valueBeforePatch).not.toEqual(valueAfterPatch) + } ) - - await retry(async () => { - const updatedContent = await browser.elementById('content').text() - expect(updatedContent).toBe('bar') - }) - - const valueAfterPatch = await retry(() => getLoggedAfterValue()) - expect(valueBeforePatch).not.toEqual(valueAfterPatch) }) }) })