• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript istanbul-lib-coverage.CoverageMap类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中istanbul-lib-coverage.CoverageMap的典型用法代码示例。如果您正苦于以下问题:TypeScript CoverageMap类的具体用法?TypeScript CoverageMap怎么用?TypeScript CoverageMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了CoverageMap类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: _checkThreshold

  private _checkThreshold(globalConfig: Config.GlobalConfig, map: CoverageMap) {
    if (globalConfig.coverageThreshold) {
      function check(
        name: string,
        thresholds: {[index: string]: number},
        actuals: CoverageSummaryData,
      ) {
        return (['statements', 'branches', 'lines', 'functions'] as Array<
          keyof CoverageSummaryData
        >).reduce<Array<string>>((errors, key) => {
          const actual = actuals[key].pct;
          const actualUncovered = actuals[key].total - actuals[key].covered;
          const threshold = thresholds[key];

          if (threshold != null) {
            if (threshold < 0) {
              if (threshold * -1 < actualUncovered) {
                errors.push(
                  `Jest: Uncovered count for ${key} (${actualUncovered})` +
                    `exceeds ${name} threshold (${-1 * threshold})`,
                );
              }
            } else if (actual < threshold) {
              errors.push(
                `Jest: "${name}" coverage threshold for ${key} (${threshold}%) not met: ${actual}%`,
              );
            }
          }
          return errors;
        }, []);
      }

      const THRESHOLD_GROUP_TYPES = {
        GLOB: 'glob',
        GLOBAL: 'global',
        PATH: 'path',
      };
      const coveredFiles = map.files();
      const thresholdGroups = Object.keys(globalConfig.coverageThreshold);
      const groupTypeByThresholdGroup: {[index: string]: string} = {};
      const filesByGlob: {[index: string]: Array<string>} = {};

      const coveredFilesSortedIntoThresholdGroup = coveredFiles.reduce<
        Array<[string, string | undefined]>
      >((files, file) => {
        const pathOrGlobMatches = thresholdGroups.reduce<
          Array<[string, string]>
        >((agg, thresholdGroup) => {
          const absoluteThresholdGroup = path.resolve(thresholdGroup);

          // The threshold group might be a path:

          if (file.indexOf(absoluteThresholdGroup) === 0) {
            groupTypeByThresholdGroup[thresholdGroup] =
              THRESHOLD_GROUP_TYPES.PATH;
            return agg.concat([[file, thresholdGroup]]);
          }

          // If the threshold group is not a path it might be a glob:

          // Note: glob.sync is slow. By memoizing the files matching each glob
          // (rather than recalculating it for each covered file) we save a tonne
          // of execution time.
          if (filesByGlob[absoluteThresholdGroup] === undefined) {
            filesByGlob[absoluteThresholdGroup] = glob
              .sync(absoluteThresholdGroup)
              .map(filePath => path.resolve(filePath));
          }

          if (filesByGlob[absoluteThresholdGroup].indexOf(file) > -1) {
            groupTypeByThresholdGroup[thresholdGroup] =
              THRESHOLD_GROUP_TYPES.GLOB;
            return agg.concat([[file, thresholdGroup]]);
          }

          return agg;
        }, []);

        if (pathOrGlobMatches.length > 0) {
          return files.concat(pathOrGlobMatches);
        }

        // Neither a glob or a path? Toss it in global if there's a global threshold:
        if (thresholdGroups.indexOf(THRESHOLD_GROUP_TYPES.GLOBAL) > -1) {
          groupTypeByThresholdGroup[THRESHOLD_GROUP_TYPES.GLOBAL] =
            THRESHOLD_GROUP_TYPES.GLOBAL;
          return files.concat([[file, THRESHOLD_GROUP_TYPES.GLOBAL]]);
        }

        // A covered file that doesn't have a threshold:
        return files.concat([[file, undefined]]);
      }, []);

      const getFilesInThresholdGroup = (thresholdGroup: string) =>
        coveredFilesSortedIntoThresholdGroup
          .filter(fileAndGroup => fileAndGroup[1] === thresholdGroup)
          .map(fileAndGroup => fileAndGroup[0]);

      function combineCoverage(filePaths: Array<string>) {
        return filePaths
//.........这里部分代码省略.........
开发者ID:facebook,项目名称:jest,代码行数:101,代码来源:coverage_reporter.ts


示例2: onTestResult

  onTestResult(
    _test: Test,
    testResult: TestResult,
    _aggregatedResults: AggregatedResult,
  ) {
    if (testResult.coverage) {
      this._coverageMap.merge(testResult.coverage);
    }

    const sourceMaps = testResult.sourceMaps;
    if (sourceMaps) {
      Object.keys(sourceMaps).forEach(sourcePath => {
        let inputSourceMap: RawSourceMap | undefined;
        try {
          const coverage: FileCoverage = this._coverageMap.fileCoverageFor(
            sourcePath,
          );
          inputSourceMap = (coverage.toJSON() as any).inputSourceMap;
        } finally {
          if (inputSourceMap) {
            this._sourceMapStore.registerMap(sourcePath, inputSourceMap);
          } else {
            this._sourceMapStore.registerURL(
              sourcePath,
              sourceMaps[sourcePath],
            );
          }
        }
      });
    }
  }
开发者ID:facebook,项目名称:jest,代码行数:31,代码来源:coverage_reporter.ts


示例3: onTestResult

  onTestResult(
    _test: Test,
    testResult: TestResult,
    _aggregatedResults: AggregatedResult,
  ) {
    if (testResult.coverage) {
      this._coverageMap.merge(testResult.coverage);
      // Remove coverage data to free up some memory.
      delete testResult.coverage;

      Object.keys(testResult.sourceMaps).forEach(sourcePath => {
        let inputSourceMap: RawSourceMap | undefined;
        try {
          const coverage: FileCoverage = this._coverageMap.fileCoverageFor(
            sourcePath,
          );
          ({inputSourceMap} = coverage.toJSON() as any);
        } finally {
          if (inputSourceMap) {
            this._sourceMapStore.registerMap(sourcePath, inputSourceMap);
          } else {
            this._sourceMapStore.registerURL(
              sourcePath,
              testResult.sourceMaps[sourcePath],
            );
          }
        }
      });
    }
  }
开发者ID:Volune,项目名称:jest,代码行数:30,代码来源:coverage_reporter.ts


示例4: check

 fileMatchingGlob => {
   errors = errors.concat(
     check(
       fileMatchingGlob,
       globalConfig.coverageThreshold[thresholdGroup],
       map.fileCoverageFor(fileMatchingGlob).toSummary(),
     ),
   );
 },
开发者ID:facebook,项目名称:jest,代码行数:9,代码来源:coverage_reporter.ts


示例5:

 Object.keys(sourceMaps).forEach(sourcePath => {
   let inputSourceMap: RawSourceMap | undefined;
   try {
     const coverage: FileCoverage = this._coverageMap.fileCoverageFor(
       sourcePath,
     );
     inputSourceMap = (coverage.toJSON() as any).inputSourceMap;
   } finally {
     if (inputSourceMap) {
       this._sourceMapStore.registerMap(sourcePath, inputSourceMap);
     } else {
       this._sourceMapStore.registerURL(
         sourcePath,
         sourceMaps[sourcePath],
       );
     }
   }
 });
开发者ID:facebook,项目名称:jest,代码行数:18,代码来源:coverage_reporter.ts


示例6: catch

    const instrumentation = files.map(async fileObj => {
      const filename = fileObj.path;
      const config = fileObj.config;

      if (!this._coverageMap.data[filename] && 'worker' in worker) {
        try {
          const result = await worker.worker({
            config,
            globalConfig,
            options: {
              ...this._options,
              changedFiles:
                this._options.changedFiles &&
                Array.from(this._options.changedFiles),
            },
            path: filename,
          });

          if (result) {
            this._coverageMap.addFileCoverage(result.coverage);

            if (result.sourceMapPath) {
              this._sourceMapStore.registerURL(filename, result.sourceMapPath);
            }
          }
        } catch (error) {
          console.error(
            chalk.red(
              [
                `Failed to collect coverage from ${filename}`,
                `ERROR: ${error.message}`,
                `STACK: ${error.stack}`,
              ].join('\n'),
            ),
          );
        }
      }
    });
开发者ID:facebook,项目名称:jest,代码行数:38,代码来源:coverage_reporter.ts



注:本文中的istanbul-lib-coverage.CoverageMap类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap