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