mirror of
https://github.com/hanzoai/vite.git
synced 2026-10-30 19:36:16 +00:00
40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
import { editFile, untilUpdated, isBuild } from '../../testUtils'
|
|
|
|
test('should render', async () => {
|
|
expect(await page.textContent('h1')).toMatch('Hello Vite + React')
|
|
})
|
|
|
|
test('should update', async () => {
|
|
expect(await page.textContent('button')).toMatch('count is: 0')
|
|
await page.click('button')
|
|
expect(await page.textContent('button')).toMatch('count is: 1')
|
|
})
|
|
|
|
test('should hmr', async () => {
|
|
editFile('App.jsx', (code) => code.replace('Vite + React', 'Updated'))
|
|
await untilUpdated(() => page.textContent('h1'), 'Hello Updated')
|
|
// preserve state
|
|
expect(await page.textContent('button')).toMatch('count is: 1')
|
|
})
|
|
|
|
test('should have annotated jsx with file location metadata', async () => {
|
|
// we're not annotating in prod,
|
|
// so we skip this test when isBuild is true
|
|
if (isBuild) return
|
|
|
|
const meta = await page.evaluate(() => {
|
|
const button = document.querySelector('button')
|
|
const key = Object.keys(button).find(
|
|
(key) => key.indexOf('__reactFiber') === 0
|
|
)
|
|
return button[key]._debugSource
|
|
})
|
|
// If the evaluate call doesn't crash, and the returned metadata has
|
|
// the expected fields, we're good.
|
|
expect(Object.keys(meta).sort()).toEqual([
|
|
'columnNumber',
|
|
'fileName',
|
|
'lineNumber'
|
|
])
|
|
})
|