Skip to content

Commit

Permalink
improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
itsjwala committed Sep 14, 2023
1 parent 40f14c9 commit 11524f9
Showing 1 changed file with 110 additions and 6 deletions.
116 changes: 110 additions & 6 deletions packages/config/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,104 @@ describe('PercyConfig', () => {
expect(conf).toEqual({ foo: { bar: 'baz', qux: 'xyzzy' } });
});

describe('validates automate integration specific properties', () => {
beforeEach(() => {
delete process.env.PERCY_TOKEN;

PercyConfig.addSchema({
test: {
type: 'object',
additionalProperties: false,
properties: {
foo: {
type: 'number',
onlyAutomate: true
},
bar: {
type: 'number'
}
}
}
});
});

it('passes when no token present', () => {
expect(PercyConfig.validate({
test: {
foo: 1,
bar: 2
}
})).toBeUndefined();
});

it('passes when token is of automate project', () => {
process.env.PERCY_TOKEN = 'auto_PERCY_TOKEN';

expect(PercyConfig.validate({
test: {
foo: 1,
bar: 2
}
})).toBeUndefined();
});

it('warns when token is of legacy web project', () => {
process.env.PERCY_TOKEN = 'PERCY_TOKEN';

expect(PercyConfig.validate({
test: {
foo: 1,
bar: 2
}
})).toEqual([{
path: 'test.foo',
message: 'property only valid with Automate integration.'
}]);
});

it('warns when token is of web project', () => {
process.env.PERCY_TOKEN = 'web_PERCY_TOKEN';

expect(PercyConfig.validate({
test: {
foo: 1,
bar: 2
}
})).toEqual([{
path: 'test.foo',
message: 'property only valid with Automate integration.'
}]);
});

it('warns when token is of app project', () => {
process.env.PERCY_TOKEN = 'app_PERCY_TOKEN';

expect(PercyConfig.validate({
test: {
foo: 1,
bar: 2
}
})).toEqual([{
path: 'test.foo',
message: 'property only valid with Automate integration.'
}]);
});

it('warns when token is of self serve project', () => {
process.env.PERCY_TOKEN = 'ss_PERCY_TOKEN';

expect(PercyConfig.validate({
test: {
foo: 1,
bar: 2
}
})).toEqual([{
path: 'test.foo',
message: 'property only valid with Automate integration.'
}]);
});
});

it('can validate functions and regular expressions', () => {
PercyConfig.addSchema({
func: { instanceof: 'Function' },
Expand Down Expand Up @@ -1102,7 +1200,8 @@ describe('PercyConfig', () => {
'percy-css': '',
'enable-javascript': false,
'disable-shadow-dom': true,
'cli-enable-javascript': true
'cli-enable-javascript': true,
'ignore-region-xpaths': ['']
})).toEqual({
fooBar: 'baz',
foo: { barBaz: 'qux' },
Expand All @@ -1111,7 +1210,8 @@ describe('PercyConfig', () => {
percyCSS: '',
enableJavaScript: false,
disableShadowDOM: true,
cliEnableJavaScript: true
cliEnableJavaScript: true,
ignoreRegionXPaths: ['']
});
});

Expand All @@ -1123,15 +1223,17 @@ describe('PercyConfig', () => {
percyCSS: '',
enableJavaScript: false,
disableShadowDOM: true,
cliEnableJavaScript: true
cliEnableJavaScript: true,
ignoreRegionXPaths: ['']
}, { kebab: true })).toEqual({
'foo-bar': 'baz',
foo: { 'bar-baz': 'qux' },
'foo-bar-baz': ['qux'],
'percy-css': '',
'enable-javascript': false,
'disable-shadow-dom': true,
'cli-enable-javascript': true
'cli-enable-javascript': true,
'ignore-region-xpaths': ['']
});
});

Expand All @@ -1143,15 +1245,17 @@ describe('PercyConfig', () => {
percyCSS: '',
enableJavaScript: false,
disableShadowDOM: true,
cliEnableJavaScript: true
cliEnableJavaScript: true,
ignoreRegionXPaths: ['']
}, { snake: true })).toEqual({
foo_bar: 'baz',
foo: { bar_baz: 'qux' },
foo_bar_baz: ['qux'],
percy_css: '',
enable_javascript: false,
disable_shadow_dom: true,
cli_enable_javascript: true
cli_enable_javascript: true,
ignore_region_xpaths: ['']
});
});

Expand Down

0 comments on commit 11524f9

Please sign in to comment.