How to use the istanbul-lib-source-maps.createSourceMapStore function in istanbul-lib-source-maps

To help you get started, we’ve selected a few istanbul-lib-source-maps 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-source-maps / istanbul-lib-source-maps-tests.ts View on Github external
import { createSourceMapStore } from 'istanbul-lib-source-maps';
import { CoverageMap } from 'istanbul-lib-coverage';
import { RawSourceMap } from 'source-map';

createSourceMapStore();
createSourceMapStore({});
const store = createSourceMapStore({
	verbose: false,
	baseDir: 'foo',
	sourceStore: 'memory',
	tmpdir: 'foo'
});

store.data['foo'].type.trim();

const sourceMap: RawSourceMap = {
	version: 1 as any as string, // Fixed by https://github.com/mozilla/source-map/pull/293 but the fix is not yet published
	sources: ['foo', 'bar'],
	names: ['foo', 'bar'],
	mappings: 'foo',
	file: 'foo'
};
store.registerMap('foo', sourceMap);
github istanbuljs / istanbuljs / packages / istanbul-api / lib / run-cover.js View on Github external
callback = includes;
        includes = null;
    }

    const includePid = config.instrumentation.includePid();
    const reportingDir = path.resolve(config.reporting.dir());
    const reporter = new Reporter(config);
    const excludes = config.instrumentation.excludes(true);
    // The coverage variable below should have different value than
    // that of the coverage variable actually used by the instrumenter (in this case: __coverage__).
    // Otherwise if you run nyc to provide coverage on these files,
    // both the actual instrumenter and this file will write to the global coverage variable,
    // and provide unexpected coverage result.
    const coverageVar = '$$coverage$$';
    const instOpts = config.instrumentation.getInstrumenterOpts();
    const sourceMapStore = libSourceMaps.createSourceMapStore({});
    let fakeRequire;

    instOpts.coverageVariable = coverageVar;
    instOpts.sourceMapUrlCallback = function(file, url) {
        sourceMapStore.registerURL(file, url);
    };
    const coverageFinderFn = function() {
        return global[coverageVar];
    };
    const instrumenter = libInstrument.createInstrumenter(instOpts);
    const transformer = function(code, options) {
        const filename =
            typeof options === 'string' ? options : options.filename;
        return instrumenter.instrumentSync(code, filename);
    };
    const runInContextTransformer = function(code, options) {
github SonarSource / sonarlint-vscode / test / coverage.ts View on Github external
export function createReport(): void {
  const iLibCoverage = require('istanbul-lib-coverage');
  const iLibSourceMaps = require('istanbul-lib-source-maps');
  const iLibReport = require('istanbul-lib-report');
  const iReports = require('istanbul-reports');

  const global = new Function('return this')();

  const mapStore = iLibSourceMaps.createSourceMapStore();
  const coverageMap = iLibCoverage.createCoverageMap(global.__coverage__);
  const transformed = mapStore.transformCoverage(coverageMap);

  const tree = iLibReport.summarizers.flat(transformed.map);
  const context = iLibReport.createContext({
    dir: path.resolve(REPO_ROOT, `coverage`)
  });

  const reports = [iReports.create('lcov')];
  reports.forEach(report => tree.visit(report, context));
}
github streamlink / streamlink-twitch-gui / build / tasks / common / cdp / coverage.js View on Github external
function processCoverage( report ) {
		grunt.log.ok( "Processing coverage data..." );

		const dir = grunt.config( "dir.tmp_coverage" );
		const watermarks = grunt.config( "coverage.watermarks" );
		const reporters = grunt.config( "coverage.reporters" );

		const libCoverage = require( "istanbul-lib-coverage" );
		const libReport = require( "istanbul-lib-report" );
		const libSourceMaps = require( "istanbul-lib-source-maps" );
		const reports = require( "istanbul-reports" );

		const map = libCoverage.createCoverageMap( report );
		const sourceMapCache = libSourceMaps.createSourceMapStore();
		map.data = sourceMapCache.transformCoverage(
			libCoverage.createCoverageMap( map.data )
		).map.data;
		const tree = libReport.summarizers.pkg( map );
		const context = libReport.createContext({ dir, watermarks });

		reporters.forEach( ({ name, options }) => {
			const report = reports.create( name, options );
			tree.visit( report, context );
			grunt.log.ok( `Coverage reporter run: ${name}` );
		});
	}
github Raathigesh / majestic / server / services / results.ts View on Github external
public mapCoverage(data: any) {
    if (!data) {
      this.coverage = {
        statement: 0,
        branch: 0,
        function: 0,
        line: 0
      };

      return;
    }

    const sourceMapStore = createSourceMapStore();
    const coverageMap = createCoverageMap(data);
    const transformed = sourceMapStore.transformCoverage(coverageMap);
    const coverageSummary = transformed.map.getCoverageSummary();

    const statementCoverage = coverageSummary.statements.pct as any;
    const branchCoverage = coverageSummary.branches.pct as any;
    const functionCoverage = coverageSummary.functions.pct as any;
    const lineCoverage = coverageSummary.lines.pct as any;

    this.coverage = {
      statement: statementCoverage === "Unknown" ? 0 : statementCoverage,
      branch: branchCoverage === "Unknown" ? 0 : branchCoverage,
      function: functionCoverage === "Unknown" ? 0 : functionCoverage,
      line: lineCoverage === "Unknown" ? 0 : lineCoverage
    };
  }
github Raathigesh / majestic / app / src / core / ui / stores / CoverageSummary.ts View on Github external
constructor() {
    this.sourceMapStore = createSourceMapStore();
    this.transformedCoverageMap = createCoverageMap();
  }
github chialab / rna-cli / lib / TestRunners / TestRunner.js View on Github external
async reportCoverage(coverageReport, environment) {
        this.coverageMap.merge(coverageReport);
        const coverageMap = createCoverageMap(coverageReport);
        const remappedCoverageMap = await createSourceMapStore().transformCoverage(coverageMap);
        const reportDir = this.coverageDir.directory(environment);
        const context = createContext({
            dir: reportDir.path,
            watermarks: getDefaultWatermarks(),
            coverageMap: remappedCoverageMap,
        });
        createReporter('html').execute(context);
        createReporter('lcovonly').execute(context);
    }
}
github Raathigesh / majestic / app / src / renderer / stores / Coverage.ts View on Github external
constructor(rootPath: string) {
    this.sourceMapStore = createSourceMapStore();
    this.transformedCoverageMap = createCoverageMap();
  }
