Skip to content

Subcommand Holds onto _optionValues Between Executions #1829

Closed
@manunamz

Description

I am setting up some unit tests around a commander.js cli tool. I verify that the args and opts the program is holding onto internally matches expectations for each test. It seems that subcommands, and possibly the Command object in general, is holding onto options between executions.

This means, if I test a command with options and then test the same command without any options, the second test will still have the options from the first execution.

// test with options pass
program.parse(['program', 'command', '-o', 'stuff']);
// test without options still have previous options
program.parse(['program', 'command']); // '-o' and 'stuff' will still be parsed

I am currently working around this issue by manually clearing options between each test -- see the following:

  afterEach(() => {
    const cmd: any = program.commands.find((cmd) => cmd.name() === 'command');
    cmd._optionValues = {};
  });

This is just a short description to notify the commander.js maintainer. I think the issue is probably a simple reset of _optionValues or class properties more generally...If more detail is required, I can fill out a more detailed ticket upon request.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions