Skip to content

Commit

Permalink
Run prettier on changed files
Browse files Browse the repository at this point in the history
  • Loading branch information
ttmarek committed Nov 14, 2017
1 parent 4047f47 commit 68a798d
Showing 1 changed file with 67 additions and 38 deletions.
105 changes: 67 additions & 38 deletions packages/jest-cli/src/reporters/coverage_reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,9 @@ export default class CoverageReporter extends BaseReporter {
}
} else if (actual < threshold) {
errors.push(
`Jest: "${name}" coverage threshold for ${key} (${threshold}%) not met: ` +
`${actual}%`,
`Jest: "${name}" coverage threshold for ${key} (${
threshold
}%) not met: ` + `${actual}%`,
);
}
}
Expand Down Expand Up @@ -264,7 +265,8 @@ export default class CoverageReporter extends BaseReporter {
// The threshold group might be a path:

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

Expand All @@ -274,81 +276,108 @@ export default class CoverageReporter extends BaseReporter {
// (rather than recalculating it for each covered file) we save a tonne
// of execution time.
if (filesByGlob[absoluteThresholdGroup] === undefined) {
filesByGlob[absoluteThresholdGroup] = glob.sync(absoluteThresholdGroup);
filesByGlob[absoluteThresholdGroup] = glob.sync(
absoluteThresholdGroup,
);
}

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

// 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 [file, THRESHOLD_GROUP_TYPES.GLOBAL]
groupTypeByThresholdGroup[THRESHOLD_GROUP_TYPES.GLOBAL] =
THRESHOLD_GROUP_TYPES.GLOBAL;
return [file, THRESHOLD_GROUP_TYPES.GLOBAL];
}

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

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

function combineCoverage(filePaths) {
return filePaths
.map((filePath) => map.fileCoverageFor(filePath))
.reduce((combinedCoverage: ?CoverageSummary, nextFileCoverage: FileCoverage) => {
if (combinedCoverage === undefined || combinedCoverage === null) {
return nextFileCoverage.toSummary();
}
return combinedCoverage.merge(nextFileCoverage.toSummary());
}, undefined);
.map(filePath => map.fileCoverageFor(filePath))
.reduce(
(
combinedCoverage: ?CoverageSummary,
nextFileCoverage: FileCoverage,
) => {
if (combinedCoverage === undefined || combinedCoverage === null) {
return nextFileCoverage.toSummary();
}
return combinedCoverage.merge(nextFileCoverage.toSummary());
},
undefined,
);
}

let errors = [];

thresholdGroups.forEach(thresholdGroup => {
switch (groupTypeByThresholdGroup[thresholdGroup]) {
case THRESHOLD_GROUP_TYPES.GLOBAL: {
const coverage = combineCoverage(getFilesInThresholdGroup(THRESHOLD_GROUP_TYPES.GLOBAL));
const coverage = combineCoverage(
getFilesInThresholdGroup(THRESHOLD_GROUP_TYPES.GLOBAL),
);
if (coverage) {
errors = errors.concat(check(
thresholdGroup,
globalConfig.coverageThreshold[thresholdGroup],
coverage
));
errors = errors.concat(
check(
thresholdGroup,
globalConfig.coverageThreshold[thresholdGroup],
coverage,
),
);
}
break;
}
case THRESHOLD_GROUP_TYPES.PATH: {
const coverage = combineCoverage(getFilesInThresholdGroup(thresholdGroup));
const coverage = combineCoverage(
getFilesInThresholdGroup(thresholdGroup),
);
if (coverage) {
errors = errors.concat(check(
thresholdGroup,
globalConfig.coverageThreshold[thresholdGroup],
coverage
));
errors = errors.concat(
check(
thresholdGroup,
globalConfig.coverageThreshold[thresholdGroup],
coverage,
),
);
}
break;
}
case THRESHOLD_GROUP_TYPES.GLOB:
getFilesInThresholdGroup(thresholdGroup).forEach(fileMatchingGlob => {
errors = errors.concat(check(
fileMatchingGlob,
globalConfig.coverageThreshold[thresholdGroup],
map.fileCoverageFor(fileMatchingGlob).toSummary()
));
});
getFilesInThresholdGroup(thresholdGroup).forEach(
fileMatchingGlob => {
errors = errors.concat(
check(
fileMatchingGlob,
globalConfig.coverageThreshold[thresholdGroup],
map.fileCoverageFor(fileMatchingGlob).toSummary(),
),
);
},
);
break;
default:
errors = errors.concat(`Jest: Coverage data for ${thresholdGroup} was not found.`)
errors = errors.concat(
`Jest: Coverage data for ${thresholdGroup} was not found.`,
);
}
});

errors = errors.filter(err => err !== undefined && err !== null && err.length > 0);
errors = errors.filter(
err => err !== undefined && err !== null && err.length > 0,
);

if (errors.length > 0) {
this.log(`${FAIL_COLOR(errors.join('\n'))}`);
Expand Down

0 comments on commit 68a798d

Please sign in to comment.