Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 });
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);
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)
}
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();
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();
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();
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();
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
);
};
}
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);
}
};
}
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);
}
};