Skip to content

Commit 73ad785

Browse files
Dont run responsive capture if defer uploads is true
1 parent ac379dd commit 73ad785

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

percy/snapshot.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ def capture_responsive_dom(driver, eligible_widths, cookies, **kwargs):
140140
return dom_snapshots
141141

142142
def is_responsive_snapshot_capture(config, **kwargs):
143+
# Don't run resposive snapshot capture when defer uploads is enabled
144+
if 'percy' in config and config['percy'].get('deferUploads', False): return False
145+
143146
return kwargs.get('responsive_snapshot_capture', False) or kwargs.get(
144147
'responsiveSnapshotCapture', False) or (
145148
'snapshot' in config and config['snapshot'].get('responsiveSnapshotCapture'))

tests/test_snapshot.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def dummy_method1(self):
4949

5050

5151
# mock helpers
52-
def mock_healthcheck(fail=False, fail_how='error', session_type=None, widths = None):
52+
def mock_healthcheck(fail=False, fail_how='error', session_type=None, widths=None, config=None):
5353
health_body = { "success": True }
5454
health_headers = { 'X-Percy-Core-Version': '1.0.0' }
5555
health_status = 200
@@ -66,6 +66,7 @@ def mock_healthcheck(fail=False, fail_how='error', session_type=None, widths = N
6666
health_body["type"] = session_type
6767

6868
if widths: health_body['widths'] = widths
69+
if config: health_body['config'] = config
6970
health_body = json.dumps(health_body)
7071
httpretty.register_uri(
7172
httpretty.GET, 'http://localhost:5338/percy/healthcheck',
@@ -272,6 +273,23 @@ def test_posts_snapshots_to_the_local_percy_server_for_responsive_snapshot_captu
272273
{ 'html': dom_string, 'cookies': expected_cookies, 'width': 390 }
273274
])
274275

276+
def test_posts_snapshots_to_the_local_percy_server_with_defer_and_responsive(self):
277+
mock_logger()
278+
mock_healthcheck(widths = { "config": [375, 1280], "mobile": [390]}, config = { 'percy': { 'deferUploads': True }})
279+
mock_snapshot()
280+
dom_string = '<html><head></head><body>Snapshot Me</body></html>'
281+
expected_dom_snapshot = { 'html': dom_string, 'cookies': [] }
282+
283+
percy_snapshot(self.driver, 'Snapshot 1', responsiveSnapshotCapture = True)
284+
285+
self.assertEqual(httpretty.last_request().path, '/percy/snapshot')
286+
287+
s1 = httpretty.latest_requests()[2].parsed_body
288+
self.assertEqual(s1['name'], 'Snapshot 1')
289+
self.assertEqual(s1['url'], 'http://localhost:8000/')
290+
self.assertEqual(s1['dom_snapshot'], expected_dom_snapshot)
291+
292+
275293
@patch('selenium.webdriver.Chrome')
276294
def test_posts_snapshots_to_the_local_percy_server_for_responsive_dom_chrome(self, MockChrome):
277295
os.environ['RESONSIVE_CAPTURE_SLEEP_TIME'] = '1'
@@ -282,7 +300,7 @@ def test_posts_snapshots_to_the_local_percy_server_for_responsive_dom_chrome(sel
282300
driver.get_cookies.return_value = ''
283301
driver.execute_cdp_cmd.return_value = ''
284302
driver.get_window_size.return_value = { 'height': 400, 'width': 800 }
285-
mock_healthcheck(widths = { "config": [375], "mobile": [390]})
303+
mock_healthcheck(widths = { "config": [375], "mobile": [390] })
286304
mock_snapshot()
287305
expected_dom_snapshot = [
288306
{ 'cookies': '', 'html': 'some_dom', 'width': 600 },

0 commit comments

Comments
 (0)