Skip to content

Commit

Permalink
Adding testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
Amit3200 committed Dec 3, 2024
1 parent 92bb0c6 commit 9d33293
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
};

Expand Down
30 changes: 30 additions & 0 deletions test/index.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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';
Expand Down

0 comments on commit 9d33293

Please sign in to comment.