Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Aug 29, 2021
1 parent c992b57 commit 8d2c064
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/report/normalize/computed.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
mergeResultProps,
normalizeCombEach,
} from './common.js'
import { prettifyTargetStats } from './stats/main.js'
import { prettifyStats } from './stats/main.js'

// Add report-specific properties to the target result, but only for
// `combinations`. This is applied after measuring and history merging have
Expand All @@ -24,7 +24,7 @@ export const normalizeComputedResult = function (
const resultA = normalizeCombAllUnmerged(result, sinceResult)
const resultB = mergeHistory(resultA, mergedResult)
const resultC = normalizeCombAllMerged(resultB)
const resultD = prettifyTargetStats(resultC)
const resultD = prettifyStats(resultC, resultC.combinations)
const resultE = addScreenInfo(resultD)
const reporters = config.reporters.map((reporter) =>
normalizeComputedEach({ result: resultE, reporter, config }),
Expand Down
4 changes: 1 addition & 3 deletions src/report/normalize/early.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ const normalizeHistory = function (history, sinceResult, config) {
.map(normalizeHistoryAll)
.map(normalizeNonCombAll)
.map((result) => normalizeCombAll(result, sinceResult))
const historyB = historyA.map((result) =>
prettifyHistoryStats(result, historyA),
)
const historyB = prettifyHistoryStats(historyA)
const reporters = config.reporters.map((reporter) =>
normalizeHistoryEach(historyB, reporter, config),
)
Expand Down
19 changes: 8 additions & 11 deletions src/report/normalize/stats/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,24 @@ import { addStatsPretty } from './prettify.js'
// This is not format specific since most formats benefit from it.
// When prettifying history results, we adjust the scale based on all history
// results, i.e. we need to also pass those as `allCombinations`.
export const prettifyHistoryStats = function (result, history) {
export const prettifyHistoryStats = function (history) {
const allCombinations = history.flatMap(getCombinations)
const combinations = prettifyStats(result.combinations, allCombinations)
return { ...result, combinations }
return history.map((historyResult) =>
prettifyStats(historyResult, allCombinations),
)
}

const getCombinations = function ({ combinations }) {
return combinations
}

export const prettifyTargetStats = function (result) {
const combinations = prettifyStats(result.combinations, result.combinations)
return { ...result, combinations }
}

const prettifyStats = function (combinations, allCombinations) {
return STAT_KINDS.reduce(
export const prettifyStats = function (result, allCombinations) {
const combinations = STAT_KINDS.reduce(
(combinationsA, statKind) =>
prettifyCombinationsStat(statKind, combinationsA, allCombinations),
combinations,
result.combinations,
)
return { ...result, combinations }
}

const prettifyCombinationsStat = function (
Expand Down

0 comments on commit 8d2c064

Please sign in to comment.