From 18d41a90a48e9d181c76fada7f80458e9e4fc67c Mon Sep 17 00:00:00 2001 From: Shu Ding Date: Wed, 7 Dec 2022 00:22:46 +0100 Subject: [PATCH] Add tests for server component HMR (#43779) Something we haven't covered in our tests. NEX-35 ## Bug - [ ] Related issues linked using `fixes #number` - [x] Integration tests added - [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md) ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md) ## Documentation / Examples - [ ] Make sure the linting passes by running `pnpm build && pnpm lint` - [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md) --- test/e2e/app-dir/index.test.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/e2e/app-dir/index.test.ts b/test/e2e/app-dir/index.test.ts index 3bf7b92d542f8a7..7c59d26cb6a622d 100644 --- a/test/e2e/app-dir/index.test.ts +++ b/test/e2e/app-dir/index.test.ts @@ -378,6 +378,27 @@ describe('app dir', () => { } ) ;(isDev ? describe : describe.skip)('HMR', () => { + it('should HMR correctly for server component', async () => { + const filePath = 'app/dashboard/index/page.js' + const origContent = await next.readFile(filePath) + + try { + const browser = await webdriver(next.url, '/dashboard/index') + expect(await browser.elementByCss('p').text()).toContain( + 'hello from app/dashboard/index' + ) + + await next.patchFile( + filePath, + origContent.replace('hello from', 'swapped from') + ) + + await check(() => browser.elementByCss('p').text(), /swapped from/) + } finally { + await next.patchFile(filePath, origContent) + } + }) + it('should HMR correctly for client component', async () => { const filePath = 'app/client-component-route/page.js' const origContent = await next.readFile(filePath)