From 9d33293e188406ac1dab1088f6120d087949c24d Mon Sep 17 00:00:00 2001 From: amit3200 Date: Tue, 3 Dec 2024 23:23:05 +0530 Subject: [PATCH] Adding testcases --- index.js | 3 +++ test/index.test.mjs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/index.js b/index.js index da24668..9eb781b 100644 --- a/index.js +++ b/index.js @@ -165,6 +165,9 @@ const percySnapshot = async function percySnapshot(driver, name, options) { // Handle errors log.error(`Could not take DOM snapshot "${name}"`); log.error(error); + if (process.env.PERCY_RAISE_ERROR === 'true') { + throw error; + } } }; diff --git a/test/index.test.mjs b/test/index.test.mjs index ff9b923..3d933e7 100644 --- a/test/index.test.mjs +++ b/test/index.test.mjs @@ -212,6 +212,21 @@ describe('percySnapshot', () => { ])); expect(error).toBeInstanceOf(Error); }); + + it('handles snapshot failures if PERCY_RAISE_ERROR is true', async () => { + process.env.PERCY_RAISE_ERROR = 'true'; + await helpers.test('error', '/percy/snapshot'); + let error = null; + try { + await percySnapshot(driver, 'Snapshot 1'); + } catch (e) { + error = e; + } + expect(helpers.logger.stderr).toEqual(jasmine.arrayContaining([ + '[percy] Could not take DOM snapshot "Snapshot 1"' + ])); + expect(error).toBeInstanceOf(Error); + }); }); describe('percyScreenshot', () => { @@ -358,6 +373,21 @@ describe('percyScreenshot', () => { expect(error).toBeInstanceOf(Error); }); + it('handles snapshot failures if PERCY_RAISE_ERROR is true', async () => { + process.env.PERCY_RAISE_ERROR = 'true'; + await helpers.test('error', '/percy/automateScreenshot'); + let error = null; + try { + await percyScreenshot(driver, 'Snapshot 1'); + } catch (e) { + error = e; + } + expect(helpers.logger.stderr).toEqual(jasmine.arrayContaining([ + '[percy] Could not take Screenshot "Snapshot 1"' + ])); + expect(error).toBeInstanceOf(Error); + }); + it('throws error for web session', async () => { spyOn(percySnapshot, 'isPercyEnabled').and.returnValue(Promise.resolve(true)); utils.percy.type = 'web';