{"id":19008283,"url":"https://github.com/jamesgeorge007/cli-prompts-test","last_synced_at":"2025-04-22T20:26:04.288Z","repository":{"id":40754269,"uuid":"289475839","full_name":"jamesgeorge007/cli-prompts-test","owner":"jamesgeorge007","description":"Write e2e tests for CLI apps with ease","archived":false,"fork":false,"pushed_at":"2023-01-06T13:51:10.000Z","size":469,"stargazers_count":21,"open_issues_count":4,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-13T19:14:38.274Z","etag":null,"topics":["cli-apps","command-line","commanderjs","e2e-tests","enquirer","hacktoberfest","hacktoberfest2020","inquirer","integration-testing","javascript","nodejs","test","yargs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jamesgeorge007.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":"2020-08-22T11:33:31.000Z","updated_at":"2024-05-02T11:59:02.000Z","dependencies_parsed_at":"2023-02-06T04:46:17.722Z","dependency_job_id":null,"html_url":"https://github.com/jamesgeorge007/cli-prompts-test","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesgeorge007%2Fcli-prompts-test","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesgeorge007%2Fcli-prompts-test/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesgeorge007%2Fcli-prompts-test/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesgeorge007%2Fcli-prompts-test/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jamesgeorge007","download_url":"https://codeload.github.com/jamesgeorge007/cli-prompts-test/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250317462,"owners_count":21410753,"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":["cli-apps","command-line","commanderjs","e2e-tests","enquirer","hacktoberfest","hacktoberfest2020","inquirer","integration-testing","javascript","nodejs","test","yargs"],"created_at":"2024-11-08T18:42:06.644Z","updated_at":"2025-04-22T20:26:04.255Z","avatar_url":"https://github.com/jamesgeorge007.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CLI Prompts Test\n\n\u003e Write e2e tests for CLI apps with ease.\n\n## Installation\n\n```bash\n$ npm install --save-dev cli-prompts-test\n```\n\n## API\n\n### runTest(args, answers, options?)\n\n- `args`: CLI args to pass in.\n- `answers`: answers to be passed to `stdout` (simulate user input).\n- `options`: Optionally specify the `testPath` (defaults to `process.cwd()`) and `timeout` (defaults to `500ms`) between keystrokes.\n\n## Usage\n\n```js\n// cli.js\n\nconst enquirer = require(\"enquirer\");\n\nconst choices = [\"First option\", \"Second option\", \"Third option\"];\n\nenquirer\n  .prompt({\n    type: \"select\",\n    name: \"option\",\n    message: \"Choose from below\",\n    choices,\n  })\n  .then(({ option }) =\u003e {\n    console.log(`You chose ${option}`);\n  });\n```\n\n```js\n// test.js\n\nimport runTest, { DOWN, ENTER } from \"cli-prompts-test\";\n\nconst cliPath = `${__dirname}/cli.js`;\n\ndescribe(\"cli-prompts-test\", () =\u003e {\n  it(\"picks first option\", async () =\u003e {\n    const { exitCode, stdout } = await runTest([cliPath], [ENTER]);\n\n    // Assertions\n    expect(exitCode).toBe(0);\n    expect(stdout).toContain(\"You chose First option\");\n  });\n\n  it(\"picks second option\", async () =\u003e {\n    const { exitCode, stdout } = await runTest([cliPath], [`${DOWN}${ENTER}`]);\n\n    // Assertions\n    expect(exitCode).toBe(0);\n    expect(stdout).toContain(\"You chose Second option\");\n  });\n\n  it(\"picks third option\", async () =\u003e {\n    const { exitCode, stdout } = await runTest(\n      [cliPath],\n      [`${DOWN}${DOWN}${ENTER}`]\n    );\n\n    // Assertions\n    expect(exitCode).toBe(0);\n    expect(stdout).toContain(\"You chose Third option\");\n  });\n});\n```\n\nFind an example [here](https://github.com/madlabsinc/mevn-cli/blob/develop/jest/helpers.js).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamesgeorge007%2Fcli-prompts-test","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjamesgeorge007%2Fcli-prompts-test","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamesgeorge007%2Fcli-prompts-test/lists"}