npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

codeceptjs-cmdhelper

v2.4.1

Published

Let your CodeceptJS tests run commands in the console/terminal

Downloads

8,887

Readme

codeceptjs-cmdhelper

npm version Downloads

Let your CodeceptJS tests run commands in the console/terminal

This is a Helper for CodeceptJS that allows you to run commands in the console/terminal. It is especially useful for preparing the execution environment before/after executing test cases.

👉 It works with CodeceptJS 1, 2, and 3.

Install

npm i -D codeceptjs-cmdhelper

Configure

In your configuration file (e.g., codecept.conf.js, codecept.json), include CmdHelper in the property helpers :

  ...
  "helpers": {
    ...
    "CmdHelper": {
      "require": "./node_modules/codeceptjs-cmdhelper"
    }
  },
  ...

Options

Optionally, you can set an options property with an object that accepts the same parameters as NodeJS spawn's, plus showOutput: boolean. The default value is { shell: true, showOutput: true }.

Example:

  ...
  "helpers": {
    ...
    "CmdHelper": {
      "require": "./node_modules/codeceptjs-cmdhelper",
      "options": {
          "showOutput": false
      },
    }
  },
  ...

Usage

Syntax differences between CodeceptJS 2 and CodeceptJS 3

In CodeceptJS 2, your callbacks receive I as argument:

Scenario('test something', async ( I ) => {   // CodeceptJS 2 notation
   /* ... */
} );

In CodeceptJS 3, your callbacks receive an object with I - that is, { I }:

Scenario('test something', async ( { I } ) => {   // CodeceptJS 3 notation
   /* ... */
} );

See the CodeceptJS docs for more information on how to upgrade your codebase.

Examples

The following examples are written with CodeceptJS 3.

Now the object I (of your callbacks) has new methods.

Example 1

BeforeSuite( async ( { I } ) => {
    await I.runCommand( 'echo "Hello world!" >foo.txt' );
} );

AfterSuite( async ( { I } ) => {
    await I.runCommand( 'rm foo.txt' );
    // await I.runCommand( 'del foo.txt' ); // on Windows
} );

// ... your feature ...

// ... your scenarios ...

Example 2

Feature( 'Foo' );

Scenario( 'Bar', async ( { I } ) => {
    await I.runCommand( 'mkdir foo' );
    await I.runCommand( 'mkdir bar', { showOutput: false } );
} );

Note

Make sure to handle errors properly, with try..catch.

    try {
        const code = await I.runCommand( 'mkdir foo' );
        console.log( 0 === code ? 'success' : 'some problem occurred' );
    } catch ( e ) {
        console.warn( e );
    }

API

/**
 * Executes the given command.
 *
 * @param {string} command Command to execute.
 * @param {object} [options] Same options as in NodeJS' spawn(), plus `showOutput: boolean`. Optional. Default is `{ shell: true, showOutput: true }`.
 *
 * @returns {Promise< number >} Promise with the returning execution status code (0 means success).
 */
runCommand( command, options )

See also

codeceptjs-dbhelper - Connect to databases and run SQL commands

License

MIT © Thiago Delgado Pinto