Skip to content

Commit

Permalink
tags support (#1625)
Browse files Browse the repository at this point in the history
  • Loading branch information
shantanuk-browserstack authored Jun 21, 2024
1 parent 198a695 commit fad41af
Show file tree
Hide file tree
Showing 12 changed files with 271 additions and 98 deletions.
13 changes: 12 additions & 1 deletion packages/cli-command/src/flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,22 @@ export const debug = {
group: 'Percy'
};

export const labels = {
name: 'labels',
description: 'Associates labels to the build (ex: --labels=dev,prod )',
group: 'Global',
type: 'string',
parse: String,
percyrc: 'labels',
short: 'l'
};

// Group constants
export const GLOBAL = [
verbose,
quiet,
silent
silent,
labels
];

export const PERCY = [
Expand Down
23 changes: 12 additions & 11 deletions packages/cli-command/test/command.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,18 @@ describe('Command', () => {
await test(['--help']);

expect(logger.stdout).toEqual([dedent`
Usage:
$ test [options]
Options:
--verbose [level] Replaces common flag (default: "debug")
-q, --qux Replaces common short flag
Global options:
--quiet Log errors only
-s, --silent Log nothing
-h, --help Display command help
Usage:
$ test [options]
Options:
--verbose [level] Replaces common flag (default: "debug")
-q, --qux Replaces common short flag
Global options:
--quiet Log errors only
-s, --silent Log nothing
-l, --labels <string> Associates labels to the build (ex: --labels=dev,prod )
-h, --help Display command help
` + '\n']);
});

Expand Down
44 changes: 41 additions & 3 deletions packages/cli-command/test/flags.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,49 @@ describe('Built-in flags:', () => {
});
});

describe('--labels', () => {
it('sets labels to the given flag labels', async () => {
test = command('percy', {
percy: {}
}, ({ percy }) => {
test.percy = percy;
});

await test(['--labels=tag1,tag2']);

expect(test.percy.labels).toBe('tag1,tag2');
});

it('sets labels to the given config labels', async () => {
test = command('percy', {
percy: { labels: 'tag3,tag4' }
}, ({ percy }) => {
test.percy = percy;
});

await test();

expect(test.percy.labels).toBe('tag3,tag4');
});

it('sets labels to the given flag labels when both are present', async () => {
test = command('percy', {
percy: { labels: 'tag3,tag4' }
}, ({ percy }) => {
test.percy = percy;
});

await test(['--labels=tag1,tag2']);

expect(test.percy.labels).toBe('tag1,tag2');
});
});

describe('Percy flags:', () => {
const expectedMinPercyFlags = jasmine.stringContaining(dedent`
Percy options:
-c, --config <file> Config file path
-d, --dry-run Print snapshot names only
-c, --config <file> Config file path
-d, --dry-run Print snapshot names only
`);

const expectedAllPercyFlags = jasmine.stringContaining(dedent`
Expand Down Expand Up @@ -99,7 +137,7 @@ describe('Built-in flags:', () => {
expect(logger.stdout).not.toEqual([expectedAllPercyFlags]);
expect(logger.stdout).toEqual([expectedMinPercyFlags]);
expect(logger.stdout).toEqual([jasmine.stringContaining(
' -P, --port [number] Local CLI server port (default: 5338)'
' -P, --port [number] Local CLI server port (default: 5338)'
)]);
});

Expand Down
159 changes: 84 additions & 75 deletions packages/cli-command/test/help.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ describe('Help output', () => {
$ foo <command>
Commands:
bar:baz [options] Foo bar baz
help [command] Display command help
bar:baz [options] Foo bar baz
help [command] Display command help
Global options:
-v, --verbose Log everything
-q, --quiet Log errors only
-s, --silent Log nothing
-h, --help Display command help
-v, --verbose Log everything
-q, --quiet Log errors only
-s, --silent Log nothing
-l, --labels <string> Associates labels to the build (ex: --labels=dev,prod )
-h, --help Display command help
` + '\n']);
});

