import { promises as fsp } from 'node:fs' import { fileURLToPath } from 'node:url' import { describe, expect, it } from 'vitest' import { isWindows } from 'std-env' import { join } from 'pathe' // eslint-disable-next-line import/order import { setup, $fetch } from '@nuxt/test-utils' import { expectWithPolling, renderPage } from './utils' const isWebpack = process.env.TEST_BUILDER === 'webpack' // TODO: fix HMR on Windows if (process.env.TEST_ENV !== 'built' && !isWindows) { const fixturePath = fileURLToPath(new URL('./fixtures-temp/basic', import.meta.url)) await setup({ rootDir: fixturePath, dev: true, server: true, browser: true, setupTimeout: (isWindows ? 240 : 120) * 1000, nuxtConfig: { builder: isWebpack ? 'webpack' : 'vite', buildDir: process.env.NITRO_BUILD_DIR, nitro: { output: { dir: process.env.NITRO_OUTPUT_DIR } } } }) describe('hmr', () => { it('should work', async () => { const { page, pageErrors, consoleLogs } = await renderPage('/') expect(await page.title()).toBe('Basic fixture') expect((await page.$('.sugar-counter').then(r => r!.textContent()))!.trim()) .toEqual('Sugar Counter 12 x 2 = 24 Inc') // reactive await page.$('.sugar-counter button').then(r => r!.click()) expect((await page.$('.sugar-counter').then(r => r!.textContent()))!.trim()) .toEqual('Sugar Counter 13 x 2 = 26 Inc') // modify file let indexVue = await fsp.readFile(join(fixturePath, 'pages/index.vue'), 'utf8') indexVue = indexVue .replace('