{"id":19994201,"url":"https://github.com/b4dnewz/process-test","last_synced_at":"2025-07-26T00:39:00.449Z","repository":{"id":35049221,"uuid":"200655105","full_name":"b4dnewz/process-test","owner":"b4dnewz","description":"Easy way to test command line applications","archived":false,"fork":false,"pushed_at":"2023-01-04T06:19:44.000Z","size":712,"stargazers_count":1,"open_issues_count":15,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-12T16:48:11.262Z","etag":null,"topics":["child-process","cli-testing","cli-utilities","fork","spawn","test","testing","testing-tools"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/b4dnewz.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":"2019-08-05T12:53:39.000Z","updated_at":"2024-02-06T13:09:03.000Z","dependencies_parsed_at":"2023-01-15T12:45:13.047Z","dependency_job_id":null,"html_url":"https://github.com/b4dnewz/process-test","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b4dnewz%2Fprocess-test","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b4dnewz%2Fprocess-test/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b4dnewz%2Fprocess-test/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b4dnewz%2Fprocess-test/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/b4dnewz","download_url":"https://codeload.github.com/b4dnewz/process-test/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241435151,"owners_count":19962401,"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":["child-process","cli-testing","cli-utilities","fork","spawn","test","testing","testing-tools"],"created_at":"2024-11-13T04:54:19.407Z","updated_at":"2025-03-01T22:50:23.544Z","avatar_url":"https://github.com/b4dnewz.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# process-test\n\n\u003e Easy way to test command line applications\n\n[![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coverage percentage][coveralls-image]][coveralls-url]\n\nThis project is mainly based on [coffee](https://github.com/node-modules/coffee) but implemented in TypeScript with no dependencies.\n\n## Install\n\n```\nnpm install @b4dnewz/process-test\n```\n\n## Usage\n\nYou can use it in your tests with any framework to test your code execution:\n\n```ts\nimport {fork, spawn} from \"@b4dnewz/process-test\"\n\n// Spawn a nodejs process\nit(\"will spawn node script\", (done) =\u003e {\n  fork(\"./test.js\", [\"foo\", \"bar\"], {})\n    .expect(\"stdout\", /foo bar/)\n    .expect(\"code\", 0)\n    .end(done);\n})\n\n// Spawn a system command\nit(\"will spawn system command\", (done) =\u003e {\n  spawn(\"node\", [\"--version\"], {})\n    .expect(\"stdout\", process.version)\n    .expect(\"code\", 0)\n    .end(done);\n})\n```\n\nFile used in usage example _test.js_\n\n```js\n#!/usr/bin/env node\n\nconst argv = process.argv.slice(2).join(\" \")\nprocess.stdout.write(argv);\n```\n\n## API\n\n#### fork\n\nThis method is used specifically to spawn new Node.js process using the given file path, arguments and [options](https://nodejs.org/api/child_process.html#child_process_child_process_fork_modulepath_args_options).\n\n```js\n// fork(binPath)\nfork(\"./test.js\")\n\n// fork(binPath, args)\nfork(\"./test.js\", [\"--foo\", \"bar\"])\n\n// fork(binPath, args, options)\nfork(\"./test.js\", [\"foo\"], { env: {} })\n```\n\n#### spawn\n\nThis method spawns a new process using the given command, arguments and [options](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options).\n\n```js\n// spawn(binPath)\nspawn(\"node\")\n\n// spawn(binPath, args)\nspawn(\"node\", [\"--version\"])\n\n// spawn(binPath, args, options)\nspawn(\"ls\", [\"-l\"], {\n  cwd: \"/home\"\n})\n```\n\nAll the methods returns a test Process class which has the following method to interact with the process and the result:\n\n#### expect(type, expectation)\n\nThis method is used to set an expectation of the process result.\n\n```js\nspawn(\"node\", [\"--version\"])\n  .expect(\"stdout\", new RegExp(process.version))\n  .expect(\"code\", 0);\n```\n\n#### notExpect(type, expectation)\n\nThis method is used to set an expectation of the process result.\n\n```js\nspawn(\"node\", [\"--version\"])\n  .notExpect(\"code\", 1);\n```\n\n---\n\n## License\n\nMIT © [Filippo Conti](https://b4dnewz.github.io/)\n\n[npm-image]: https://badge.fury.io/js/%40b4dnewz%2Fprocess-test.svg\n[npm-url]: https://npmjs.org/package/@b4dnewz/process-test\n[travis-image]: https://travis-ci.org/b4dnewz/process-test.svg?branch=master\n[travis-url]: https://travis-ci.org/b4dnewz/process-test\n[coveralls-image]: https://coveralls.io/repos/b4dnewz/process-test/badge.svg\n[coveralls-url]: https://coveralls.io/r/b4dnewz/process-test\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fb4dnewz%2Fprocess-test","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fb4dnewz%2Fprocess-test","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fb4dnewz%2Fprocess-test/lists"}