@@ -37,56 +37,50 @@ describe('reload', () => {
37
37
} ) ;
38
38
39
39
describe ( 'on browser client' , ( ) => {
40
- it ( 'should hot reload without page refresh' , ( done ) => {
41
- runBrowser ( ) . then ( ( { page, browser } ) => {
42
- let refreshed = false ;
43
- page . waitForNavigation ( { waitUntil : 'load' } ) . then ( ( ) => {
44
- page
45
- . evaluate ( ( ) => {
46
- const body = document . body ;
47
- const bgColor = getComputedStyle ( body ) [ 'background-color' ] ;
48
- return bgColor ;
49
- } )
50
- . then ( ( color ) => {
51
- page . setRequestInterception ( true ) . then ( ( ) => {
52
- page . on ( 'request' , ( req ) => {
53
- if (
54
- req . isNavigationRequest ( ) &&
55
- req . frame ( ) === page . mainFrame ( ) &&
56
- req . url ( ) === `http://localhost:${ port } /main`
57
- ) {
58
- refreshed = true ;
59
- }
60
- req . continue ( ) ;
61
- } ) ;
62
- fs . writeFileSync (
63
- cssFilePath ,
64
- 'body { background-color: rgb(255, 0, 0); }'
65
- ) ;
66
- page . waitFor ( 10000 ) . then ( ( ) => {
67
- page
68
- . evaluate ( ( ) => {
69
- const body = document . body ;
70
- const bgColor = getComputedStyle ( body ) [
71
- 'background-color'
72
- ] ;
73
- return bgColor ;
74
- } )
75
- . then ( ( color2 ) => {
76
- browser . close ( ) . then ( ( ) => {
77
- expect ( color ) . toEqual ( 'rgb(0, 0, 255)' ) ;
78
- expect ( color2 ) . toEqual ( 'rgb(255, 0, 0)' ) ;
79
- expect ( refreshed ) . toBeFalsy ( ) ;
80
- done ( ) ;
81
- } ) ;
82
- } ) ;
83
- } ) ;
84
- } ) ;
85
- } ) ;
86
- } ) ;
87
-
88
- page . goto ( `http://localhost:${ port } /main` ) ;
40
+ it ( 'should hot reload without page refresh' , async ( ) => {
41
+ let refreshed = false ;
42
+ const { page, browser } = await runBrowser ( ) ;
43
+
44
+ page . goto ( `http://localhost:${ port } /main` ) ;
45
+
46
+ await page . waitForNavigation ( { waitUntil : 'load' } ) ;
47
+
48
+ const color = await page . evaluate ( ( ) => {
49
+ const body = document . body ;
50
+ const bgColor = getComputedStyle ( body ) [ 'background-color' ] ;
51
+ return bgColor ;
52
+ } ) ;
53
+
54
+ await page . setRequestInterception ( true ) ;
55
+
56
+ page . on ( 'request' , ( req ) => {
57
+ if (
58
+ req . isNavigationRequest ( ) &&
59
+ req . frame ( ) === page . mainFrame ( ) &&
60
+ req . url ( ) === `http://localhost:${ port } /main`
61
+ ) {
62
+ refreshed = true ;
63
+ }
64
+ req . continue ( ) ;
89
65
} ) ;
66
+ fs . writeFileSync (
67
+ cssFilePath ,
68
+ 'body { background-color: rgb(255, 0, 0); }'
69
+ ) ;
70
+
71
+ await page . waitFor ( 10000 ) ;
72
+
73
+ const color2 = await page . evaluate ( ( ) => {
74
+ const body = document . body ;
75
+ const bgColor = getComputedStyle ( body ) [ 'background-color' ] ;
76
+ return bgColor ;
77
+ } ) ;
78
+
79
+ await browser . close ( ) ;
80
+
81
+ expect ( color ) . toEqual ( 'rgb(0, 0, 255)' ) ;
82
+ expect ( color2 ) . toEqual ( 'rgb(255, 0, 0)' ) ;
83
+ expect ( refreshed ) . toBeFalsy ( ) ;
90
84
} ) ;
91
85
} ) ;
92
86
} ) ;
@@ -115,56 +109,50 @@ describe('reload', () => {
115
109
} ) ;
116
110
117
111
describe ( 'on browser client' , ( ) => {
118
- it ( 'should reload with page refresh' , ( done ) => {
119
- runBrowser ( ) . then ( ( { page, browser } ) => {
120
- let refreshed = false ;
121
- page . waitForNavigation ( { waitUntil : 'load' } ) . then ( ( ) => {
122
- page
123
- . evaluate ( ( ) => {
124
- const body = document . body ;
125
- const bgColor = getComputedStyle ( body ) [ 'background-color' ] ;
126
- return bgColor ;
127
- } )
128
- . then ( ( color ) => {
129
- page . setRequestInterception ( true ) . then ( ( ) => {
130
- page . on ( 'request' , ( req ) => {
131
- if (
132
- req . isNavigationRequest ( ) &&
133
- req . frame ( ) === page . mainFrame ( ) &&
134
- req . url ( ) === `http://localhost:${ port } /main`
135
- ) {
136
- refreshed = true ;
137
- }
138
- req . continue ( ) ;
139
- } ) ;
140
- fs . writeFileSync (
141
- cssFilePath ,
142
- 'body { background-color: rgb(255, 0, 0); }'
143
- ) ;
144
- page . waitFor ( 10000 ) . then ( ( ) => {
145
- page
146
- . evaluate ( ( ) => {
147
- const body = document . body ;
148
- const bgColor = getComputedStyle ( body ) [
149
- 'background-color'
150
- ] ;
151
- return bgColor ;
152
- } )
153
- . then ( ( color2 ) => {
154
- browser . close ( ) . then ( ( ) => {
155
- expect ( color ) . toEqual ( 'rgb(0, 0, 255)' ) ;
156
- expect ( color2 ) . toEqual ( 'rgb(255, 0, 0)' ) ;
157
- expect ( refreshed ) . toBeTruthy ( ) ;
158
- done ( ) ;
159
- } ) ;
160
- } ) ;
161
- } ) ;
162
- } ) ;
163
- } ) ;
164
- } ) ;
165
-
166
- page . goto ( `http://localhost:${ port } /main` ) ;
112
+ it ( 'should reload with page refresh' , async ( ) => {
113
+ let refreshed = false ;
114
+ const { page, browser } = await runBrowser ( ) ;
115
+
116
+ page . goto ( `http://localhost:${ port } /main` ) ;
117
+
118
+ await page . waitForNavigation ( { waitUntil : 'load' } ) ;
119
+
120
+ const color = await page . evaluate ( ( ) => {
121
+ const body = document . body ;
122
+ const bgColor = getComputedStyle ( body ) [ 'background-color' ] ;
123
+ return bgColor ;
124
+ } ) ;
125
+
126
+ await page . setRequestInterception ( true ) ;
127
+
128
+ page . on ( 'request' , ( req ) => {
129
+ if (
130
+ req . isNavigationRequest ( ) &&
131
+ req . frame ( ) === page . mainFrame ( ) &&
132
+ req . url ( ) === `http://localhost:${ port } /main`
133
+ ) {
134
+ refreshed = true ;
135
+ }
136
+ req . continue ( ) ;
167
137
} ) ;
138
+ fs . writeFileSync (
139
+ cssFilePath ,
140
+ 'body { background-color: rgb(255, 0, 0); }'
141
+ ) ;
142
+
143
+ await page . waitFor ( 10000 ) ;
144
+
145
+ const color2 = await page . evaluate ( ( ) => {
146
+ const body = document . body ;
147
+ const bgColor = getComputedStyle ( body ) [ 'background-color' ] ;
148
+ return bgColor ;
149
+ } ) ;
150
+
151
+ await browser . close ( ) ;
152
+
153
+ expect ( color ) . toEqual ( 'rgb(0, 0, 255)' ) ;
154
+ expect ( color2 ) . toEqual ( 'rgb(255, 0, 0)' ) ;
155
+ expect ( refreshed ) . toBeTruthy ( ) ;
168
156
} ) ;
169
157
} ) ;
170
158
} ) ;
0 commit comments