github laggingreflex / mochista / istanbul / instrument / transformer.js View on Github external
module.exports = function createTransformerFn ({
  root,
  coverageVariable,
  transformerCacheVariable,
  sourceMapCacheVariable,
  cacheDir,
  disableCache = false,
  ext = '.js',
  verbose = false
}) {
  const transformerCache = global[transformerCacheVariable] = global[transformerCacheVariable] || {};
  const sourceMapCache = global[sourceMapCacheVariable] = global[sourceMapCacheVariable] || createSourceMapStore();

  const instrumenter = createInstrumenter({
    autoWrap: true,
    coverageVariable,
    embedSource: true,
    noCompact: true,
    preserveComments: true
  });
  const instrument = instrumenter.instrumentSync.bind(instrumenter);

  return function transform (code, file) {
    let instrumentedCode, hasChanged, cacheFile, codeHash;

    cacheFile = resolve(cacheDir, relative(root, file)) + '.json';
    codeHash = md5Hex(code);
github monounity / karma-typescript / packages / karma-typescript / src / karma / reporter.ts View on Github external
browsers.forEach((browser: any) => {

                    const coverage = that.coverageMap.get(browser);
                    const coverageMap = istanbulCoverage.createCoverageMap();
                    coverageMap.merge(coverage);

                    const sourceMapStore = istanbulSourceMaps.createSourceMapStore();
                    const remappedCoverageMap = sourceMapStore.transformCoverage(coverageMap).map;

                    const tree = istanbulReport.summarizers.pkg(remappedCoverageMap);

                    if (results && config.hasCoverageThreshold && !threshold.check(browser, remappedCoverageMap)) {
                        results.exitCode = 1;
                    }

                    Object.keys(config.reports).forEach((reportType: any) => {

                        const destination = that.getReportDestination(browser, config.reports, reportType);

                        if (destination) {
                            that.log.debug("Writing coverage to %s", destination);
                        }
                        const context = istanbulReport.createContext( { dir: destination } );

istanbul-lib-source-maps

Source maps support for istanbul

BSD-3-Clause
Latest version published 5 months ago

Package Health Score

81 / 100
Full package analysis

Popular istanbul-lib-source-maps functions