{"id":18576083,"url":"https://github.com/thiagodp/codeceptjs-cmdhelper","last_synced_at":"2025-04-10T08:31:01.326Z","repository":{"id":47048315,"uuid":"136822414","full_name":"thiagodp/codeceptjs-cmdhelper","owner":"thiagodp","description":"💻 Let your CodeceptJS tests run commands in the console/terminal","archived":false,"fork":false,"pushed_at":"2022-10-31T01:46:01.000Z","size":302,"stargazers_count":4,"open_issues_count":3,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T19:02:21.284Z","etag":null,"topics":["bdd","codeceptjs","command","console","execute","run","terminal","test","testing"],"latest_commit_sha":null,"homepage":"","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/thiagodp.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":"2018-06-10T15:48:40.000Z","updated_at":"2022-12-07T07:02:32.000Z","dependencies_parsed_at":"2023-01-20T10:34:49.344Z","dependency_job_id":null,"html_url":"https://github.com/thiagodp/codeceptjs-cmdhelper","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thiagodp%2Fcodeceptjs-cmdhelper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thiagodp%2Fcodeceptjs-cmdhelper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thiagodp%2Fcodeceptjs-cmdhelper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thiagodp%2Fcodeceptjs-cmdhelper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thiagodp","download_url":"https://codeload.github.com/thiagodp/codeceptjs-cmdhelper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247846714,"owners_count":21006088,"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":["bdd","codeceptjs","command","console","execute","run","terminal","test","testing"],"created_at":"2024-11-06T23:23:32.575Z","updated_at":"2025-04-10T08:31:00.976Z","avatar_url":"https://github.com/thiagodp.png","language":"JavaScript","readme":"# codeceptjs-cmdhelper\n\n[![npm version](https://badge.fury.io/js/codeceptjs-cmdhelper.svg)](https://badge.fury.io/js/codeceptjs-cmdhelper)\n[![Downloads](https://img.shields.io/npm/dt/codeceptjs-cmdhelper.svg)](https://npmjs.org/package/codeceptjs-cmdhelper)\n\n\u003e Let your CodeceptJS tests run commands in the console/terminal\n\nThis is a [Helper](https://codecept.io/helpers/) for [CodeceptJS](https://codecept.io/) that allows you to run commands in the console/terminal. **It is especially useful for preparing the execution environment before/after executing test cases.**\n\n👉 It works with CodeceptJS 1, 2, and 3.\n\n## Install\n\n```bash\nnpm i -D codeceptjs-cmdhelper\n```\n\n## Configure\n\nIn your configuration file (_e.g._, `codecept.conf.js`, `codecept.json`), include **CmdHelper** in the property **helpers** :\n\n```js\n  ...\n  \"helpers\": {\n    ...\n    \"CmdHelper\": {\n      \"require\": \"./node_modules/codeceptjs-cmdhelper\"\n    }\n  },\n  ...\n```\n\n### Options\n\nOptionally, you can set an `options` property with an object that accepts the same parameters as [NodeJS spawn](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options)'s, plus `showOutput: boolean`. The default value is `{ shell: true, showOutput: true }`.\n\nExample:\n\n```js\n  ...\n  \"helpers\": {\n    ...\n    \"CmdHelper\": {\n      \"require\": \"./node_modules/codeceptjs-cmdhelper\",\n      \"options\": {\n          \"showOutput\": false\n      },\n    }\n  },\n  ...\n```\n\n## Usage\n\n### Syntax differences between CodeceptJS 2 and CodeceptJS 3\nIn CodeceptJS 2, your callbacks receive `I` as argument:\n\n```javascript\nScenario('test something', async ( I ) =\u003e {   // CodeceptJS 2 notation\n   /* ... */\n} );\n```\n\nIn CodeceptJS 3, your callbacks receive an object with `I` - that is, `{ I }`:\n\n```javascript\nScenario('test something', async ( { I } ) =\u003e {   // CodeceptJS 3 notation\n   /* ... */\n} );\n```\n\nSee the [CodeceptJS docs](https://github.com/codeceptjs/CodeceptJS/wiki/Upgrading-to-CodeceptJS-3) for more information on how to upgrade your codebase.\n\n### Examples\n\n\u003e The following examples are written with **CodeceptJS 3**.\n\nNow the object `I` (of your callbacks) has [new methods](#api).\n\n\n#### Example 1\n\n```js\nBeforeSuite( async ( { I } ) =\u003e {\n    await I.runCommand( 'echo \"Hello world!\" \u003efoo.txt' );\n} );\n\nAfterSuite( async ( { I } ) =\u003e {\n    await I.runCommand( 'rm foo.txt' );\n    // await I.runCommand( 'del foo.txt' ); // on Windows\n} );\n\n// ... your feature ...\n\n// ... your scenarios ...\n```\n\n#### Example 2\n\n```js\nFeature( 'Foo' );\n\nScenario( 'Bar', async ( { I } ) =\u003e {\n    await I.runCommand( 'mkdir foo' );\n    await I.runCommand( 'mkdir bar', { showOutput: false } );\n} );\n```\n\n### Note\n\nMake sure to handle errors properly, with `try`..`catch`.\n\n```js\n    try {\n        const code = await I.runCommand( 'mkdir foo' );\n        console.log( 0 === code ? 'success' : 'some problem occurred' );\n    } catch ( e ) {\n        console.warn( e );\n    }\n```\n\n\n## API\n\n```js\n/**\n * Executes the given command.\n *\n * @param {string} command Command to execute.\n * @param {object} [options] Same options as in NodeJS' spawn(), plus `showOutput: boolean`. Optional. Default is `{ shell: true, showOutput: true }`.\n *\n * @returns {Promise\u003c number \u003e} Promise with the returning execution status code (0 means success).\n */\nrunCommand( command, options )\n```\n\n\n## See also\n\n[codeceptjs-dbhelper](https://github.com/thiagodp/codeceptjs-dbhelper) - Connect to databases and run SQL commands\n\n\n## License\n\nMIT © [Thiago Delgado Pinto](https://github.com/thiagodp)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthiagodp%2Fcodeceptjs-cmdhelper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthiagodp%2Fcodeceptjs-cmdhelper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthiagodp%2Fcodeceptjs-cmdhelper/lists"}