From 2e25463a0528d39eb6756727adf22edf061cd3b1 Mon Sep 17 00:00:00 2001 From: Amit Singh Sansoya Date: Mon, 2 Dec 2024 14:44:36 +0530 Subject: [PATCH] Adding support for IGNORE_TIMEOUT_ERROR env (#1805) * Adding support for IGNORE_TIMEOUT_ERROR env * Renaming flag to PERCY_IGNORE_TIMEOUT_ERROR --- packages/core/src/network.js | 17 +++++++++++++++-- packages/core/test/discovery.test.js | 17 +++++++++++++++++ packages/core/test/percy.test.js | 1 + 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/packages/core/src/network.js b/packages/core/src/network.js index ccdfb059e..5bdf5d3f2 100644 --- a/packages/core/src/network.js +++ b/packages/core/src/network.js @@ -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); diff --git a/packages/core/test/discovery.test.js b/packages/core/test/discovery.test.js index 059ad279e..c99ba2cfe 100644 --- a/packages/core/test/discovery.test.js +++ b/packages/core/test/discovery.test.js @@ -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 () => { @@ -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 diff --git a/packages/core/test/percy.test.js b/packages/core/test/percy.test.js index fec47941a..4f2f84b75 100644 --- a/packages/core/test/percy.test.js +++ b/packages/core/test/percy.test.js @@ -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) => {