1.0.0 • Published 4 months ago

@rmtc/plugin-mocha v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

@rmtc/plugin-mocha

A Mocha test running plugin for @rmtc/toolchain.

!WARNING This project is intended for use in @rowanmanning's projects. It's free to use but I don't offer support for use-cases outside of what I need.

Table of Contents

Requirements

This library requires the following to run:

Usage

Install the module with npm:

npm install --save-dev @rmtc/plugin-mocha

Include it in your .rmtc.json file:

{
    plugins: [
        // ...
        '@rmtc/plugin-mocha'
    ]
    // ...
}

Workflows

This plugin defines the following workflows:

  • test: a general workflow used to run all automated tests.

  • test:<type>: optionally (see config.type) more specific workflows for different types of automated tests.

Steps

This plugin defines the following steps that can be added to any workflow:

  • mocha: optionally (see config.type) a general step used to run any tests found in the project. This uses the following pattern to find test files:

    1. Look in all folders matching **/test/**
    2. Run tests in files that end in .spec.{js,cjs,mjs}
  • mocha:<type>: optionally (see config.type) a step used to run tests of a specific type found in the project. This uses the following pattern to find test files:

    1. Look in all folders matching **/test/<type>/**
    2. Run tests in files that end in .spec.{js,cjs,mjs}

Configuration

Most of the configuration for this plugin should live within the Mocha configuration file or package.json. See the Mocha documentation for more information.

config.type

string. Use this configuration to specify a different location to look for tests in, which in turn will define additional workflows and steps. E.g.

{
    plugins: [
        ['@rmtc/plugin-mocha', {
            type: 'unit'
        }]
    ]
}

The above will define two workflows (test and test:unit). It will define one step (mocha:unit), which will run tests inside **/test/unit/** folders in the project. The test workflow also runs the mocha:unit step.

Because the workflows and steps change, it's possible to add multiple different mocha plugin configurations this way, e.g.

{
    plugins: [
        ['@rmtc/plugin-mocha', {
            type: 'unit'
        }],
        ['@rmtc/plugin-mocha', {
            type: 'end-to-end'
        }]
    ]
}

The above will define three workflows (test, test:unit, and test:end-to-end). It will define two steps (mocha:unit and mocha:end-to-end), which will run tests inside their respective directories. The test workflow runs both the mocha:unit and mocha:end-to-end steps for convenience.

config.coverage

boolean. Whether to collect code coverage for the tests using Istanbul. If this is set to true then coverage will be collected and reported based on how you've configured nyc.

This configuration is useful when combined with type because you could report coverage only based on unit tests and not allow the end-to-end tests to impact this. E.g.

{
    plugins: [
        ['@rmtc/plugin-mocha', {
            type: 'unit',
            coverage: true
        }],
        ['@rmtc/plugin-mocha', {
            type: 'end-to-end'
        }]
    ]
}

Contributing

See the central README for a contribution guide and code of conduct.

License

Licensed under the MIT license. Copyright © 2023, Rowan Manning

1.0.0

4 months ago

0.3.1

4 months ago

0.3.0

4 months ago

0.2.5

5 months ago

0.2.4

5 months ago

0.2.3

5 months ago

0.2.2

5 months ago

0.2.1

5 months ago

0.2.0

5 months ago

0.1.1

5 months ago

0.1.0

5 months ago