|
| 1 | +import { expect, test } from 'vitest' |
| 2 | +import { editFile, isServe, page } from '~utils' |
| 3 | + |
| 4 | +test('should render', async () => { |
| 5 | + // In bundled dev mode, the page initially shows a "Bundling in progress" |
| 6 | + // placeholder and reloads once the bundle is ready. |
| 7 | + await expect.poll(() => page.textContent('h1')).toMatch('Hello Vite + React') |
| 8 | +}) |
| 9 | + |
| 10 | +test('should update', async () => { |
| 11 | + expect(await page.textContent('#state-button')).toMatch('count is: 0') |
| 12 | + await page.click('#state-button') |
| 13 | + expect(await page.textContent('#state-button')).toMatch('count is: 1') |
| 14 | +}) |
| 15 | + |
| 16 | +test.runIf(isServe)('should hmr', async () => { |
| 17 | + editFile('src/App.tsx', (code) => |
| 18 | + code.replace('Vite + React', 'Vite + React Updated'), |
| 19 | + ) |
| 20 | + await expect |
| 21 | + .poll(() => page.textContent('h1')) |
| 22 | + .toMatch('Hello Vite + React Updated') |
| 23 | + // preserve state |
| 24 | + expect(await page.textContent('#state-button')).toMatch('count is: 1') |
| 25 | + |
| 26 | + editFile('src/App.tsx', (code) => |
| 27 | + code.replace('Vite + React Updated', 'Vite + React'), |
| 28 | + ) |
| 29 | + await expect.poll(() => page.textContent('h1')).toMatch('Hello Vite + React') |
| 30 | +}) |
0 commit comments