How to use istanbul-lib-hook - 10 common examples

To help you get started, we’ve selected a few istanbul-lib-hook examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / types / istanbul-lib-hook / istanbul-lib-hook-tests.ts View on Github external
import {
	hookRequire,
	hookCreateScript,
	unhookCreateScript,
	hookRunInThisContext,
	unhookRunInThisContext,
	hookRunInContext,
	unhookRunInContext,
	unloadRequireCache
} from 'istanbul-lib-hook';

const matcher = (filename: string) => true;
const transformer = (code: string, options: { filename: string }) => 'foo';

hookRequire(matcher, transformer);
hookRequire(matcher, transformer, {});
hookRequire(matcher, transformer, { verbose: true });

const retVal = hookRequire(matcher, transformer, {
	extensions: ['.js'],
	postLoadHook: (filename: string) => {}
});
retVal();

hookCreateScript(matcher, transformer, {});
hookCreateScript(matcher, transformer, { verbose: true });

unhookCreateScript();

hookRunInThisContext(matcher, transformer, {});
hookRunInThisContext(matcher, transformer, { verbose: true });
github DefinitelyTyped / DefinitelyTyped / types / istanbul-lib-hook / istanbul-lib-hook-tests.ts View on Github external
unhookCreateScript,
	hookRunInThisContext,
	unhookRunInThisContext,
	hookRunInContext,
	unhookRunInContext,
	unloadRequireCache
} from 'istanbul-lib-hook';

const matcher = (filename: string) => true;
const transformer = (code: string, options: { filename: string }) => 'foo';

hookRequire(matcher, transformer);
hookRequire(matcher, transformer, {});
hookRequire(matcher, transformer, { verbose: true });

const retVal = hookRequire(matcher, transformer, {
	extensions: ['.js'],
	postLoadHook: (filename: string) => {}
});
retVal();

hookCreateScript(matcher, transformer, {});
hookCreateScript(matcher, transformer, { verbose: true });

unhookCreateScript();

hookRunInThisContext(matcher, transformer, {});
hookRunInThisContext(matcher, transformer, { verbose: true });

unhookRunInThisContext();

unloadRequireCache(matcher);
github imodeljs / imodeljs / test-apps / testbed / coverage.js View on Github external
const customOpts = {
  includeAllSources: true
};

const instrumenter = createInstrumenter(customOpts)
const transformer = instrumenter.instrumentSync.bind(instrumenter)
const cov = global.__coverage__ = {}

const tmpd = resolve(__dirname, '.nyc_output')
if (!fs.existsSync(tmpd)) {
  fs.mkdirSync(tmpd)
}

const matched = match()

hookRequire(matched, transformer, {})

if (process.type === 'browser') {
  process.on('exit', report)
} else {
  window.addEventListener('unload', report)
}
github DefinitelyTyped / DefinitelyTyped / types / istanbul-lib-hook / istanbul-lib-hook-tests.ts View on Github external
retVal();

hookCreateScript(matcher, transformer, {});
hookCreateScript(matcher, transformer, { verbose: true });

unhookCreateScript();

hookRunInThisContext(matcher, transformer, {});
hookRunInThisContext(matcher, transformer, { verbose: true });

unhookRunInThisContext();

unloadRequireCache(matcher);

hookRunInContext(matcher, transformer, {});
hookRunInContext(matcher, transformer, { verbose: true, coverageVariable: '__cov__' });

unhookRunInContext();
github DefinitelyTyped / DefinitelyTyped / types / istanbul-lib-hook / istanbul-lib-hook-tests.ts View on Github external
hookRequire(matcher, transformer, {});
hookRequire(matcher, transformer, { verbose: true });

const retVal = hookRequire(matcher, transformer, {
	extensions: ['.js'],
	postLoadHook: (filename: string) => {}
});
retVal();

hookCreateScript(matcher, transformer, {});
hookCreateScript(matcher, transformer, { verbose: true });

