@@ -6,23 +6,23 @@ const { defaultPreset } = require('@vue/cli/lib/options')
6
6
const create = require ( '@vue/cli-test-utils/createTestProject' )
7
7
const serve = require ( '@vue/cli-test-utils/serveWithPuppeteer' )
8
8
9
- const sleep = n => new Promise ( resolve => setTimeout ( resolve , n ) )
10
-
11
9
test ( 'serve' , async ( ) => {
12
10
const project = await create ( 'e2e-serve' , defaultPreset )
13
11
14
12
await serve (
15
13
( ) => project . run ( 'vue-cli-service serve' ) ,
16
- async ( { nextUpdate, helpers } ) => {
14
+ async ( { page , nextUpdate, helpers } ) => {
17
15
const msg = `Welcome to Your Vue.js App`
18
16
expect ( await helpers . getText ( 'h1' ) ) . toMatch ( msg )
19
17
20
18
// test hot reload
21
19
const file = await project . read ( `src/App.vue` )
22
20
project . write ( `src/App.vue` , file . replace ( msg , `Updated` ) )
23
21
await nextUpdate ( ) // wait for child stdout update signal
24
- await sleep ( 5000 ) // give the client time to update
25
- expect ( await helpers . getText ( 'h1' ) ) . toMatch ( `Updated` )
22
+ await page . waitForFunction ( selector => {
23
+ const el = document . querySelector ( selector )
24
+ return el && el . textContent . includes ( 'Updated' )
25
+ } , { } , 'h1' )
26
26
}
27
27
)
28
28
} )
@@ -97,16 +97,18 @@ test('serve with inline entry', async () => {
97
97
98
98
await serve (
99
99
( ) => project . run ( 'vue-cli-service serve src/index.js' ) ,
100
- async ( { nextUpdate, helpers } ) => {
100
+ async ( { page , nextUpdate, helpers } ) => {
101
101
const msg = `Welcome to Your Vue.js App`
102
102
expect ( await helpers . getText ( 'h1' ) ) . toMatch ( msg )
103
103
104
104
// test hot reload
105
105
const file = await project . read ( `src/App.vue` )
106
106
project . write ( `src/App.vue` , file . replace ( msg , `Updated` ) )
107
107
await nextUpdate ( ) // wait for child stdout update signal
108
- await sleep ( 1000 ) // give the client time to update
109
- expect ( await helpers . getText ( 'h1' ) ) . toMatch ( `Updated` )
108
+ await page . waitForFunction ( selector => {
109
+ const el = document . querySelector ( selector )
110
+ return el && el . textContent . includes ( 'Updated' )
111
+ } , { } , 'h1' )
110
112
}
111
113
)
112
114
} )
@@ -118,16 +120,18 @@ test('serve with no public dir', async () => {
118
120
119
121
await serve (
120
122
( ) => project . run ( 'vue-cli-service serve' ) ,
121
- async ( { nextUpdate, helpers } ) => {
123
+ async ( { page , nextUpdate, helpers } ) => {
122
124
const msg = `Welcome to Your Vue.js App`
123
125
expect ( await helpers . getText ( 'h1' ) ) . toMatch ( msg )
124
126
125
127
// test hot reload
126
128
const file = await project . read ( `src/App.vue` )
127
129
project . write ( `src/App.vue` , file . replace ( msg , `Updated` ) )
128
130
await nextUpdate ( ) // wait for child stdout update signal
129
- await sleep ( 1000 ) // give the client time to update
130
- expect ( await helpers . getText ( 'h1' ) ) . toMatch ( `Updated` )
131
+ await page . waitForFunction ( selector => {
132
+ const el = document . querySelector ( selector )
133
+ return el && el . textContent . includes ( 'Updated' )
134
+ } , { } , 'h1' )
131
135
}
132
136
)
133
137
} )
0 commit comments