Skip to main content

runCommand

Callable

  • runCommand<O, P>(command: Command<O, P, {}>, params: P, options?: Partial<O>): Promise<string>

  • Runs a Command outside the context of a Program, but mimics similar functionality, including React component rendering. Params are required as they're passed to the run method, while options are optional and assume class properties have been defined. Also, the exit and log methods have been mocked with Vitest spies so that they can be asserted.

    import { runCommand } from '@boost/cli/test';
    import TestCommand from '../src/commands/TestCommand';

    it('runs a command', async () => {
    const command = new TestCommand();

    expect(await runCommand(command, ['foo', 'bar', 'baz'])).toMatchSnapshot();
    expect(command.log).toHaveBeenCalled();
    });

    Since there is no Program context, any functionality that requires a program will fail. If needed, use runProgram() instead.


    Type parameters