mocha-they

0.1.3 • Public • Published

Node.js mocha-they

Extends Mocha with a new they function replacing it. The goal is to execute the same test in multiple configuration environments.

This package was originally written to test ssh2-fs, ssh2-exec and Nikita. For example, in those packages, each test is run twice: the first time on a local environment and a second time on a remote environment with SSH.

Installation

This is OSS and licensed under the MIT license.

npm install mocha-fs

Usage

The package mocha-they exports a function. Call this function with an array of configuration to initialize it.

The configuration elements can be anything. When an an object, an optional label property can be provided to customized the message output.

It returns a new function which behave exactly like the it function in mocha. The only difference is the precence of the configuration element as the first argument of the test. Like with it, you can customize Mocha with the only and skip directives.

Example

The below example found inspiration in the Nikita execute action which execute a Shell command.

This test will connect to localhost with the current working user:

const should = require('should')
const fs = require('ssh2-fs')
const they = require('ssh2-they')([{
  label: 'local',
  ssh: null
}, {
  label: 'remote',
  ssh: {
    host: 'localhost',
    username: 'root',
    private_key_path: '~/.ssh/id_rsa'
  }
}])

describe('exists', function(){

  they('on file', function({ssh}){
    const {whoami} = await nikita({
      ssh: ssh
    }).execute('whoami')
    whoami.should.eql(
      !ssh ? require("os").userInfo().username : ssh.username
    )
  })

})

Contributors

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.1.3
    2
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.1.3
    2
  • 0.1.2
    0
  • 0.1.1
    0
  • 0.1.0
    0

Package Sidebar

Install

npm i mocha-they

Weekly Downloads

2

Version

0.1.3

License

MIT

Unpacked Size

9.11 kB

Total Files

9

Last publish

Collaborators

  • david