11import crypto from "node:crypto" ;
2- import P from "bluebird" ;
32import _ from "lodash" ;
43import { io } from "socket.io-client" ;
54import urljoin from "url-join" ;
65
6+ import { promiseTimeout } from "../../../../utils/promise" ;
77import NodejsEnvTestRunner from "../../../runner/test-runner" ;
88import { wrapExecutionThread } from "./execution-thread" ;
99import { WorkerEventNames } from "./types" ;
@@ -143,34 +143,33 @@ export class TestRunner extends NodejsEnvTestRunner {
143143 private _waitBroInitOnReconnect ( ) : Promise < void > {
144144 let intervalId : NodeJS . Timeout | null = null ;
145145
146- return new P ( ( resolve , reject ) => {
147- intervalId = setInterval ( ( ) => {
148- if ( _ . isNull ( this . _broInitResOnReconnect ) ) {
149- return ;
150- }
146+ return promiseTimeout (
147+ new Promise < void > ( ( resolve , reject ) => {
148+ intervalId = setInterval ( ( ) => {
149+ if ( _ . isNull ( this . _broInitResOnReconnect ) ) {
150+ return ;
151+ }
151152
152- if ( intervalId ) {
153- clearInterval ( intervalId ) ;
154- }
153+ if ( intervalId ) {
154+ clearInterval ( intervalId ) ;
155+ }
155156
156- if ( _ . isEmpty ( this . _broInitResOnReconnect ) ) {
157- resolve ( ) ;
158- } else {
159- reject ( this . _broInitResOnReconnect [ 0 ] ) ;
160- }
161- } , BRO_INIT_INTERVAL_ON_RECONNECT ) . unref ( ) ;
162- } )
163- . timeout (
164- BRO_INIT_TIMEOUT_ON_RECONNECT ,
165- `Browser didn't connect to the Vite server after reconnect in ${ BRO_INIT_TIMEOUT_ON_RECONNECT } ms` ,
166- )
167- . catch ( err => {
168- if ( intervalId ) {
169- clearInterval ( intervalId ) ;
170- }
157+ if ( _ . isEmpty ( this . _broInitResOnReconnect ) ) {
158+ resolve ( ) ;
159+ } else {
160+ reject ( this . _broInitResOnReconnect [ 0 ] ) ;
161+ }
162+ } , BRO_INIT_INTERVAL_ON_RECONNECT ) . unref ( ) ;
163+ } ) ,
164+ BRO_INIT_TIMEOUT_ON_RECONNECT ,
165+ `Browser didn't connect to the Vite server after reconnect in ${ BRO_INIT_TIMEOUT_ON_RECONNECT } ms` ,
166+ ) . catch ( err => {
167+ if ( intervalId ) {
168+ clearInterval ( intervalId ) ;
169+ }
171170
172- throw err ;
173- } ) ;
171+ throw err ;
172+ } ) ;
174173 }
175174
176175 _getPreparePageActions ( browser : Browser , history : BrowserHistory ) : ( ( ) => Promise < void > ) [ ] {
@@ -298,7 +297,7 @@ export class TestRunner extends NodejsEnvTestRunner {
298297 }
299298
300299 private async _openViteUrl ( browser : Browser ) : Promise < void > {
301- const browserInitialize = new P ( ( resolve , reject ) => {
300+ const browserInitialize = new Promise < void > ( ( resolve , reject ) => {
302301 this . _socket . once ( BrowserEventNames . initialize , errors => {
303302 _ . isEmpty ( errors ) ? resolve ( ) : reject ( errors [ 0 ] ) ;
304303 } ) ;
@@ -308,7 +307,7 @@ export class TestRunner extends NodejsEnvTestRunner {
308307 const uri = urljoin ( this . _config . baseUrl , VITE_RUN_UUID_ROUTE , this . _runUuid ) ;
309308
310309 await Promise . all ( [
311- browserInitialize . timeout ( timeout , `Browser didn't connect to the Vite server in ${ timeout } ms` ) ,
310+ promiseTimeout ( browserInitialize , timeout , `Browser didn't connect to the Vite server in ${ timeout } ms` ) ,
312311 browser . publicAPI . url ( uri ) ,
313312 ] ) ;
314313 }
0 commit comments