Skip to content

Commit

Permalink
disabled restart browser in devmode (#8017)
Browse files Browse the repository at this point in the history
If development mode turned on, the heartbeat continues to work and
_waitHeartBeat doesn't assign promises responsible for reloading.
HeartBeat responsible for fast stopping application when pressed ctr + c
  • Loading branch information
PavelMor25 authored Sep 22, 2023
1 parent 455291f commit 8e08c91
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/browser/connection/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,9 @@ export default class BrowserConnection extends EventEmitter {
}

private _waitForHeartbeat (): void {
if (this._options.developmentMode)
return;

this.heartbeatTimeout = setTimeout(() => {
const err = this._createBrowserDisconnectedError();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ const reporter = createReporter({
},
});

function createConnection (browser) {
function createConnection (browser, devMode) {
return browserProviderPool
.getBrowserInfo(browser)
.then(browserInfo => {
const options = {
disableMultipleWindows: false,
nativeAutomation: config.nativeAutomation,
developmentMode: config.devMode,
developmentMode: devMode,
};

const connnection = new BrowserConnection(testCafe.browserConnectionGateway, browserInfo, false, options);
Expand Down Expand Up @@ -55,11 +55,11 @@ const initializeConnectionHangOnRestart = connection => {
};
};

function run (pathToTest, filter, initializeConnection = initializeConnectionLowHeartbeatTimeout) {
function run (pathToTest, filter, devMode = config.devMode, initializeConnection = initializeConnectionLowHeartbeatTimeout) {
const src = path.join(__dirname, pathToTest);
const browserNames = config.currentEnvironment.browsers.map(browser => browser.browserName || browser.alias);

return Promise.all(browserNames.map(browser => createConnection(browser)))
return Promise.all(browserNames.map(browser => createConnection(browser, devMode)))
.then(connections => {
connections.forEach(connection => initializeConnection(connection));

Expand Down Expand Up @@ -150,7 +150,14 @@ if (config.useLocalBrowsers) {
});

it('Should restart browser on timeout if the `closeBrowser` method hangs', function () {
return run('./testcafe-fixtures/index-test.js', 'Should restart browser on timeout if the `closeBrowser` method hangs', initializeConnectionHangOnRestart)
return run('./testcafe-fixtures/index-test.js', 'Should restart browser on timeout if the `closeBrowser` method hangs', config.devMode, initializeConnectionHangOnRestart)
.then(() => {
expect(errors.length).eql(0);
});
});

it('Shouldn\'t restart browser when it does not respond and developmentMode on', function () {
return run('./testcafe-fixtures/index-test.js', 'Shouldn\'t restart browser when it does not respond and developmentMode on', true)
.then(() => {
expect(errors.length).eql(0);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,15 @@ test('Should log error on browser disconnect', async t => {
t.testRun.browserConnection.emit('error', new Error('force error'));
}, 5000);
});

test('Shouldn\'t restart browser when it does not respond and developmentMode on', async t => {
const userAgent = await getUserAgent();

counter[userAgent] = counter[userAgent] || 0;

counter[userAgent]++;

await hang();

await t.expect(counter[userAgent]).eql(1);
});

0 comments on commit 8e08c91

Please sign in to comment.