unhookCreateScript();

hookRunInThisContext(matcher, transformer, {});
hookRunInThisContext(matcher, transformer, { verbose: true });

unhookRunInThisContext();

unloadRequireCache(matcher);

hookRunInContext(matcher, transformer, {});
hookRunInContext(matcher, transformer, { verbose: true, coverageVariable: '__cov__' });

unhookRunInContext();
github DefinitelyTyped / DefinitelyTyped / types / istanbul-lib-hook / istanbul-lib-hook-tests.ts View on Github external
extensions: ['.js'],
	postLoadHook: (filename: string) => {}
});
retVal();

hookCreateScript(matcher, transformer, {});
hookCreateScript(matcher, transformer, { verbose: true });

unhookCreateScript();

hookRunInThisContext(matcher, transformer, {});
hookRunInThisContext(matcher, transformer, { verbose: true });

unhookRunInThisContext();

unloadRequireCache(matcher);

hookRunInContext(matcher, transformer, {});
hookRunInContext(matcher, transformer, { verbose: true, coverageVariable: '__cov__' });

unhookRunInContext();
github DefinitelyTyped / DefinitelyTyped / types / istanbul-lib-hook / istanbul-lib-hook-tests.ts View on Github external
const matcher = (filename: string) => true;
const transformer = (code: string, options: { filename: string }) => 'foo';

hookRequire(matcher, transformer);
hookRequire(matcher, transformer, {});
hookRequire(matcher, transformer, { verbose: true });

const retVal = hookRequire(matcher, transformer, {
	extensions: ['.js'],
	postLoadHook: (filename: string) => {}
});
retVal();

hookCreateScript(matcher, transformer, {});
hookCreateScript(matcher, transformer, { verbose: true });

unhookCreateScript();

hookRunInThisContext(matcher, transformer, {});
hookRunInThisContext(matcher, transformer, { verbose: true });

unhookRunInThisContext();

unloadRequireCache(matcher);

hookRunInContext(matcher, transformer, {});
hookRunInContext(matcher, transformer, { verbose: true, coverageVariable: '__cov__' });

unhookRunInContext();
github laggingreflex / mochista / istanbul / instrument / index.js View on Github external
module.exports = function instrument ({
  root,
  coverageVariable,
  transformerCacheVariable,
  sourceMapCacheVariable,
  cacheDir,
  files,
  preserveComments = true,
  extensions = ['.js'],
  verbose = 0
} = {}) {
  global[coverageVariable] = global[coverageVariable] || {};

  const hookOpts = { extensions, verbose: verbose > 3 };
  hookRequire(
    matcher({ files }),
    transformer({ root, coverageVariable, transformerCacheVariable, sourceMapCacheVariable, cacheDir, verbose }),
    hookOpts
  );
};
github flaviuse / mern-authentication / client / node_modules / istanbul-api / lib / run-cover.js View on Github external
}
        if (config.hooks.hookRunInThisContext()) {
            hook.hookRunInThisContext(
                matchFn,
                runInThisContextTransformer,
                hookOpts
            );
            if (compareVersions(process.versions.node, '6.0.0') === -1) {
                disabler = hook.hookRequire(
                    matchFn,
                    requireTransformer,
                    hookOpts
                );
            }
        } else {
            disabler = hook.hookRequire(matchFn, requireTransformer, hookOpts);
        }
    };
github istanbuljs / istanbuljs / packages / istanbul-api / lib / run-cover.js View on Github external
}
        if (config.hooks.hookRunInThisContext()) {
            hook.hookRunInThisContext(
                matchFn,
                runInThisContextTransformer,
                hookOpts
            );
            if (compareVersions(process.versions.node, '6.0.0') === -1) {
                disabler = hook.hookRequire(
                    matchFn,
                    requireTransformer,
                    hookOpts
                );
            }
        } else {
            disabler = hook.hookRequire(matchFn, requireTransformer, hookOpts);
        }
    };