{"id":15395,"library":"test-cmd","title":"Minimal Test Runner Command Builder","description":"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.","status":"abandoned","version":"1.7.0","language":"javascript","source_language":"en","source_url":"git://github.com/dominictarr/test-cmd","tags":["javascript"],"install":[{"cmd":"npm install test-cmd","lang":"bash","label":"npm"},{"cmd":"yarn add test-cmd","lang":"bash","label":"yarn"},{"cmd":"pnpm add test-cmd","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used for parsing command-line arguments within the generated test commands. Note: `optimist` is itself unmaintained and deprecated.","package":"optimist","optional":false},{"reason":"A common dependency for writing simple, TAP-producing tests, often used in conjunction with `test-cmd` to structure test logic.","package":"tape","optional":true},{"reason":"Provides a simple readable/writable stream for piping data, which is useful in command-line testing scenarios.","package":"through","optional":true}],"imports":[{"note":"The package exclusively uses CommonJS `require` syntax. Attempting to use ESM `import` will result in errors as it's not an ESM module.","wrong":"import createCommand from 'test-cmd';","symbol":"createCommand","correct":"const createCommand = require('test-cmd');"},{"note":"The package exports a single function. The conventional use is to assign the entire module export to a variable, then call methods on it, like `testCmd.command`.","wrong":"const { command } = require('test-cmd');","symbol":"testCmd","correct":"const testCmd = require('test-cmd');\ntestCmd.command(args, fn);"}],"quickstart":{"code":"const createCommand = require('test-cmd');\nconst tape = require('tape');\n\n// Simulate a simple command that echoes arguments\nconst mockCommand = (args) => {\n  return `echo 'Hello, ${args.join(' ')}'`;\n};\n\n// Define a test using tape and test-cmd\ntape('test-cmd basic usage', (t) => {\n  t.plan(1); // Expect one assertion\n\n  const myTestCmd = createCommand();\n\n  myTestCmd.command(['world'], (run) => {\n    // In a real scenario, 'run' would execute a shell command.\n    // Here, we simulate it.\n    const simulatedOutput = mockCommand(run.argv);\n    \n    // 'run' object would typically contain child process stdout/stderr\n    // For this mock, we just check the generated command string.\n    t.equal(simulatedOutput, \"echo 'Hello, world'\", 'should generate the correct echo command');\n    t.end();\n  });\n\n});\n\n// To run this: save as e.g., `my-test.js`, then `node my-test.js`\n// This quickstart mocks the actual command execution for simplicity, \n// but `test-cmd` would typically spawn a child process.","lang":"javascript","description":"Demonstrates how to import `test-cmd` using CommonJS and define a simple test command with `tape`, illustrating the expected command generation."},"warnings":[{"fix":"Ensure your project or file uses CommonJS (`.js` files without `\"type\": \"module\"` in `package.json` or explicit `.cjs` extension) and use `const testCmd = require('test-cmd');`.","message":"The package is CommonJS-only. Using `import` statements in an ESM module context will result in a `SyntaxError: Cannot use import statement outside a module` or `require is not defined` error. It requires a Node.js environment configured for CommonJS.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Consider migrating to actively maintained test runner frameworks (e.g., Jest, Mocha, Vitest) or modern CLI argument parsers (e.g., `yargs`, `commander.js`) for new projects. For existing projects, be aware of potential security risks and compatibility issues.","message":"The package is unmaintained, with its last update over 8 years ago. It relies on deprecated dependencies like `optimist` for argument parsing, which may have security vulnerabilities or unexpected behavior with newer Node.js versions or complex CLI arguments.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Wrap `test-cmd`'s callback-based functions in Promises using `util.promisify` or manual Promise constructors if `async/await` syntax is desired.","message":"Direct integration with modern `async/await` patterns is challenging due to its callback-based API. While it can be wrapped in Promises, the core design predates widespread async/await adoption in Node.js.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Change your file to use CommonJS (e.g., by ensuring your `package.json` does not have `\"type\": \"module\"`, or changing your file extension to `.cjs`), or use a transpiler like Babel if you must use ESM syntax while consuming CJS modules.","cause":"Attempting to `require('test-cmd')` in an ECMAScript Module (ESM) context.","error":"ReferenceError: require is not defined"},{"fix":"Use `const createCommand = require('test-cmd');` to get the default function export.","cause":"Incorrectly trying to destructure a named export, or accessing a property that doesn't exist. `test-cmd` exports a single function as its `module.exports`.","error":"TypeError: createCommand is not a function"},{"fix":"Ensure that any child processes or servers spawned by your tests (managed by `test-cmd` or otherwise) are properly terminated or cleaned up after each test run, typically in `t.end()` or `afterEach` hooks.","cause":"While not directly caused by `test-cmd`, old testing patterns often involve spawning multiple processes or servers without proper cleanup. `test-cmd` itself can spawn child processes for testing, and if these don't exit cleanly, they might leave resources like open ports in use.","error":"Error: listen EADDRINUSE: address already in use :::<port>"}],"ecosystem":"npm"}