Expand Down Expand Up @@ -96,34 +97,35 @@ describe('Help output', () => {

expect(logger.stderr).toEqual([]);
expect(logger.stdout).toEqual([dedent`
Command description
Usage:
$ test [options] <first> [second]
Arguments:
first First command argument
second Second command argument (default: "2")
Commands:
sub [options]
sub:nested [options] Nested description
help [command] Display command help
Options:
-o, --one Command flag 1
--two <value> Command flag 2
--other-flag
Global options:
-v, --verbose Log everything
-q, --quiet Log errors only
-s, --silent Log nothing
-h, --help Display command help
Examples:
$ test --one
$ test -o --two 2
Command description
Usage:
$ test [options] <first> [second]
Arguments:
first First command argument
second Second command argument (default: "2")
Commands:
sub [options]
sub:nested [options] Nested description
help [command] Display command help
Options:
-o, --one Command flag 1
--two <value> Command flag 2
--other-flag
Global options:
-v, --verbose Log everything
-q, --quiet Log errors only
-s, --silent Log nothing
-l, --labels <string> Associates labels to the build (ex: --labels=dev,prod )
-h, --help Display command help
Examples:
$ test --one
$ test -o --two 2
` + '\n']);

logger.reset();
Expand Down Expand Up @@ -151,6 +153,7 @@ describe('Help output', () => {
-v, --verbose Log everything
-q, --quiet Log errors only
-s, --silent Log nothing
-l, --labels <string> Associates labels to the build (ex: --labels=dev,prod )
-h, --help Display command help
` + '\n']);

Expand All @@ -173,6 +176,7 @@ describe('Help output', () => {
-v, --verbose Log everything
-q, --quiet Log errors only
-s, --silent Log nothing
-l, --labels <string> Associates labels to the build (ex: --labels=dev,prod )
-h, --help Display command help
Examples:
Expand All @@ -191,10 +195,11 @@ describe('Help output', () => {
$ test sub:nested:deep [options]
Global options:
-v, --verbose Log everything
-q, --quiet Log errors only
-s, --silent Log nothing
-h, --help Display command help
-v, --verbose Log everything
-q, --quiet Log errors only
-s, --silent Log nothing
-l, --labels <string> Associates labels to the build (ex: --labels=dev,prod )
-h, --help Display command help
` + '\n']);
});

Expand Down Expand Up @@ -311,20 +316,21 @@ describe('Help output', () => {
$ test <command>
Arguments:
arg (default: "foo")
arg (default: "foo")
Commands:
command [options]
help [command] Display command help
help [command] Display command help
Options:
--flag
Global options:
-v, --verbose Log everything
-q, --quiet Log errors only
-s, --silent Log nothing
-h, --help Display command help
-v, --verbose Log everything
-q, --quiet Log errors only
-s, --silent Log nothing
-l, --labels <string> Associates labels to the build (ex: --labels=dev,prod )
-h, --help Display command help
` + '\n']);
});

Expand All @@ -349,49 +355,52 @@ describe('Help output', () => {
$ test [options]
Options:
--help Custom help
--version Custom version
--help Custom help
--version Custom version
Global options:
-v, --verbose Log everything
-q, --quiet Log errors only
-s, --silent Log nothing
-h Display command help
-V Display version
-v, --verbose Log everything
-q, --quiet Log errors only
-s, --silent Log nothing
-l, --labels <string> Associates labels to the build (ex: --labels=dev,prod )
-h Display command help
-V Display version
` + '\n']);

logger.reset();
await test(false, true);
expect(logger.stdout).toEqual([dedent`
Usage:
$ test [options]
Options:
-h Custom help
-V Custom version
Global options:
-v, --verbose Log everything
-q, --quiet Log errors only
-s, --silent Log nothing
--help Display command help
--version Display version
Usage:
$ test [options]
Options:
-h Custom help
-V Custom version
Global options:
-v, --verbose Log everything
-q, --quiet Log errors only
-s, --silent Log nothing
-l, --labels <string> Associates labels to the build (ex: --labels=dev,prod )
--help Display command help
--version Display version
` + '\n']);

logger.reset();
await test(true, true);
expect(logger.stdout).toEqual([dedent`
Usage:
$ test [options]
Options:
-h, --help Custom help
-V, --version Custom version
Global options:
-v, --verbose Log everything
-q, --quiet Log errors only
-s, --silent Log nothing
Usage:
$ test [options]
Options:
-h, --help Custom help
-V, --version Custom version
Global options:
-v, --verbose Log everything
-q, --quiet Log errors only
-s, --silent Log nothing
-l, --labels <string> Associates labels to the build (ex: --labels=dev,prod )
` + '\n']);
});

Expand Down
1 change: 1 addition & 0 deletions packages/cli-upload/test/upload.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ describe('percy upload', () => {
scope: null,
sync: false,
'test-case': null,
tags: [],
'scope-options': {},
'minimum-height': 10,
'enable-javascript': null,
Expand Down
Loading

0 comments on commit fad41af

Please sign in to comment.