@@ -6,16 +6,16 @@ test('should render', async () => {
6
6
} )
7
7
8
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' )
9
+ expect ( await page . textContent ( '#state- button' ) ) . toMatch ( 'count is: 0' )
10
+ await page . click ( '#state- button' )
11
+ expect ( await page . textContent ( '#state- button' ) ) . toMatch ( 'count is: 1' )
12
12
} )
13
13
14
14
test ( 'should hmr' , async ( ) => {
15
15
editFile ( 'App.jsx' , ( code ) => code . replace ( 'Vite + React' , 'Updated' ) )
16
16
await untilUpdated ( ( ) => page . textContent ( 'h1' ) , 'Hello Updated' )
17
17
// preserve state
18
- expect ( await page . textContent ( 'button' ) ) . toMatch ( 'count is: 1' )
18
+ expect ( await page . textContent ( '#state- button' ) ) . toMatch ( 'count is: 1' )
19
19
} )
20
20
21
21
// #9869
@@ -37,7 +37,7 @@ test.runIf(isServe)(
37
37
'should have annotated jsx with file location metadata' ,
38
38
async ( ) => {
39
39
const meta = await page . evaluate ( ( ) => {
40
- const button = document . querySelector ( 'button' )
40
+ const button = document . querySelector ( '#state- button' )
41
41
const key = Object . keys ( button ) . find (
42
42
( key ) => key . indexOf ( '__reactFiber' ) === 0
43
43
)
@@ -52,3 +52,28 @@ test.runIf(isServe)(
52
52
] )
53
53
}
54
54
)
55
+
56
+ test ( 'should hmr react context' , async ( ) => {
57
+ browserLogs . length = 0
58
+ expect ( await page . textContent ( '#context-button' ) ) . toMatch (
59
+ 'context-based count is: 0'
60
+ )
61
+ await page . click ( '#context-button' )
62
+ expect ( await page . textContent ( '#context-button' ) ) . toMatch (
63
+ 'context-based count is: 1'
64
+ )
65
+ editFile ( 'context/CountProvider.jsx' , ( code ) =>
66
+ code . replace ( 'context provider' , 'context provider updated' )
67
+ )
68
+ await untilUpdated (
69
+ ( ) => page . textContent ( '#context-provider' ) ,
70
+ 'context provider updated'
71
+ )
72
+ expect ( browserLogs ) . toMatchObject ( [
73
+ '[vite] hot updated: /context/CountProvider.jsx' ,
74
+ '[vite] hot updated: /App.jsx' ,
75
+ '[vite] hot updated: /context/ContextButton.jsx' ,
76
+ 'Parent rendered'
77
+ ] )
78
+ browserLogs . length = 0
79
+ } )
0 commit comments