{"id":16329793,"url":"https://github.com/amilajack/joker","last_synced_at":"2025-10-25T21:31:13.329Z","repository":{"id":34184994,"uuid":"167885375","full_name":"amilajack/joker","owner":"amilajack","description":"A modern and intuitive testing library for command-line apps","archived":false,"fork":false,"pushed_at":"2022-03-26T14:22:41.000Z","size":707,"stargazers_count":4,"open_issues_count":14,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-09T17:09:13.257Z","etag":null,"topics":["cli","e2e","node","test","test-runner"],"latest_commit_sha":null,"homepage":"https://amilajack.github.io/joker/classes/runner","language":"TypeScript","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/amilajack.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"amilajack","patreon":"amilajack","paypal":"https://paypal.me/amilajack"}},"created_at":"2019-01-28T02:21:27.000Z","updated_at":"2023-11-23T02:32:46.000Z","dependencies_parsed_at":"2022-08-08T00:01:52.772Z","dependency_job_id":null,"html_url":"https://github.com/amilajack/joker","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amilajack%2Fjoker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amilajack%2Fjoker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amilajack%2Fjoker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amilajack%2Fjoker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amilajack","download_url":"https://codeload.github.com/amilajack/joker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238018659,"owners_count":19402754,"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","e2e","node","test","test-runner"],"created_at":"2024-10-10T23:17:17.380Z","updated_at":"2025-10-25T21:31:12.834Z","avatar_url":"https://github.com/amilajack.png","language":"TypeScript","funding_links":["https://github.com/sponsors/amilajack","https://patreon.com/amilajack","https://paypal.me/amilajack","https://www.patreon.com/amilajack"],"categories":["Rendering"],"sub_categories":["Testing"],"readme":"![logo](./logo.jpg)\n\n[![Build Status](https://dev.azure.com/amilajack/amilajack/_apis/build/status/amilajack.joker?branchName=master)](https://dev.azure.com/amilajack/amilajack/_build/latest?definitionId=1\u0026branchName=master)\n[![NPM version](https://img.shields.io/npm/v/@amilajack/joker.svg)](https://www.npmjs.com/package/@amilajack/joker)\n[![npm](https://img.shields.io/npm/dm/@amilajack/joker.svg)](https://npm-stat.com/charts.html?package=@amilajack/joker)\n[![codecov](https://codecov.io/gh/amilajack/joker/branch/master/graph/badge.svg)](https://codecov.io/gh/amilajack/joker)\n\nA modern and intuitive testing library for command-line apps\n\n## Installation\n\n```bash\nnpm install --save-dev @amilajack/joker\n```\n\n## How it looks\n\n```js\nconst path = require('path');\nconst assert = require('assert');\nconst { default: Joker } = require('@amilajack/joker');\n\n(async () =\u003e {\n  await new Joker()\n    .run('echo hello')\n    .expect((result) =\u003e {\n      assert(result.stdout === 'hello');\n    })\n    .code(0)\n    .end();\n})();\n```\n\n## API\n\nSee [full API docs](https://amilajack.github.io/joker/classes/runner)\n\n## Features\n\n### Formatting options\n\nJoker can strip new line characters and colors. You can tell it to do so by passing an\nobject that looks like this:\n\n```js\nconst options = {\n  colors: false,\n  newLines: false\n};\n\nnew Joker(options);\n```\n\n### Custom expectations\n\nWhile Joker comes with built-in expectations, you can use your own too.\n\n```js\nawait new Joker()\n  .run('unicorns')\n  .expect(result =\u003e {\n    if (result.stdout !== 'unicorns') {\n      return new Error('NO!');\n    }\n  })\n  .end();\n```\n\n### Custom middlewares\n\nYou can register as many before and after middlewares as you wish.\n\n```js\nawait new Joker()\n  .before(setupDatabase)\n  .before(runMigrations)\n  .run(cmd)\n  .after(downgradeCron)\n  .after(deleteDatabase)\n  .end();\n```\n\n### Middleware order\n\nThe Middleware execution order is very simple - \"before\" middlewares always run\nbefore everything else, \"after\" middlewares always run after everything else.\nThe other middlewares will match the order that you have specified.\n\n```js\nawait new Joker()\n  .before(before1)\n  .before(before2)\n  .after(after1)\n  .after(after2)\n  .writeFile(file, '')\n  .run(cmd)\n  .unlink(file)\n  .end();\n\n// Execution order:\n// before1, before2, writeFile, cmd, unlink, after1, after2\n```\n\n### Plugins\n\nJoker has primitive support for plugins. You can register any expectation or/and\nany middleware by calling `joker.register`.\n\n```js\nconst fn = () =\u003e {};\nnew Joker().register('foo', fn);\n```\n\nOr you may want to register many functions at once.\n\n```js\nconst fn = () =\u003e {};\nconst fn1 = () =\u003e {};\njoker.register({ baz: fn, bar: fn1 });\n```\n\n### Usage with a test runner\n\nJoker plays nice with any test runner out there.\n\n#### Jest\n\nHere is a minimal example how you could use it with [Jest](http://jestjs.io) using async/await:\n\n```js\ndescribe('todo add', () =\u003e {\n  it('adds a new todo item', async () =\u003e {\n    const result = await new Joker()\n      .run('todo add')\n      .stdout('A new todo has been added')\n      .end();\n    expect(result.stdout).toMatchSnapshot();\n  });\n});\n```\n\n#### Mocha\n\nHere is a minimal example how you could use it with [Mocha](http://mochajs.org) using callbacks:\n\n```js\ndescribe('todo add', () =\u003e {\n  it('adds a new todo item', done =\u003e {\n    new Joker()\n      .run('todo add')\n      .stdout('A new todo has been added')\n      .end(done);\n  });\n});\n```\n\n### Usage without a test runner\n\nWhile using a test runner is recommended Joker is completely 'nodeable'. Here is\na simple example how you could accomplish that:\n\n```js\nconst assert = require('assert');\n\nfunction refute(err) {\n  assert(!err);\n}\n\nnew Joker()\n  .run(cmd)\n  .end(refute);\n\nnew Joker()\n  .run(anotherCmd)\n  .end(refute);\n```\n\n### Responding to interactive prompts\n\nJoker can respond to apps that run interactively using the `on()` and\n`respond()` functions.\n\n```js\nawait new Joker()\n  .run(cmd)\n  .on('Your name: ')\n  .respond('Joe User\\n')\n  .end();\n```\n\nSee [`test/prompt.test.ts`](https://github.com/amilajack/joker/blob/master/tests/prompt.test.ts) for more examples.\n\n### Templates\n\nEvery `Joker` instance can be cloned, which allows you to build \"templates\" for tests. Here's some examples:\n\n```js\nconst template = new Joker()\n  .cwd(path.join(__dirname, 'fixtures'))\n  .run('echo test');\n\nconst test1 = await template\n  .clone()\n  .stdout(/test/)\n  .end();\n\nconst test2 = await template\n  .clone()\n  .stdout('test')\n  .end();\n```\n\n## Credits\n\nSpecial thanks to:\n\n- [Martin Lazarov](https://github.com/mlazarov)\n- [Radoslav Stankov](https://github.com/rstankov)\n\n## Support\n\nDo you like this project? Star the repository, spread the word - it really helps. You may want to follow\nme on [Twitter](https://twitter.com/amilajack) and\n[GitHub](https://github.com/amilajack). Thanks!\n\nIf this project is saving you (or your team) time, please consider supporting it on Patreon 👍 thank you!\n\n\u003cp\u003e\n  \u003ca href=\"https://www.patreon.com/amilajack\"\u003e\n    \u003cimg src=\"https://c5.patreon.com/external/logo/become_a_patron_button@2x.png\" width=\"160\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Familajack%2Fjoker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Familajack%2Fjoker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Familajack%2Fjoker/lists"}