@@ -6,23 +6,23 @@ const { defaultPreset } = require('@vue/cli/lib/options')
66const create = require ( '@vue/cli-test-utils/createTestProject' )
77const serve = require ( '@vue/cli-test-utils/serveWithPuppeteer' )
88
9- const sleep = n => new Promise ( resolve => setTimeout ( resolve , n ) )
10-
119test ( 'serve' , async ( ) => {
1210 const project = await create ( 'e2e-serve' , defaultPreset )
1311
1412 await serve (
1513 ( ) => project . run ( 'vue-cli-service serve' ) ,
16- async ( { nextUpdate, helpers } ) => {
14+ async ( { page , nextUpdate, helpers } ) => {
1715 const msg = `Welcome to Your Vue.js App`
1816 expect ( await helpers . getText ( 'h1' ) ) . toMatch ( msg )
1917
2018 // test hot reload
2119 const file = await project . read ( `src/App.vue` )
2220 project . write ( `src/App.vue` , file . replace ( msg , `Updated` ) )
2321 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' )
2626 }
2727 )
2828} )
@@ -97,16 +97,18 @@ test('serve with inline entry', async () => {
9797
9898 await serve (
9999 ( ) => project . run ( 'vue-cli-service serve src/index.js' ) ,
100- async ( { nextUpdate, helpers } ) => {
100+ async ( { page , nextUpdate, helpers } ) => {
101101 const msg = `Welcome to Your Vue.js App`
102102 expect ( await helpers . getText ( 'h1' ) ) . toMatch ( msg )
103103
104104 // test hot reload
105105 const file = await project . read ( `src/App.vue` )
106106 project . write ( `src/App.vue` , file . replace ( msg , `Updated` ) )
107107 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' )
110112 }
111113 )
112114} )
@@ -118,16 +120,18 @@ test('serve with no public dir', async () => {
118120
119121 await serve (
120122 ( ) => project . run ( 'vue-cli-service serve' ) ,
121- async ( { nextUpdate, helpers } ) => {
123+ async ( { page , nextUpdate, helpers } ) => {
122124 const msg = `Welcome to Your Vue.js App`
123125 expect ( await helpers . getText ( 'h1' ) ) . toMatch ( msg )
124126
125127 // test hot reload
126128 const file = await project . read ( `src/App.vue` )
127129 project . write ( `src/App.vue` , file . replace ( msg , `Updated` ) )
128130 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' )
131135 }
132136 )
133137} )
0 commit comments