Skip to content

Commit

Permalink
test: add failing test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
cristiand391 committed Nov 30, 2023
1 parent 7dd619a commit 4c6d3cf
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
54 changes: 54 additions & 0 deletions test/commandExecution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,60 @@ describe('toJson', () => {
expect(actual.deprecatedCommandUsed).to.equal('deprecated:alias');
});

it('does not capture flags that have a default value but were not specified by the user', async () => {
process.env.CI = 'true';
const config = stubInterface<Interfaces.Config>(sandbox, {});

// the `test` command has `user` flag that sets a default value
// we run this command with no flags to ensure only flags specified (typed by user) are captured in telemetry
const execution = await CommandExecution.create({
argv: [],
command: MyCommand,
config,
});
const actual = execution.toJson();
expect(actual.specifiedFlags).to.equal('');
expect(actual.specifiedFlagFullNames).to.equal('');
expect(actual.deprecatedFlagsUsed).to.equal('');
});

it('captures flag if used non-deprecated alias', async () => {
process.env.CI = 'true';
const config = stubInterface<Interfaces.Config>(sandbox, {});

// flag name: "blue"
// flag alias: "bleu"
// non-deprecated alias
const execution = await CommandExecution.create({
argv: ['--bleu', 'test'],
command: MyCommand,
config,
});
const actual = execution.toJson();
expect(actual.specifiedFlags).to.equal('blue');
expect(actual.specifiedFlagFullNames).to.equal('blue');
expect(actual.deprecatedFlagsUsed).to.equal('');
});

it('captures flag if used non-deprecated char alias', async () => {
process.env.CI = 'true';
const config = stubInterface<Interfaces.Config>(sandbox, {});

// flag name: "red"
// flag char: "r"
// flag char alias: "e"
// non-deprecated alias
const execution = await CommandExecution.create({
argv: ['-e', 'test'],
command: MyCommand,
config,
});
const actual = execution.toJson();
expect(actual.specifiedFlags).to.equal('red');
expect(actual.specifiedFlagFullNames).to.equal('red');
expect(actual.deprecatedFlagsUsed).to.equal('');
});

it('shows short help flag', async () => {
process.env.CI = 'true';
const config = stubInterface<Interfaces.Config>(sandbox, {});
Expand Down
12 changes: 12 additions & 0 deletions test/helpers/myCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ export class MyCommand extends SfCommand<void> {
test: Flags.string({ char: 't' }),
valid: Flags.string({ aliases: ['invalid', 'i'], char: 'v', deprecateAliases: true }),
newflag: Flags.string({ aliases: ['oldflag', 'o'], char: 'n', deprecateAliases: true }),
user: Flags.string({
aliases: ['targetuser'],
deprecateAliases: true,
default: async () => 'test',
}),
blue: Flags.string({
aliases: ['bleu'],
}),
red: Flags.string({
charAliases: ['e'],
char: 'r',
}),
};
public static args = {};

Expand Down

0 comments on commit 4c6d3cf

Please sign in to comment.