Skip to content

Commit

Permalink
Test run should pass when Page crashed execution error occures (see #13)
Browse files Browse the repository at this point in the history
  • Loading branch information
Filipoliko committed Apr 22, 2022
1 parent 28922a9 commit cf95402
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/tester/Runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default class Runner {
sendFailingScenario(results);
}

if (results && results.executionError) {
if (results && results.executionError && instance.unknownExecutionErrorOccured) {
this._isSuccess = false;
}

Expand Down
4 changes: 2 additions & 2 deletions src/tester/__tests__/RunnerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ describe('Runner', () => {
expect(messanger.report).toHaveBeenCalledWith('runner:end');
});

it('can start a test instance and handle run with execution errors', async () => {
let instance = { clear: jest.fn() };
it('can start a test instance and handle run with unknown execution errors', async () => {
let instance = { clear: jest.fn(), unknownExecutionErrorOccured: true };
messanger.requestScenario = jest
.fn()
.mockReturnValueOnce(Promise.resolve({ type: 'random', scenario: 'scenario' }))
Expand Down
31 changes: 31 additions & 0 deletions src/tester/browser/Browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import puppeteer from 'puppeteer';
import EventEmitter from 'events';
import { report } from '../messanger';

/**
* These errors will not cause test run to exit as failrue
*/
const KNOWN_FATAL_ERROR_MESSAGES = [
'Page crashed!', // See https://github.com/seznam/QApe/issues/13
];

/**
* Browser instance
*/
Expand All @@ -17,6 +24,8 @@ export default class Browser {
this._page = null;

this._pageErrorHandler = null;

this._unknownExecutionErrorOccured = false;
}

/**
Expand Down Expand Up @@ -45,6 +54,13 @@ export default class Browser {
return this._pageErrorHandler;
}

/**
* Test run with execution error will fail only when unknown execution error occured
*/
get unknownExecutionErrorOccured() {
return this._unknownExecutionErrorOccured;
}

/**
* Initializes browser instance
* @returns {Promise<Browser>}
Expand Down Expand Up @@ -110,10 +126,25 @@ export default class Browser {
'tester should recover by itself.';

report('browser:error', { error: msg });

this._handleUnknownExecutionErrors(error);

this.clear();
});
}

/**
* Sets unknown execution error indicator
* @param {Object} error
*/
_handleUnknownExecutionErrors(error) {
if (KNOWN_FATAL_ERROR_MESSAGES.some((message) => error.message.includes(message))) {
return;
}

this._unknownExecutionErrorOccured = true;
}

/**
* Initializes pageErrorHandler, exposes it to the
* page instance and loads config.pageErrorHandler
Expand Down
12 changes: 12 additions & 0 deletions src/tester/browser/__tests__/BrowserSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ describe('Browser', () => {
fn({ stack: 'error' });
}),
};
browser._handleUnknownExecutionErrors = jest.fn();
browser.clear = jest.fn();

browser._initFatalErrorHandler();
Expand All @@ -70,9 +71,20 @@ describe('Browser', () => {
expect(messanger.report).toHaveBeenCalledWith('browser:error', {
error: expect.any(String),
});
expect(browser._handleUnknownExecutionErrors).toHaveBeenCalled();
expect(browser.clear).toHaveBeenCalled();
});

it('can handle unknown execution error', () => {
browser._handleUnknownExecutionErrors({ message: 'Error: Page crashed!' });

expect(browser.unknownExecutionErrorOccured).toEqual(false);

browser._handleUnknownExecutionErrors({ message: 'Unknown error' });

expect(browser.unknownExecutionErrorOccured).toEqual(true);
});

it('can initialize page error handler', async () => {
let eventEmitter = {};
browser._getEventEmitter = jest.fn().mockReturnValue(eventEmitter);
Expand Down

0 comments on commit cf95402

Please sign in to comment.