Skip to content

Commit

Permalink
Merge 14d48b0 into 76cf9c7
Browse files Browse the repository at this point in the history
  • Loading branch information
flops committed Nov 29, 2019
2 parents 76cf9c7 + 14d48b0 commit 785e390
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
8 changes: 5 additions & 3 deletions packages/api/src/test-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@ export class TestContext {
];

for (const customApplication of this.customApplications) {
requests.push(
customApplication.end()
);
if (!customApplication.isStopped()) {
requests.push(
customApplication.end()
);
}
}

return Promise.all(requests)
Expand Down
33 changes: 21 additions & 12 deletions packages/web-application/src/web-application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export class WebApplication extends PluggableModule {

private isLogOpened: boolean = false;

private isSessionStopped: boolean = false;

private mainTabID: number | null = null;

private isRegisteredInDevtool: boolean = false;
Expand Down Expand Up @@ -241,43 +243,44 @@ export class WebApplication extends PluggableModule {

// eslint-disable-next-line func-style
const method = async function decoratedMethod(...args) {
const logger = this.logger;
const message = logFn.apply(this, args);
const self = this;
const logger = self.logger;
const message = logFn.apply(self, args);
let result;

if (this.isLogOpened) {
if (self.isLogOpened) {
logger.debug(message);
result = originMethod.apply(this, args);
result = originMethod.apply(self, args);
} else {
await asyncBreakpoints.waitBeforeInstructionBreakpoint((state) => {
if (state) {
logger.debug('Debug: Stopped in breakpoint before instruction execution');
}
});
logger.startStep(message);
this.isLogOpened = true;
self.isLogOpened = true;

try {
result = originMethod.apply(this, args);
result = originMethod.apply(self, args);
if (result && result.catch && typeof result.catch === 'function') {
result = result.catch(async (err) => {
await this.asyncErrorHandler(err);
await self.asyncErrorHandler(err);
logger.endStep(message);
this.isLogOpened = false;
self.isLogOpened = false;
return Promise.reject(err);
}).then((result) => {
logger.endStep(message);
this.isLogOpened = false;
self.isLogOpened = false;
return result;
});
} else {
logger.endStep(message);
this.isLogOpened = false;
self.isLogOpened = false;
}
} catch (err) {
this.errorHandler(err);
self.errorHandler(err);
logger.endStep(message);
this.isLogOpened = false;
self.isLogOpened = false;

throw err;
}
Expand Down Expand Up @@ -1433,11 +1436,17 @@ export class WebApplication extends PluggableModule {
return this.client.uploadFile(fullPath);
}

public isStopped(): boolean {
return this.isSessionStopped;
}

public async end() {
if (this.config.devtool !== null && this.isRegisteredInDevtool) {
await this.unregisterAppInDevtool();
}

await this.client.end();
this.isSessionStopped = true;
}

public async getCssProperty(xpath, cssProperty: string, timeout: number = this.WAIT_TIMEOUT): Promise<any> {
Expand Down

0 comments on commit 785e390

Please sign in to comment.