generateEmptyCoverage.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.default = _default;
  6. function _istanbulLibInstrument() {
  7. const data = require('istanbul-lib-instrument');
  8. _istanbulLibInstrument = function _istanbulLibInstrument() {
  9. return data;
  10. };
  11. return data;
  12. }
  13. function _istanbulLibCoverage() {
  14. const data = require('istanbul-lib-coverage');
  15. _istanbulLibCoverage = function _istanbulLibCoverage() {
  16. return data;
  17. };
  18. return data;
  19. }
  20. function _transform() {
  21. const data = require('@jest/transform');
  22. _transform = function _transform() {
  23. return data;
  24. };
  25. return data;
  26. }
  27. /**
  28. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  29. *
  30. * This source code is licensed under the MIT license found in the
  31. * LICENSE file in the root directory of this source tree.
  32. */
  33. function _default(source, filename, globalConfig, config, changedFiles) {
  34. const coverageOptions = {
  35. changedFiles,
  36. collectCoverage: globalConfig.collectCoverage,
  37. collectCoverageFrom: globalConfig.collectCoverageFrom,
  38. collectCoverageOnlyFrom: globalConfig.collectCoverageOnlyFrom
  39. };
  40. let coverageWorkerResult = null;
  41. if ((0, _transform().shouldInstrument)(filename, coverageOptions, config)) {
  42. // Transform file with instrumentation to make sure initial coverage data is well mapped to original code.
  43. const _transformSource = new (_transform()).ScriptTransformer(
  44. config
  45. ).transformSource(filename, source, true),
  46. code = _transformSource.code,
  47. mapCoverage = _transformSource.mapCoverage,
  48. sourceMapPath = _transformSource.sourceMapPath;
  49. const extracted = (0, _istanbulLibInstrument().readInitialCoverage)(code); // Check extracted initial coverage is not null, this can happen when using /* istanbul ignore file */
  50. if (extracted) {
  51. coverageWorkerResult = {
  52. coverage: (0, _istanbulLibCoverage().createFileCoverage)(
  53. extracted.coverageData
  54. ),
  55. sourceMapPath: mapCoverage ? sourceMapPath : null
  56. };
  57. }
  58. }
  59. return coverageWorkerResult;
  60. }