Skip to content

Commit

Permalink
Fix prettify of lastResult
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Aug 29, 2021
1 parent 8d2c064 commit 6b92dd1
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/combination/result.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const pickResultCombinations = function (resultA, resultB) {
}

// Filter out the `combinations` that are not in `result`
export const keepResultCombinations = function ({ combinations }, result) {
const keepResultCombinations = function ({ combinations }, result) {
return combinations.filter((combination) =>
resultHasCombination(result, combination),
)
Expand Down
9 changes: 0 additions & 9 deletions src/history/since/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { keepResultCombinations } from '../../combination/result.js'
import { findByDelta } from '../delta/main.js'

import { getMergedResult, getSinceResult, mergeCombinations } from './merge.js'
Expand Down Expand Up @@ -66,14 +65,6 @@ export const applySince = async function (result, previous, { since, cwd }) {
return { mergedResult, history }
}

// `history[last]` is updated with the final combinations during reporting.
// However, that history result should be normalized like the others, so we
// merge them then.
export const mergeLastResult = function (lastResult, result) {
const combinations = keepResultCombinations(result, lastResult)
return { ...lastResult, combinations }
}

// In principle, we should do both `applySince()` and `mergeHistory()` at
// the same time, before reporting. However, `applySince()` is slow.
// - To avoid repeating it before each preview, we compute it only once before
Expand Down
56 changes: 38 additions & 18 deletions src/report/normalize/computed.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mergeHistory, mergeLastResult } from '../../history/since/main.js'
import { mergeHistory } from '../../history/since/main.js'
import { addScreenInfo } from '../tty.js'

import {
Expand All @@ -7,7 +7,7 @@ import {
mergeResultProps,
normalizeCombEach,
} from './common.js'
import { prettifyStats } from './stats/main.js'
import { prettifyStats, prettifyHistoryStats } 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 @@ -17,17 +17,22 @@ import { prettifyStats } from './stats/main.js'
// beginning of the command in `normalizeHistory()` and
// `normalizeTargetResult()`
export const normalizeComputedResult = function (
result,
unmergedResult,
{ history: [sinceResult], mergedResult },
config,
) {
const resultA = normalizeCombAllUnmerged(result, sinceResult)
const resultB = mergeHistory(resultA, mergedResult)
const resultC = normalizeCombAllMerged(resultB)
const resultD = prettifyStats(resultC, resultC.combinations)
const resultE = addScreenInfo(resultD)
const unmergedResultA = normalizeCombAllUnmerged(unmergedResult, sinceResult)
const result = mergeHistory(unmergedResultA, mergedResult)
const resultA = normalizeCombAllMerged(result)
const resultB = prettifyStats(resultA, resultA.combinations)
const resultC = addScreenInfo(resultB)
const reporters = config.reporters.map((reporter) =>
normalizeComputedEach({ result: resultE, reporter, config }),
normalizeComputedEach({
result: resultC,
unmergedResult: unmergedResultA,
reporter,
config,
}),
)
return { ...config, reporters }
}
Expand All @@ -36,14 +41,18 @@ export const normalizeComputedResult = function (
// related and reporter-specific.
const normalizeComputedEach = function ({
result,
reporter: {
capabilities: { history: hasHistory },
},
unmergedResult,
reporter: { history, resultProps, footerParams, ...reporter },
config,
}) {
const resultA = normalizeCombEach(result, reporter, config)
const resultB = addLastResult(resultA, history, hasHistory)
const resultA = addLastResult({
result,
unmergedResult,
history,
reporter,
config,
})
const resultB = normalizeCombEach(resultA, reporter, config)
const resultC = mergeResultProps(resultB, resultProps)
const resultD = { ...resultC, ...footerParams }
return { ...reporter, result: resultD }
Expand All @@ -53,13 +62,24 @@ const normalizeComputedEach = function ({
// - It must use history result's normalization, not target result
// - Its combinations do not include `mergeResult`
// We also apply `capabilities.history: false`, which omits `result.history`.
const addLastResult = function (result, history, hasHistory) {
if (!hasHistory) {
const addLastResult = function ({
result,
unmergedResult: { combinations },
history,
reporter,
reporter: { capabilities },
config,
}) {
if (!capabilities.history) {
return result
}

const lastResult = history[history.length - 1]
const historyA = history.slice(0, -1)
const lastResultA = mergeLastResult(lastResult, result)
return { ...result, history: [...historyA, lastResultA] }
const lastResultA = { ...lastResult, combinations }
const lastResultB = normalizeCombAllMerged(lastResultA)
const lastResultC = normalizeCombEach(lastResultB, reporter, config)
const historyB = [...historyA, lastResultC]
const historyC = prettifyHistoryStats(historyB)
return { ...result, history: historyC }
}
4 changes: 1 addition & 3 deletions src/report/normalize/early.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
mergeResultProps,
normalizeCombEach,
} from './common.js'
import { prettifyHistoryStats } from './stats/main.js'
import { normalizeTargetResult } from './target.js'

// Normalize as many properties as possible at the beginning of the reporting
Expand Down Expand Up @@ -35,9 +34,8 @@ const normalizeHistory = function (history, sinceResult, config) {
.map(normalizeHistoryAll)
.map(normalizeNonCombAll)
.map((result) => normalizeCombAll(result, sinceResult))
const historyB = prettifyHistoryStats(historyA)
const reporters = config.reporters.map((reporter) =>
normalizeHistoryEach(historyB, reporter, config),
normalizeHistoryEach(historyA, reporter, config),
)
return { ...config, reporters }
}
Expand Down
7 changes: 5 additions & 2 deletions src/report/normalize/stats/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ import { addStatsPretty } from './prettify.js'
// combinations. This ensures results are all printed with the same scale.
// - This is used when printing `result.history`
// 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`.
// Prettifying history results:
// - We adjust the scale based on all history results, i.e. we need to also
// pass those as `allCombinations`.
// - Must be done on each history result during each preview since the target
// result might change the scale of all history results
export const prettifyHistoryStats = function (history) {
const allCombinations = history.flatMap(getCombinations)
return history.map((historyResult) =>
Expand Down

0 comments on commit 6b92dd1

Please sign in to comment.