@@ -17,9 +17,10 @@ export class TestContext
1717 this . tracks = tracks ;
1818 this . outputConfigs = outputConfigs ;
1919 this . options = null ;
20+ this . wantRestart = false ;
2021 }
2122
22- async beginSuite ( options = { } )
23+ initOptions ( options )
2324 {
2425 const pluginSettings = Object . assign ( { } , this . config . pluginSettings , options . pluginSettings ) ;
2526
@@ -33,22 +34,29 @@ export class TestContext
3334 } ,
3435 options . resetOptions ) ;
3536
36- const axiosConfig = options . axiosConfig || null ;
37- const environment = options . environment || null ;
37+ const { axiosConfig, environment } = options ;
3838
39- this . options = options = {
39+ this . options = {
4040 pluginSettings,
4141 resetOptions,
4242 axiosConfig,
4343 environment
4444 } ;
45+ }
4546
46- await this . player . start ( options ) ;
47+ initClient ( )
48+ {
49+ this . client . handler . init ( this . options . axiosConfig ) ;
50+ }
4751
48- this . client . handler . init ( axiosConfig ) ;
52+ async startPlayer ( )
53+ {
54+ await this . player . start ( this . options ) ;
4955
5056 if ( await this . client . waitUntilReady ( ) )
57+ {
5158 return ;
59+ }
5260
5361 const logData = await this . player . getLog ( ) ;
5462
@@ -57,17 +65,50 @@ export class TestContext
5765
5866 throw Error ( 'Failed to reach API endpoint' ) ;
5967 }
68+
69+ async stopPlayer ( )
70+ {
71+ await this . player . stop ( ) ;
72+ }
73+
74+ async beginSuite ( options = { } , reuseOptions = false )
75+ {
76+ this . wantRestart = false ;
77+ this . initOptions ( options ) ;
78+ this . initClient ( ) ;
79+ await this . startPlayer ( ) ;
80+ }
6081
6182 async endSuite ( )
6283 {
6384 this . options = null ;
64- await this . player . stop ( ) ;
85+ await this . stopPlayer ( ) ;
6586 }
6687
6788 async beginTest ( )
6889 {
69- this . client . handler . init ( this . options . axiosConfig ) ;
70- await this . client . resetState ( this . options . resetOptions ) ;
90+ if ( this . wantRestart )
91+ {
92+ await this . stopPlayer ( ) ;
93+ this . initClient ( ) ;
94+ await this . startPlayer ( ) ;
95+ this . wantRestart = false ;
96+ }
97+ else
98+ {
99+ this . initClient ( ) ;
100+ }
101+
102+ try
103+ {
104+ await this . client . resetState ( this . options . resetOptions ) ;
105+ }
106+ catch ( err )
107+ {
108+ console . log ( 'failed to reset player state, next test will restart player' ) ;
109+ this . wantRestart = true ;
110+ throw err ;
111+ }
71112 }
72113
73114 endTest ( )
0 commit comments