/
file-delete-restore.spec.ts
58 lines (49 loc) · 1.2 KB
/
file-delete-restore.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import {
editFile,
untilUpdated,
removeFile,
addFile,
isBuild
} from '../../testUtils'
test.runIf(isBuild)(
'should hmr when file is deleted and restored',
async () => {
await untilUpdated(() => page.textContent('p'), 'Child state 1')
editFile('Child.jsx', (code) =>
code.replace('Child state 1', 'Child state 2')
)
await untilUpdated(() => page.textContent('p'), 'Child state 2')
editFile('App.jsx', (code) =>
code
.replace(`import Child from './Child'`, '')
.replace(`<Child />`, '<p>Child deleted</p>')
)
removeFile('Child.jsx')
await untilUpdated(() => page.textContent('p'), 'Child deleted')
// restore Child.jsx
addFile(
'Child.jsx',
` export default function Child() {
return <p>Child state 1</p>
}
`
)
// restore App.jsx
editFile(
'App.jsx',
(code) =>
`import { useState } from 'react'
import Child from './Child'
function App() {
return (
<div className="App">
<Child />
</div>
)
}
export default App
`
)
await untilUpdated(() => page.textContent('p'), 'Child state 1')
}
)