From 27c2ed3a8582fdfbde74cd7d2b962e43d70a726a Mon Sep 17 00:00:00 2001 From: Wil Wilsman Date: Thu, 29 Jul 2021 11:33:22 -0500 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20Fix=20enableJavaScript=20def?= =?UTF-8?q?ault=20for=20snapshot=20discovery?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/percy.js | 2 +- packages/core/test/discovery.test.js | 35 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/packages/core/src/percy.js b/packages/core/src/percy.js index f4f2261a3..1b2050a3c 100644 --- a/packages/core/src/percy.js +++ b/packages/core/src/percy.js @@ -295,7 +295,7 @@ export default class Percy { // open a new browser page page = await this.browser.page({ networkIdleTimeout: this.config.discovery.networkIdleTimeout, - enableJavaScript: domSnapshot ? conf.enableJavaScript : true, + enableJavaScript: conf.enableJavaScript ?? !domSnapshot, requestHeaders: discovery.requestHeaders, authorization: discovery.authorization, userAgent: discovery.userAgent, diff --git a/packages/core/test/discovery.test.js b/packages/core/test/discovery.test.js index c67eebc70..eaca09fdc 100644 --- a/packages/core/test/discovery.test.js +++ b/packages/core/test/discovery.test.js @@ -353,6 +353,41 @@ describe('Discovery', () => { ]); }); + it('does not capture javascript files when not enabled', async () => { + server.reply('/javascript.js', () => [200, 'text/javascript', 'window.location = "/"']); + + let jsDOM = dedent` + + + + `; + + await percy.snapshot({ + name: 'test snapshot', + url: 'http://localhost:8000', + domSnapshot: jsDOM + }); + + await percy.idle(); + + let paths = server.requests.map(r => r[0]); + expect(paths.sort()).not.toContain('/javascript.js'); + + expect(captured[0]).toEqual([ + jasmine.objectContaining({ + attributes: jasmine.objectContaining({ + 'resource-url': jasmine.stringMatching(/^\/percy\.\d+\.log$/) + }) + }), + jasmine.objectContaining({ + attributes: jasmine.objectContaining({ + 'resource-url': 'http://localhost:8000/', + 'is-root': true + }) + }) + ]); + }); + it('logs detailed debug logs', async () => { percy.loglevel('debug'); From 14a52fe03ed41cfa48d96014f79fd2fd53d5dd70 Mon Sep 17 00:00:00 2001 From: Wil Wilsman Date: Thu, 29 Jul 2021 11:59:04 -0500 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9C=85=20Fix=20lazy=20img=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Lazy images only work when JS is enabled. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attr-loading --- packages/core/test/discovery.test.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/core/test/discovery.test.js b/packages/core/test/discovery.test.js index eaca09fdc..c3c0ee552 100644 --- a/packages/core/test/discovery.test.js +++ b/packages/core/test/discovery.test.js @@ -838,7 +838,10 @@ describe('Discovery', () => { await percy.snapshot({ name: 'test snapshot', url: 'http://localhost:8000', - domSnapshot: testExternalAsyncDOM + domSnapshot: testExternalAsyncDOM, + // img loading is eager when not enabled which causes the page load event + // to wait for the eager img request to finish + enableJavaScript: true }); await percy.idle();