{"id":17134702,"url":"https://github.com/robojones/command-test","last_synced_at":"2026-05-06T21:31:33.059Z","repository":{"id":57204060,"uuid":"101655800","full_name":"robojones/command-test","owner":"robojones","description":"The easy way to test commands in Node.js.","archived":false,"fork":false,"pushed_at":"2017-10-04T16:12:43.000Z","size":29,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-22T22:01:45.578Z","etag":null,"topics":["command","nodejs","npm","promises","testing"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/command-test","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/robojones.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-08-28T15:08:57.000Z","updated_at":"2017-08-28T16:39:58.000Z","dependencies_parsed_at":"2022-09-17T19:03:50.420Z","dependency_job_id":null,"html_url":"https://github.com/robojones/command-test","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robojones%2Fcommand-test","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robojones%2Fcommand-test/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robojones%2Fcommand-test/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robojones%2Fcommand-test/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robojones","download_url":"https://codeload.github.com/robojones/command-test/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245025993,"owners_count":20549071,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["command","nodejs","npm","promises","testing"],"created_at":"2024-10-14T19:45:32.315Z","updated_at":"2026-05-06T21:31:33.023Z","avatar_url":"https://github.com/robojones.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# command-test\nThe easy way to test commands.\n\n[![Build Status](https://travis-ci.org/robojones/command-test.svg?branch=master)](https://travis-ci.org/robojones/command-test)\n[![Test Coverage](https://codeclimate.com/github/robojones/command-test/badges/coverage.svg)](https://codeclimate.com/github/robojones/command-test/coverage)\n\n[![bitHound Code](https://www.bithound.io/github/robojones/command-test/badges/code.svg)](https://www.bithound.io/github/robojones/command-test)\n[![bitHound Overall Score](https://www.bithound.io/github/robojones/command-test/badges/score.svg)](https://www.bithound.io/github/robojones/command-test)\n[![bitHound Dependencies](https://www.bithound.io/github/robojones/command-test/badges/dependencies.svg)](https://www.bithound.io/github/robojones/command-test/master/dependencies/npm)\n[![bitHound Dev Dependencies](https://www.bithound.io/github/robojones/command-test/badges/devDependencies.svg)](https://www.bithound.io/github/robojones/command-test/master/dependencies/npm)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n## Install\n\n```\nnpm i command-test --save\n```\n\n## Docs\n\n### command(cmd)\n\nThis function runs the given command.\n\n__Returns__ a `\u003cPromise\u003e` that resolves to a [Command](#class-command) object.\n\n```javascript\nconst command = require('command-test')\n\nasync function example() {\n  const cmd = await command('node -v')\n\n  cmd.code // 0\n  cmd.out // \"v8.1.4\"\n  cmd.err // \"\"\n}\n\nexample()\n```\n\n### command.works(cmd)\nThis function runs the given command. If the command's exit code __is not 0__, an error gets thrown.\n\n__Returns__ a `\u003cPromise\u003e` that resolves to a [Command](#class-command) object.\n\n```javascript\nconst command = require('command-test')\n\nasync function example() {\n  const cmd = await command.works('node -v')\n  command.code // 0\n  command.out // \"v8.1.4\"\n  command.err // \"\"\n\n  await command.fails('non-existent-command')\n  // Throws an error because the command has an exit code 1\n}\n\nexample()\n```\n\n### command.fails(cmd)\nThis function runs the given command. If the command's exit code __is 0__, an error gets thrown.\n\n__Returns__ a `\u003cPromise\u003e` that resolves to a [Command](#class-command) object.\n\n```javascript\nconst command = require('command-test')\n\nasync function example() {\n  const cmd = await command.fails('non-existent-command')\n  cmd.code // 1\n  cmd.err // \"/bin/sh: 1: huhn: not found\\n\"\n  cmd.out // \"\"\n\n  await command.fails('node -v')\n  // Throws an error because the command has an exit code 0\n}\n\nexample()\n```\n\n### Class: Command\n\nRepresents a command.\n\nThis class extends [BetterEvents](https://npmjs.com/package/better-events).\nTherefore you can await events if you don't pass a listener to the `.once()` method.\n\n#### Example\n```javascript\nconst { Command } = require('command-test')\n\nasync function example() {\n  const command = new Command('node -v')\n\n  await command.once('done')\n\n  command.code // 0\n  command.out // \"v8.1.4\"\n  command.err // \"\"\n}\n\nexample()\n```\n\n#### Event: \"done\"\nThis event is emitted as soon as the command exits.\n\n```javascript\nawait command.once('done')\n\n// or\ncommand.once('done', () =\u003e {\n\n})\n\n// or\ncommand.on('done', () =\u003e {\n\n})\n```\n\n#### Property: out\nThis property is a `\u003cstring\u003e` that stores everything that the command has written to the stdout stream.\n\n#### Property: err\n\nThis property is a `\u003cstring\u003e` that stores everything that the command has written to the __stderr__ stream.\n\n#### Property: code\nThis property stores the __exit code__ `\u003cnumber\u003e` of the command.\n\n#### Property: stdout\nThis property is a reference to the stdout of the command's child_process\n\n#### Property: stderr\nThis property is a reference to the stderr of the command's child_process","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobojones%2Fcommand-test","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobojones%2Fcommand-test","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobojones%2Fcommand-test/lists"}