Minimal Test Runner Command Builder

1.7.0 · abandoned · verified Tue Apr 21

The `test-cmd` package is a minimalist Node.js utility designed to facilitate the creation and execution of simple command-line test runners. Released with its latest stable version 1.7.0 over eight years ago, this package is built entirely on CommonJS modules and leverages older dependencies like `optimist` for argument parsing, `tape` for test assertions, and `through` for stream manipulation. Its primary function is to wrap shell commands and integrate them into a testing flow, making it suitable for black-box testing of command-line interfaces. Due to its age and lack of recent maintenance, it does not support modern JavaScript features like ESM or `async/await` and is generally considered superseded by contemporary testing frameworks. It has an infrequent release cadence, with its last update being many years ago, indicating it is no longer actively maintained.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to import `test-cmd` using CommonJS and define a simple test command with `tape`, illustrating the expected command generation.

const createCommand = require('test-cmd');
const tape = require('tape');

// Simulate a simple command that echoes arguments
const mockCommand = (args) => {
  return `echo 'Hello, ${args.join(' ')}'`;
};

// Define a test using tape and test-cmd
tape('test-cmd basic usage', (t) => {
  t.plan(1); // Expect one assertion

  const myTestCmd = createCommand();

  myTestCmd.command(['world'], (run) => {
    // In a real scenario, 'run' would execute a shell command.
    // Here, we simulate it.
    const simulatedOutput = mockCommand(run.argv);
    
    // 'run' object would typically contain child process stdout/stderr
    // For this mock, we just check the generated command string.
    t.equal(simulatedOutput, "echo 'Hello, world'", 'should generate the correct echo command');
    t.end();
  });

});

// To run this: save as e.g., `my-test.js`, then `node my-test.js`
// This quickstart mocks the actual command execution for simplicity, 
// but `test-cmd` would typically spawn a child process.

view raw JSON →