|
| 1 | +import { expect, test } from 'vitest' |
| 2 | +import { editFile, isServe, page, untilUpdated } from '~utils' |
| 3 | + |
| 4 | +test('should render', async () => { |
| 5 | + expect(await page.textContent('h1')).toMatch('Hello Vite + React') |
| 6 | +}) |
| 7 | + |
| 8 | +test('should update', async () => { |
| 9 | + expect(await page.textContent('button')).toMatch('count is: 0') |
| 10 | + await page.click('button') |
| 11 | + expect(await page.textContent('button')).toMatch('count is: 1') |
| 12 | +}) |
| 13 | + |
| 14 | +test.runIf(isServe)('should hmr', async () => { |
| 15 | + editFile('App.jsx', (code) => code.replace('Vite + React', 'Updated')) |
| 16 | + await untilUpdated(() => page.textContent('h1'), 'Hello Updated') |
| 17 | + // preserve state |
| 18 | + expect(await page.textContent('button')).toMatch('count is: 1') |
| 19 | +}) |
| 20 | + |
| 21 | +test.runIf(isServe)( |
| 22 | + 'should have annotated jsx with file location metadata', |
| 23 | + async () => { |
| 24 | + const meta = await page.evaluate(() => { |
| 25 | + const button = document.querySelector('button') |
| 26 | + const key = Object.keys(button).find( |
| 27 | + (key) => key.indexOf('__reactFiber') === 0, |
| 28 | + ) |
| 29 | + return button[key]._debugSource |
| 30 | + }) |
| 31 | + // If the evaluate call doesn't crash, and the returned metadata has |
| 32 | + // the expected fields, we're good. |
| 33 | + expect(Object.keys(meta).sort()).toEqual([ |
| 34 | + 'columnNumber', |
| 35 | + 'fileName', |
| 36 | + 'lineNumber', |
| 37 | + ]) |
| 38 | + }, |
| 39 | +) |
0 commit comments