@@ -71,7 +71,10 @@ export class ElectronApplication extends EventEmitter {
71
71
super ( ) ;
72
72
this . _apiLogger = logger . api ;
73
73
this . _browserContext = browser . _defaultContext as CRBrowserContext ;
74
- this . _browserContext . on ( Events . BrowserContext . Close , ( ) => this . emit ( ElectronEvents . ElectronApplication . Close ) ) ;
74
+ this . _browserContext . on ( Events . BrowserContext . Close , ( ) => {
75
+ // Emit application closed after context closed.
76
+ Promise . resolve ( ) . then ( ( ) => this . emit ( ElectronEvents . ElectronApplication . Close ) ) ;
77
+ } ) ;
75
78
this . _browserContext . on ( Events . BrowserContext . Page , event => this . _onPage ( event ) ) ;
76
79
this . _nodeConnection = nodeConnection ;
77
80
this . _nodeSession = nodeConnection . rootSession ;
@@ -125,8 +128,10 @@ export class ElectronApplication extends EventEmitter {
125
128
}
126
129
127
130
async close ( ) {
131
+ const closed = this . waitForEvent ( ElectronEvents . ElectronApplication . Close ) ;
128
132
await this . evaluate ( ( { app } ) => app . quit ( ) ) ;
129
133
this . _nodeConnection . close ( ) ;
134
+ await closed ;
130
135
}
131
136
132
137
async waitForEvent ( event : string , optionsOrPredicate : types . WaitForEventOptions = { } ) : Promise < any > {
@@ -188,10 +193,7 @@ export class Electron {
188
193
cwd : options . cwd ,
189
194
tempDirectories : [ ] ,
190
195
attemptToGracefullyClose : ( ) => app ! . close ( ) ,
191
- onExit : ( exitCode , signal ) => {
192
- if ( app )
193
- app . emit ( ElectronEvents . ElectronApplication . Close , exitCode , signal ) ;
194
- } ,
196
+ onExit : ( exitCode , signal ) => { } ,
195
197
} ) ;
196
198
197
199
const nodeMatch = await waitForLine ( progress , launchedProcess , launchedProcess . stderr , / ^ D e b u g g e r l i s t e n i n g o n ( w s : \/ \/ .* ) $ / ) ;
0 commit comments