Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/client/src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ function parseVisualConfigFromEnv(log) {
validateBoolean(visualConfig.compareWithPreviousRun, 'compareWithPreviousRun');
validateBoolean(visualConfig.diffIgnoreEnabled, 'diffIgnoreEnabled');
validateNumberInRange(visualConfig.diffIgnorePercentage, 'diffIgnorePercentage');
validateIntegerRange(visualConfig.diffSensitivity, 'diffSensitivity', 1, 5);
// 0-indexed like the project setting: 0 = Very Strict ... 4 = Very Relaxed
validateIntegerRange(visualConfig.diffSensitivity, 'diffSensitivity', 0, 4);

if (visualConfig.browsers != null) {
if (!Array.isArray(visualConfig.browsers) || !visualConfig.browsers.every(b => typeof b === 'string')) {
Expand Down
19 changes: 18 additions & 1 deletion packages/client/test/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -769,13 +769,30 @@ describe('PercyClient', () => {
.toBeRejectedWithError('Invalid PERCY_VISUAL_CONFIG: value must be valid JSON');
});

it('accepts diffSensitivity 0 (Very Strict)', async () => {
process.env.PERCY_VISUAL_CONFIG = JSON.stringify({ diffSensitivity: 0 });

await expectAsync(client.createBuild({ projectType: 'web' })).toBeResolved();

expect(api.requests['/builds'][0].body.data.attributes['visual-config'])
.toEqual({ diffSensitivity: 0 });
});

it('throws when PERCY_VISUAL_CONFIG contains invalid types', async () => {
process.env.PERCY_VISUAL_CONFIG = JSON.stringify({
diffSensitivity: 'high'
});

await expectAsync(client.createBuild({ projectType: 'web' })).toBeRejectedWithError(
"Invalid PERCY_VISUAL_CONFIG: 'diffSensitivity' must be an integer between 1 and 5"
"Invalid PERCY_VISUAL_CONFIG: 'diffSensitivity' must be an integer between 0 and 4"
);
});

it('throws when PERCY_VISUAL_CONFIG diffSensitivity is out of range', async () => {
process.env.PERCY_VISUAL_CONFIG = JSON.stringify({ diffSensitivity: 5 });

await expectAsync(client.createBuild({ projectType: 'web' })).toBeRejectedWithError(
"Invalid PERCY_VISUAL_CONFIG: 'diffSensitivity' must be an integer between 0 and 4"
);
});

Expand Down
Loading