felixge / node-sandboxed-module

A sandboxed node.js module loader that lets you inject dependencies into your modules.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Istanbul source transformer and node_modules

elliotstokes opened this issue · comments

I have been using the Istanbul source transformer and it works great. I have a small issue though that it doesn't ignore the node_modules folder and am getting code_coverage for these (i.e. underscore). I have written a work-around to get around this locally. Could we get this or someway to ignore files and paths included?

Will happily send you a push request if you think its worth it.

I have the same issue here, any chance for a pull request?

You should be able to use sourceTransformersSingleOnly instead of sourceTransformers to get this behavior. Let me know if that works; if it doesn't then we have a bug.

Yep, works when using sourceTransformersSingleOnly.

Awesome!

Could you be so kind to document this option? Finding it in a closed issue is not that ideal...

Edit: scratch that, its already there

I'm too quick today. After more testing, I do not understand how this is supposed to work. Consider this jasmine clause:

    var stdin, utils, spawn, iconize;
    var spawnLineFn, normalizeCallbacks = {};

    beforeEach(function () {
        stdin = {
            write: jasmine.createSpy('write')
        };
        utils = {
            normalize: function (fn, callback) {
                normalizeCallbacks[fn] = callback;
            },
            handleErr: jasmine.createSpy('handleErr')
        };
        spyOn(utils, 'normalize').and.callThrough();
        spawn = jasmine.createSpy('spawn')
                .and.callFake(function (cmd, lineFn) {
            spawnLineFn = lineFn;
            return stdin;
        });
        iconize = SandboxedModule.require('../../lib/iconize-png.js', {
            requires: { './utils': utils, './spawn': spawn },
            globals: { 'console': { log: () => {} } }
        });
    });

The tested module has an additional require('async'), it will be included in coverage if used like this.

Adding sourceTransformersSingleOnly: true does not change this, it is still in the results.

Adding singleOnly: true leads to the spec failing, because the mocks are not available.

Requiring async in the spec and adding it to the requires:

var async = require('async');
//...
            requires: { 'async': async, './utils': utils, './spawn': spawn },

excludes async from coverage.