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

kaukau

v4.0.0

Published

JS test tools, Mocha wrapper

Downloads

40

Readme

kaukau

NodeJS test tools, Mocha wrapper.

Install

npm install kaukau --save-dev

Usage

CLI

Set up config file:

kaukau setup
kaukau setup --config kaukau-config.js
kaukau setup --config kaukau-config.js --file tests/

Run tests/:

kaukau --file tests/

Run custom config:

kaukau --config kaukau-config.js

Run tests/ with custom config:

kaukau start --config kaukau-config.js --file tests/

Other options are available.

Display help:

kaukau --help

Programmatically

Run:

const Kaukau = require('kaukau');
const config = require('./kaukau-config');

const kaukau = new Kaukau(config);

kaukau.run()
  // kaukau events
  .on('done', function(){ /* done testing */ })
  // mocha events (https://mochajs.org/api/runner)
  .on('test', function(test) {})
  .on('test end', function(test) {})
  .on('pass', function(test) {})
  .on('fail', function(test, err) {})
  .on('end', function() {});

Configuration

A JSON object with the following properties:

  • enableLogs: (boolean) Enable/disable kaukau logs. Default: true.

  • logLevel: (string) error, warn, info, verbose, debug, silly. Default: silly. Learn usage here.

  • exitOnFail: (boolean) Exit after a set of tests fails so it won't execute tests for the next sets of parameters if there are some. Default: false.

  • files: (string|string[]) Files and/or directories to be loaded for execution. Default: [].

  • ext: (string) File extensions to be loaded if files contains path to directories. Default: '.js'.

  • options: See mocha options there.

  • parameters: (object|object[]) Learn more about parameters option here.

Example:

{
  /* kaukau options */
  "enableLogs": true,
  "exitOnFail": false,
  "files": [], // Test files/directories to execute. (e.g.: [ "tests/test01.js" ])
  "options": {
    /* mocha options */
  },

  /* sets of parameters */
  "parameters": [
    {      
      "kaukauOptions":{
        /* Overwrite kaukau options */
      },
      "mochaOptions":{
        /* Overwrite mocha options */
      }
      /* custom parameters */
      // ...
    }
  ]  
}

Helpers

The following helpers come with kaukau.

Parameters

Usefull if you need to run the same tests with different parameters and options.

If you define sets of parameters in your configuration, the test scripts will be executed for each set. You can access parameters for the current set running as:

describe('test 01', function() {

  const { params } = this.ctx.kaukau;

  /**
   * In configuration:
   * parameters: [
   *  {
   *    host: "test.com",
   *    credentials: {
   *      email: "[email protected]"
   *    }
   *  }
   * ]
   */
  let host = params('host'); // "test.com"
  let email = params('credentials.email'); // "[email protected]"
});

Parameters can overwrite the main configuration by using the properties kaukauOptions and mochaOptions.

kaukauOptions can overwrite files and ext.

mochaOptions can overwrite all mocha options.

Logger

Logging utility.

describe('test 02', function() {

  const { logger } = this.ctx.kaukau;

  logger.silly('silly level');
  logger.debug('debug level');
  logger.log('verbose level');
  logger.info('info level');
  logger.warn('warn level');
  logger.error('error level');
});

Tester

Example:

// chai@4
const { expect } = require('chai');

describe('test 03', function() {

  const { params, tester } = this.ctx.kaukau;

  // set default options (axios.defaults)
  tester.setRequestDefaults({});
  
  // overwrite default options
  tester.updateRequestDefaults({});
  
  /* request */
  
  it('should be ok', async () => {
    const res = await tester.request({
      method: 'GET',
      url: params('host')
    });
    expect(res.status).to.equal(200);
  });
  
  // or
  
  tester.save({
    method: 'GET',
    url: params('host')
  });
  
  it('should be ok', function(){
    expect(this.err).to.equal(null);
    expect(this.res.status).to.equal(200);
  });
});

Learn more about the options for tester.request and tester.save at Axios Request Config.

Reference