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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@codeceptjs/configure

v1.0.1

Published

Set of CodeceptJS config hooks to simplify configuration

Downloads

748,286

Readme

CodeceptJS Configuration Hooks Build Status

Configuration hook helps you update CodeceptJS configuration at ease.

Those hooks are expected to simplify configuration for common use cases.

Requires CodeceptJS >= 2.3.3

Install it

npm i @codeceptjs/configure --save

How to use it

Better to see once.

Watch YouTube video

setHeadlessWhen

Toggle headless mode for Puppeteer, WebDriver, TestCafe and Playwright on condition.

Usage:

// in codecept.conf.js
const { setHeadlessWhen } = require('@codeceptjs/configure');

// enable headless when env var HEADLESS exists
// Use it like:
//
// export HEADLESS=true && npx codeceptjs run
setHeadlessWhen(process.env.HEADLESS); 

exports.config = {
  helpers: {
    // standard config goes here
    WebDriver: {} 
    // or Puppeteer
    // or TestCafe
  }
}
  • For Puppeteer, TestCafe, Playwright: it enables show: true.
  • For WebDriver with Chrome or Firefox browser: it adds --headless option to chrome/firefox options inside desiredCapabilities.

setHeadedWhen

Opposite to setHeadlessWhen. Forces window mode for running tests.

// in codecept.conf.js
const { setHeadlessWhen } = require('@codeceptjs/configure');

// enable window mode when env var DEV exists
// Use it like:
//
// export DEV=true && npx codeceptjs run
setHeadedWhen(process.env.DEV); 

setCommonPlugins

Enables CodeceptJS plugins which are recommened for common usage. The list of plugins can be updated from version to version so this hook ensures that all of them are loaded and you won't need to update them in a config:

// in codecept.conf.js
const { setCommonPlugins } = require('@codeceptjs/configure');

setCommonPlugins();

These plugins will be loaded:

  • tryTo (enabled globally)
  • retryFailedStep (enabled globally)
  • retryTo (enabled globally)
  • eachElement (enabled globally)
  • pauseOnFail (disabled, should be turned on when needed)
  • screenshotOnFail (enable globally)

setSharedCookies

Shares cookies between browser and REST/GraphQL helpers.

This hooks sets onRequest function for REST, GraphQL, ApiDataFactory, GraphQLDataFactory. This function obtains cookies from an active session in WebDriver or Puppeteer helpers.

// in codecept.conf.js
const { setSharedCookies } = require('@codeceptjs/configure');

// share cookies between browser helpers and REST/GraphQL
setSharedCookies();

exports.config = {
  helpers: {
    WebDriver: {
      // standard config goes here      
    },
    // or Puppeteer
    // or TestCafe,
    REST: {
      // standard config goes here      
      // onRequest: <= will be set by hook
    },
    ApiDataFactory: {
      // standard config goes here
      // onRequest: <= will be set by hook
    }
  }
}

setBrowser

Changes browser in config for Playwright, Puppeteer, WebDriver & TestCafe:

const { setBrowser } = require('@codeceptjs/configure');

setBrowser(process.env.BROWSER);

setWindowSize

Universal way to set a browser window size. For Puppeteer this launches Chrome browser with a specified width and height dimensions without changing viewport size.

Usage: setWindowSize(width, height).

// in codecept.conf.js
const { setWindowSize } = require('@codeceptjs/configure');

setWindowSize(1600, 1200);

exports.config = {
  helpers: {
    Puppeteer: {}
  }
}

setTestHost

Changes url in config for Playwright, Puppeteer, WebDriver & TestCafe:

const { setTestHost } = require('@codeceptjs/configure');

setTestHost(process.env.TEST_HOST);

Contributing

Please send your config hooks!

If you feel that codecept.conf.js becomes too complicated, and you know how to make it simpler, send a pull request with a config hook to solve your case.

Good ideas for config hooks:

  • Setting the same window size for all browser helpers.
  • Configuring run-multiple
  • Changing browser in WebDriver or Protractor depending on environment variable.

To create a custom hook follow this rules.

  1. Create a file starting with prefix use in hooks directory.
  2. Create a js module that exports a function.
  3. Require config object from codeceptjs package.
  4. Use config.addHook((config) => {}) to set a hook for configuration
  5. Add a test to index.test.js
  6. Run npm run test

See current hooks as examples.