Skip to content

Commit

Permalink
Add combinationName to limit error message
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Sep 12, 2021
1 parent bda1b54 commit 5a73421
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
22 changes: 16 additions & 6 deletions src/combination/name.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,30 @@ import { getCombinationIds } from './ids.js'

// Retrieve string with each combination's dimension id.
// This is in contrast with `combinationTitle`:
// - `combinationTitle` uses dimensions titles, which is more useful at
// - `combinationTitle*` uses dimensions titles, which is more useful at
// report time
// - `combinationName` uses ids, which is more useful at `run`-time
// - `combinationName*` uses ids, which is more useful at `run`-time
// (`dev`, preview bottom bar) since users might use those on the next run
export const getCombinationNameColor = function (combination) {
return getCombinationIds(combination)
.map(getCombinationNamePart)
.map(getNameColorPart)
.join(NAME_SEPARATOR_COLOR)
}

const getCombinationNamePart = function ({ dimension: { messageName }, id }) {
export const getCombinationName = function (combination) {
return getCombinationIds(combination).map(getNamePart).join(NAME_SEPARATOR)
}

const getNameColorPart = function ({ dimension: { messageName }, id }) {
const idColor = titleColor(id)
return `${noteColor(messageName)} ${QUOTE_COLOR}${idColor}${QUOTE_COLOR}`
}

const NAME_SEPARATOR_COLOR = noteColor(', ')
const QUOTE_COLOR = noteColor('"')
const getNamePart = function ({ dimension: { messageName }, id }) {
return `${messageName} ${QUOTE}${id}${QUOTE}`
}

const NAME_SEPARATOR = ', '
const NAME_SEPARATOR_COLOR = noteColor(NAME_SEPARATOR)
const QUOTE = '"'
const QUOTE_COLOR = noteColor(QUOTE)
12 changes: 5 additions & 7 deletions src/history/compare/limit.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import stripAnsi from 'strip-ansi'

import { getCombinationName } from '../../combination/name.js'
import { UserError } from '../../error/main.js'
import { matchSelectors } from '../../select/match.js'

Expand Down Expand Up @@ -45,7 +44,6 @@ const hasDiff = function ({ stats: { diff, diffPrecise } }) {
const checkCombinationLimits = function ({
combination,
combination: {
name,
stats: {
diff: { raw: diff },
},
Expand All @@ -66,19 +64,19 @@ const checkCombinationLimits = function ({
return
}

return getLimitError({ name, diff, threshold, higher })
return getLimitError({ diff, threshold, higher, combination })
}

const isBelowThreshold = function (diff, threshold, higher) {
return higher ? diff <= threshold : diff >= threshold
}

const getLimitError = function ({ name = 'oo', diff, threshold, higher }) {
const nameA = stripAnsi(name)
const getLimitError = function ({ diff, threshold, higher, combination }) {
const combinationName = getCombinationName(combination)
const thresholdStr = threshold * PERCENTAGE_RATIO
const diffStr = serializeDiff(diff)
const higherStr = higher ? 'higher' : 'lower'
return `${nameA} should be at most ${thresholdStr}% ${higherStr} but it is ${diffStr}% ${higherStr}.`
return `The ${combinationName} should be at most ${thresholdStr}% ${higherStr} but it is ${diffStr}% ${higherStr}.`
}

const serializeDiff = function (diff) {
Expand Down

0 comments on commit 5a73421

Please sign in to comment.