Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

playground/vue/__tests__/vue.spec.ts > hmr > should reload when relies file changed test is flaky #485

Closed
sapphi-red opened this issue Dec 12, 2024 · 2 comments · Fixed by #486

Comments

@sapphi-red
Copy link
Member

sapphi-red commented Dec 12, 2024

This test has been failing many times.

test('should reload when relies file changed', async () => {
// rerender
editFile('Hmr.vue', (code) => code.replace('HMR', 'HMR updated'))
await untilUpdated(() => page.textContent('h2.hmr'), 'HMR updated')
await untilUpdated(() => page.textContent('.hmr-number'), '100')
// reload
editFile('lib.js', (code) => code.replace('100', '200'))
await untilUpdated(() => page.textContent('.hmr-number'), '200')
})

@edison1105
Copy link
Member

It was previously only unstable on windows, and running it again sometimes passed. I've tried to investigate, but there's no error on local. 😓

@sapphi-red
Copy link
Member Author

I got the following output with this patch when the test failed.

patch
diff --git a/packages/plugin-vue/src/main.ts b/packages/plugin-vue/src/main.ts
index eddcfff..b511c72 100644
--- a/packages/plugin-vue/src/main.ts
+++ b/packages/plugin-vue/src/main.ts
@@ -150,6 +150,7 @@ export async function transformMain(
     )
     output.push(
       `import.meta.hot.on('file-changed', ({ file }) => {`,
+      normalizePath(filename).endsWith('Hmr.vue') ? `  console.log('file-changed', file)` : '',
       `  __VUE_HMR_RUNTIME__.CHANGED_FILE = file`,
       `})`,
     )
diff --git a/playground/vue/__tests__/vue.spec.ts b/playground/vue/__tests__/vue.spec.ts
index 988efa7..0a5e872 100644
--- a/playground/vue/__tests__/vue.spec.ts
+++ b/playground/vue/__tests__/vue.spec.ts
@@ -207,14 +207,20 @@ describe('hmr', () => {
   })
 
   test('should reload when relies file changed', async () => {
-    // rerender
-    editFile('Hmr.vue', (code) => code.replace('HMR', 'HMR updated'))
-    await untilUpdated(() => page.textContent('h2.hmr'), 'HMR updated')
-    await untilUpdated(() => page.textContent('.hmr-number'), '100')
-
-    // reload
-    editFile('lib.js', (code) => code.replace('100', '200'))
-    await untilUpdated(() => page.textContent('.hmr-number'), '200')
+    browserLogs.length = 0
+    try {
+      // rerender
+      editFile('Hmr.vue', (code) => code.replace('HMR', 'HMR updated'))
+      await untilUpdated(() => page.textContent('h2.hmr'), 'HMR updated')
+      await untilUpdated(() => page.textContent('.hmr-number'), '100')
+
+      // reload
+      editFile('lib.js', (code) => code.replace('100', '200'))
+      await untilUpdated(() => page.textContent('.hmr-number'), '200')
+    } catch (e) {
+      console.log('browserLogs', browserLogs)
+      throw e
+    }
   })
 
   test('global hmr for some scenarios', async () => {
browserLogs [
  'file-changed D:/documents/GitHub/vite-plugin-vue/playground-temp/vue/lib.js',
  'file-changed D:/documents/GitHub/vite-plugin-vue/playground-temp/vue/lib.js',
  'file-changed D:/documents/GitHub/vite-plugin-vue/playground-temp/vue/Hmr.vue',
  'file-changed D:/documents/GitHub/vite-plugin-vue/playground-temp/vue/Hmr.vue',
  '[vite] hot updated: /Hmr.vue',
  '[vite] hot updated: /Hmr.vue'
]

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants