Skip to content

Commit

Permalink
Adding support for IGNORE_TIMEOUT_ERROR env (#1805)
Browse files Browse the repository at this point in the history
* Adding support for IGNORE_TIMEOUT_ERROR env

* Renaming flag to PERCY_IGNORE_TIMEOUT_ERROR
  • Loading branch information
Amit3200 authored Dec 2, 2024
1 parent 3daa654 commit 2e25463
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
17 changes: 15 additions & 2 deletions packages/core/src/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,24 @@ export class Network {
return this.#aborted.has(requestId);
}

logNetworkRequests(filter) {
let msg = '';
let reqs = Array.from(this.#requests.values()).filter(filter).map(r => r.url);
msg += `\n\n ${['Active requests:', ...reqs].join('\n - ')}\n`;
return msg;
}

// Throw a better network timeout error
_throwTimeoutError(msg, filter = () => true) {
if (this.log.shouldLog('debug')) {
let reqs = Array.from(this.#requests.values()).filter(filter).map(r => r.url);
msg += `\n\n ${['Active requests:', ...reqs].join('\n - ')}\n`;
msg += this.logNetworkRequests(filter);
}

if (process.env.PERCY_IGNORE_TIMEOUT_ERROR === 'true') {
let warnMsg = 'Ignoring network timeout failures.';
warnMsg += this.logNetworkRequests(filter);
this.log.warn(warnMsg);
return;
}

throw new Error(msg);
Expand Down
17 changes: 17 additions & 0 deletions packages/core/test/discovery.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@ describe('Discovery', () => {
afterEach(() => {
Network.TIMEOUT = undefined;
process.env.PERCY_NETWORK_IDLE_WAIT_TIMEOUT = undefined;
process.env.PERCY_IGNORE_TIMEOUT_ERROR = undefined;
});

it('throws an error when requests fail to idle in time', async () => {
Expand Down Expand Up @@ -1068,6 +1069,22 @@ describe('Discovery', () => {
));
});

it('should not throw error when requests fail to idle in time when PERCY_IGNORE_TIMEOUT_ERROR is true', async () => {
process.env.PERCY_IGNORE_TIMEOUT_ERROR = 'true';
await percy.snapshot({
name: 'test idle',
url: 'http://localhost:8000'
});

expect(logger.stderr).toContain(jasmine.stringMatching(
'^\\[percy] Ignoring network timeout failures.'
));

expect(logger.stderr).toContain(jasmine.stringMatching(
' Active requests:\n' + ' - http://localhost:8000/img.gif\n'
));
});

describe('with multiple network requests with same url', () => {
beforeEach(async () => {
// a custom page where we make 2 requests to same url where only one of them will
Expand Down
1 change: 1 addition & 0 deletions packages/core/test/percy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describe('Percy', () => {
await server.close();
delete process.env.PERCY_TOKEN;
delete process.env.PERCY_CLIENT_ERROR_LOGS;
delete process.env.PERCY_IGNORE_TIMEOUT_ERROR;
});

const sharedExpectBlockForSuggestion = (expectedBody) => {
Expand Down

0 comments on commit 2e25463

Please sign in to comment.