Skip to content

Commit

Permalink
test: fix hmr-ssr
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Dec 18, 2024
1 parent 95f47eb commit 2245aaa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
17 changes: 10 additions & 7 deletions playground/hmr-ssr/__tests__/hmr-ssr.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -844,20 +844,23 @@ if (!isBuild) {
await untilUpdated(() => hmr('.optional-chaining')?.toString(), '2')
})

test.skip('hmr works for self-accepted module within circular imported files', async () => {
test('hmr works for self-accepted module within circular imported files', async () => {
await setupModuleRunner('/self-accept-within-circular/index')
const el = () => hmr('.self-accept-within-circular')
expect(el()).toBe('c')
editFile('self-accept-within-circular/c.js', (code) =>
code.replace(`export const c = 'c'`, `export const c = 'cc'`),
)
// it throws a same error as browser case,
// but it doesn't auto reload and it calls `hot.accept` called with `undefined`
await untilUpdated(() => el(), '')

// test reloading manually for now
// TODO: why clearCache not working?
// runner.clearCache();
// runner.import('/self-accept-within-circular/index')
await setupModuleRunner('/self-accept-within-circular/index')
await untilUpdated(() => el(), 'cc')
await vi.waitFor(() => {
expect(serverLogs.length).greaterThanOrEqual(1)
// Should still keep hmr update, but it'll error on the browser-side and will refresh itself.
// Match on full log not possible because of color markers
expect(serverLogs.at(-1)!).toContain('hmr update')
})
})

test('hmr should not reload if no accepted within circular imported files', async (ctx) => {
Expand Down
2 changes: 1 addition & 1 deletion playground/hmr-ssr/self-accept-within-circular/c.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ function render(content) {
render(c)

import.meta.hot?.accept((nextExports) => {
render(nextExports.c)
render(nextExports?.c)
})

0 comments on commit 2245aaa

Please sign in to comment.