{"id":17816639,"url":"https://github.com/saurabhdaware/cli-testing-tool","last_synced_at":"2026-03-11T08:02:43.798Z","repository":{"id":45636176,"uuid":"407268449","full_name":"saurabhdaware/cli-testing-tool","owner":"saurabhdaware","description":"Testing library for cli commands","archived":false,"fork":false,"pushed_at":"2021-12-03T14:13:47.000Z","size":556,"stargazers_count":24,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-19T20:28:23.173Z","etag":null,"topics":["cli","nodejs-testing","testing-library"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/cli-testing-tool","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/saurabhdaware.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-09-16T18:10:42.000Z","updated_at":"2022-04-09T10:10:17.000Z","dependencies_parsed_at":"2022-09-03T02:41:15.198Z","dependency_job_id":null,"html_url":"https://github.com/saurabhdaware/cli-testing-tool","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/saurabhdaware/cli-testing-tool","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saurabhdaware%2Fcli-testing-tool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saurabhdaware%2Fcli-testing-tool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saurabhdaware%2Fcli-testing-tool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saurabhdaware%2Fcli-testing-tool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/saurabhdaware","download_url":"https://codeload.github.com/saurabhdaware/cli-testing-tool/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saurabhdaware%2Fcli-testing-tool/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30375487,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-11T06:09:32.197Z","status":"ssl_error","status_checked_at":"2026-03-11T06:09:17.086Z","response_time":84,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["cli","nodejs-testing","testing-library"],"created_at":"2024-10-27T16:38:47.720Z","updated_at":"2026-03-11T08:02:43.761Z","avatar_url":"https://github.com/saurabhdaware.png","language":"JavaScript","readme":"# CLI Testing Tool\n\nA testing library that allows you to test input and outputs of your CLI command.\n\n*Note: This is WIP but it should be ready enough for most common CLI use-cases I can think of*\n\n## Installation\n\nWith NPM:\n```sh\nnpm install --save-dev cli-testing-tool \n```\n\nWith Yarn:\n```sh\nyarn add --dev cli-testing-tool\n```\n\n## Examples\n\nCheck out [Interactive Examples on Stackblitz](https://stackblitz.com/edit/node-kfod5b?file=examples%2Fprompts%2Fprompts.test.js)\n\n### Testing Colored Terminal Text\n\nCheck out [this example of StackBlitz](https://stackblitz.com/edit/node-kfod5b?file=examples%2Fgraphic-hello-world%2Fgraphic-hello-world.test.js)\n\n```js\n// colored-greeting.test.js\nconst { createCommandInterface } = require('cli-testing-tool');\n\ntest('should print colored greetings', async () =\u003e {\n  const commandInterface = createCommandInterface('node ./graphic-print.js', {\n    cwd: __dirname, // considering, the test file is in the same directory as the cli file\n  });\n  await commandInterface.type('Saurabh\\n');\n  const terminal = await commandInterface.getOutput();\n\n  // ANSI Escape codes are tokenized into readable text token in tokenizedOutput\n  // Helpful when libraries like inquirer or prompts add ansi-escape codes.\n  expect(terminal.tokenizedOutput).toBe(\n    \"What's your name?Hi, [BOLD_START][RED_START]Saurabh[COLOR_END][BOLD_END]!\"\n  );\n\n  // ANSI Escape codes are not tokenized.\n  expect(terminal.rawOutput).toBe(\n    `What's your name?Hi, \\x1B[1m\\x1B[31mSaurabh\\x1B[39m\\x1B[22m!`\n  );\n\n  // ANSI Escape codes are removed\n  expect(terminal.stringOutput).toBe(`What's your name?Hi, Saurabh!`);\n});\n\n```\n\n\u003cdetails\u003e\n\u003csummary\u003eCode of the CLI that we're testing in above snippet\u003c/summary\u003e\n\n```js\n// colored-greeting.js\nconst readline = require('readline').createInterface({\n  input: process.stdin,\n  output: process.stdout\n});\n\nconst bold = (str) =\u003e `\\x1b[1m${str}\\x1b[22m`;\nconst red = (str) =\u003e `\\x1b[31m${str}\\x1b[39m`;\n\nreadline.question(`What's your name?`, (name) =\u003e {\n  console.log(`Hi, ${bold(red('Saurabh'))}!`);\n  readline.close();\n});\n\n```\n\n\u003c/details\u003e\n\n\n\n## Options\n\nYou can pass options as 2nd param to `createCommandInterface`.\n\nThe default options are:\n```js\nconst defaultOptions = {\n  typeDelay: 100, // number. delay between each `.type()` call\n  logData: false, // boolean. if true, logs the command data on terminal\n  logError: true, // boolean. if false, won't add command errors on terminal\n  cwd: process.cwd(), // string. working directory from where your simulated command is executed\n  env: undefined // object | undefined. environment variables object if there are any\n};\n```\n\n\n## Terminal Text Parsing Support Checklist\nRefer to [Full List of Ansi Escape Codes](https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797) that need to be handled.\n- [x] Normal text without ansi escape codes\n- [x] Colored text\n- [x] Cursor movement (Basic Support. Not tested)\n- [x] Erase Line/Screen Clear (Basic Support. Not tested)\n- [ ] Screen Modes (No Support)\n- [ ] Private Modes (No Support)\n- [ ] Multiple Arguments (No Support. Difficult to support this)\n\n\n\n----\n\nBig Shoutout to \n- [@fnky](https://github.com/fnky) for the [list of all ansi escape codes](https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797).\n\n- [@netzkolchose](https://github.com/netzkolchose) for [node-ansiterminal](https://github.com/netzkolchose/node-ansiterminal) library.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaurabhdaware%2Fcli-testing-tool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsaurabhdaware%2Fcli-testing-tool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaurabhdaware%2Fcli-testing-tool/lists"}