|
4 | 4 | *--------------------------------------------------------------------------------------------*/ |
5 | 5 |
|
6 | 6 | import * as playwright from 'playwright'; |
7 | | -import { getDevElectronPath, Quality, ConsoleLogger, FileLogger, Logger, MultiLogger, getBuildElectronPath, getBuildVersion, measureAndLog } from '../../automation'; |
| 7 | +import { getDevElectronPath, Quality, ConsoleLogger, FileLogger, Logger, MultiLogger, getBuildElectronPath, getBuildVersion, measureAndLog, Application } from '../../automation'; |
8 | 8 | import * as path from 'path'; |
9 | 9 | import * as fs from 'fs'; |
10 | 10 | import * as os from 'os'; |
@@ -281,7 +281,6 @@ async function ensureStableCode(): Promise<void> { |
281 | 281 | } |
282 | 282 |
|
283 | 283 | async function setup(): Promise<void> { |
284 | | - logger.log('Test data path:', testDataPath); |
285 | 284 | logger.log('Preparing smoketest setup...'); |
286 | 285 |
|
287 | 286 | if (!opts.web && !opts.remote && opts.build) { |
@@ -329,3 +328,55 @@ export async function getApplication() { |
329 | 328 | }); |
330 | 329 | return application; |
331 | 330 | } |
| 331 | + |
| 332 | +export class ApplicationService { |
| 333 | + private _application: Application | undefined; |
| 334 | + private _closing: Promise<void> | undefined; |
| 335 | + private _listeners: ((app: Application | undefined) => void)[] = []; |
| 336 | + |
| 337 | + onApplicationChange(listener: (app: Application | undefined) => void): void { |
| 338 | + this._listeners.push(listener); |
| 339 | + } |
| 340 | + |
| 341 | + removeApplicationChangeListener(listener: (app: Application | undefined) => void): void { |
| 342 | + const index = this._listeners.indexOf(listener); |
| 343 | + if (index >= 0) { |
| 344 | + this._listeners.splice(index, 1); |
| 345 | + } |
| 346 | + } |
| 347 | + |
| 348 | + get application(): Application | undefined { |
| 349 | + return this._application; |
| 350 | + } |
| 351 | + |
| 352 | + async getOrCreateApplication(): Promise<Application> { |
| 353 | + if (this._closing) { |
| 354 | + await this._closing; |
| 355 | + } |
| 356 | + if (!this._application) { |
| 357 | + this._application = await getApplication(); |
| 358 | + this._application.code.driver.browserContext.on('close', () => { |
| 359 | + this._closing = (async () => { |
| 360 | + if (this._application) { |
| 361 | + this._application.code.driver.browserContext.removeAllListeners(); |
| 362 | + await this._application.stop(); |
| 363 | + this._application = undefined; |
| 364 | + this._runAllListeners(); |
| 365 | + } |
| 366 | + })(); |
| 367 | + }); |
| 368 | + this._runAllListeners(); |
| 369 | + } |
| 370 | + return this._application; |
| 371 | + } |
| 372 | + |
| 373 | + private _runAllListeners() { |
| 374 | + for (const listener of this._listeners) { |
| 375 | + try { |
| 376 | + listener(this._application); |
| 377 | + } catch (error) { |
| 378 | + console.error('Error occurred in application change listener:', error); |
| 379 | + } |
| 380 | + } |
| 381 | + } |
| 382 | +} |
0 commit comments