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

babel-plugin-rewire-ignore-coverage

v2.0.2

Published

disable instanbul coverage on rewire injection by adding comments

Downloads

498

Readme

babel-plugin-rewire-ignore-coverage

This plugin disables rewire injected methods from istanbul coverage counts.

We get ES6/7 syntax and JSX transpiling out of the box with babel-loader (webpack module). The rewire plugin to babel is used to mock out other components when unit testing a component. The rewiring injects some code (setters/getters/resetters) when the system under test accesses the other dependent mocked components. The coverage sweep reported those injected methods as not covered by tests. This new babel-plugin-rewire-ignore-coverage plugin marks those injected code functions to be ignored by istanbul, after the rewiring

Works with Babel 6.x

Example

In

 

function _get__(variableName) {
    if (_RewiredData__ === undefined || _RewiredData__[variableName] === undefined) {
        return _get_original__(variableName);
    } else {
        var value = _RewiredData__[variableName];

        if (value === INTENTIONAL_UNDEFINED) {
            return undefined;
        } else {
            return value;
        }
    }
}

function _get_original__(variableName) {
    switch (variableName) {
    case 'React':
        return _react2.default;
    }

    return undefined;
}

function _assign__(variableName, value) {
    if (_RewiredData__ === undefined || _RewiredData__[variableName] === undefined) {
        return _set_original__(variableName, value);
    } else {
        return _RewiredData__[variableName] = value;
    }
}

function _set_original__(variableName, _value) {
    switch (variableName) {}

    return undefined;
}

function _update_operation__(operation, variableName, prefix) {
    var oldValue = _get__(variableName);

    var newValue = operation === '++' ? oldValue + 1 : oldValue - 1;

    _assign__(variableName, newValue);

    return prefix ? newValue : oldValue;
}

function _set__(variableName, value) {
    if ((typeof variableName === 'undefined' ? 'undefined' : _typeof(variableName)) === 'object') {
        Object.keys(variableName).forEach(function(name) {
            _RewiredData__[name] = variableName[name];
        });
    } else {
        if (value === undefined) {
            _RewiredData__[variableName] = INTENTIONAL_UNDEFINED;
        } else {
            _RewiredData__[variableName] = value;
        }

        return function() {
            _reset__(variableName);
        };
    }
}

function _reset__(variableName) {
    delete _RewiredData__[variableName];
}

function _with__(object) {
    var rewiredVariableNames = Object.keys(object);
    var previousValues = {};

    function reset() {
        rewiredVariableNames.forEach(function(variableName) {
            _RewiredData__[variableName] = previousValues[variableName];
        });
    }

    return function(callback) {
        rewiredVariableNames.forEach(function(variableName) {
            previousValues[variableName] = _RewiredData__[variableName];
            _RewiredData__[variableName] = object[variableName];
        });
        var result = callback();

        if (!!result && typeof result.then === 'function') {
            result.then(reset).catch(reset);
        } else {
            reset();
        }

        return result;
    };
}

Out

// istanbul ignore next
function _get__(variableName) {
    if (_RewiredData__ === undefined || _RewiredData__[variableName] === undefined) {
        return _get_original__(variableName);
    } else {
        var value = _RewiredData__[variableName];

        if (value === INTENTIONAL_UNDEFINED) {
            return undefined;
        } else {
            return value;
        }
    }
}

// istanbul ignore next
function _get_original__(variableName) {
    switch (variableName) {
    case 'React':
        return _react2.default;
    }

    return undefined;
}

// istanbul ignore next
function _assign__(variableName, value) {
    if (_RewiredData__ === undefined || _RewiredData__[variableName] === undefined) {
        return _set_original__(variableName, value);
    } else {
        return _RewiredData__[variableName] = value;
    }
}

// istanbul ignore next
function _set_original__(variableName, _value) {
    switch (variableName) {}

    return undefined;
}

// istanbul ignore next
function _update_operation__(operation, variableName, prefix) {
    var oldValue = _get__(variableName);

    var newValue = operation === '++' ? oldValue + 1 : oldValue - 1;

    _assign__(variableName, newValue);

    return prefix ? newValue : oldValue;
}

// istanbul ignore next
function _set__(variableName, value) {
    if ((typeof variableName === 'undefined' ? 'undefined' : _typeof(variableName)) === 'object') {
        Object.keys(variableName).forEach(function(name) {
            _RewiredData__[name] = variableName[name];
        });
    } else {
        if (value === undefined) {
            _RewiredData__[variableName] = INTENTIONAL_UNDEFINED;
        } else {
            _RewiredData__[variableName] = value;
        }

        return function() {
            _reset__(variableName);
        };
    }
}

// istanbul ignore next
function _reset__(variableName) {
    delete _RewiredData__[variableName];
}

// istanbul ignore next
function _with__(object) {
    var rewiredVariableNames = Object.keys(object);
    var previousValues = {};

    function reset() {
        rewiredVariableNames.forEach(function(variableName) {
            _RewiredData__[variableName] = previousValues[variableName];
        });
    }

    return function(callback) {
        rewiredVariableNames.forEach(function(variableName) {
            previousValues[variableName] = _RewiredData__[variableName];
            _RewiredData__[variableName] = object[variableName];
        });
        var result = callback();

        if (!!result && typeof result.then === 'function') {
            result.then(reset).catch(reset);
        } else {
            reset();
        }

        return result;
    };
}

Installation

$ npm install babel-plugin-rewire-ignore-coverage

Usage

Via .babelrc (Recommended)

.babelrc

{
  "plugins": ["rewire", "rewire-ignore-coverage"]
}

Via CLI

$ babel --plugins rewire-ignore-coverage  script.js

Via Node API

require("babel-core").transform("code", {
  plugins: ["rewire-ignore-coverage"]
});

Via Karma config

       webpack: {
            devtool: "source-map",
            module: {
                loaders: [
                    {
                        // all js src and test files get treated by babel
                        test: /\.js?$/,
                        include: [
                            path.resolve(__dirname, "client/src"),
                            path.resolve(__dirname, "client/test")
                        ],
                        exclude: [nodeModulesPath],
                        loader: "babel-loader",
                        query: {
                            plugins: ['babel-plugin-rewire', 
                                      'babel-plugin-rewire-ignore-coverage']
                        }
                    },