diff --git a/packages/ci/src/lib/portal/__snapshots__/transform.unit.test.ts.snap b/packages/ci/src/lib/portal/__snapshots__/transform.unit.test.ts.snap index 6786b87f0..a7bcefa67 100644 --- a/packages/ci/src/lib/portal/__snapshots__/transform.unit.test.ts.snap +++ b/packages/ci/src/lib/portal/__snapshots__/transform.unit.test.ts.snap @@ -4,7 +4,6 @@ exports[`transformGQLReport > should convert full GraphQL report to valid report { "categories": [ { - "isBinary": false, "refs": [ { "plugin": "eslint", @@ -17,7 +16,6 @@ exports[`transformGQLReport > should convert full GraphQL report to valid report "title": "Code style", }, { - "isBinary": false, "refs": [ { "plugin": "bundle-stats", diff --git a/packages/ci/src/lib/portal/transform.ts b/packages/ci/src/lib/portal/transform.ts index 760ea3850..d9535e5c6 100644 --- a/packages/ci/src/lib/portal/transform.ts +++ b/packages/ci/src/lib/portal/transform.ts @@ -61,7 +61,6 @@ function transformGQLCategory(category: CategoryFragment): CategoryConfig { return { slug: category.slug, title: category.title, - isBinary: category.isBinary, ...(category.description && { description: category.description }), refs: category.refs.map( ({ target, weight }): CategoryRef => ({ @@ -71,6 +70,9 @@ function transformGQLCategory(category: CategoryFragment): CategoryConfig { weight, }), ), + // TODO: Portal API migration - convert isBinary to scoreTarget for backward compatibility + // Remove this conversion when Portal API supports scoreTarget (#713) + ...(category.isBinary && { scoreTarget: 1 }), }; } diff --git a/packages/core/src/lib/implementation/report-to-gql.ts b/packages/core/src/lib/implementation/report-to-gql.ts index 0a9358682..6c0dab792 100644 --- a/packages/core/src/lib/implementation/report-to-gql.ts +++ b/packages/core/src/lib/implementation/report-to-gql.ts @@ -199,7 +199,9 @@ function categoryToGQL(category: CategoryConfig): PortalCategory { slug: category.slug, title: category.title, description: category.description, - isBinary: category.isBinary, + // TODO: Portal API migration - convert scoreTarget to isBinary for backward compatibility + // Remove this conversion when Portal API supports scoreTarget (#713) + isBinary: category.scoreTarget === 1, refs: category.refs.map(ref => ({ plugin: ref.plugin, type: categoryRefTypeToGQL(ref.type), diff --git a/packages/models/docs/models-reference.md b/packages/models/docs/models-reference.md index be7d688c1..cad1b40d4 100644 --- a/packages/models/docs/models-reference.md +++ b/packages/models/docs/models-reference.md @@ -167,15 +167,15 @@ _Boolean._ _Object containing the following properties:_ -| Property | Description | Type | -| :--------------- | :------------------------------------------------------------------------- | :---------------------------------------------------------------- | -| **`slug`** (\*) | Human-readable unique ID, e.g. "performance" | `string` (_regex: `/^[a-z\d]+(?:-[a-z\d]+)*$/`, max length: 128_) | -| **`refs`** (\*) | | _Array of at least 1 [CategoryRef](#categoryref) items_ | -| **`title`** (\*) | Category Title | `string` (_max length: 256_) | -| `description` | Category description | `string` (_max length: 65536_) | -| `docsUrl` | Category docs URL | `string` (_url_) (_optional_) _or_ `''` | -| `isSkipped` | | `boolean` | -| `isBinary` | Is this a binary category (i.e. only a perfect score considered a "pass")? | `boolean` | +| Property | Description | Type | +| :--------------- | :------------------------------------------- | :---------------------------------------------------------------- | +| **`slug`** (\*) | Human-readable unique ID, e.g. "performance" | `string` (_regex: `/^[a-z\d]+(?:-[a-z\d]+)*$/`, max length: 128_) | +| **`refs`** (\*) | | _Array of at least 1 [CategoryRef](#categoryref) items_ | +| **`title`** (\*) | Category Title | `string` (_max length: 256_) | +| `description` | Category description | `string` (_max length: 65536_) | +| `docsUrl` | Category docs URL | `string` (_url_) (_optional_) _or_ `''` | +| `isSkipped` | | `boolean` | +| `scoreTarget` | Pass/fail score threshold (0-1) | `number` (_≥0, ≤1_) | _(\*) Required._ diff --git a/packages/models/src/lib/category-config.ts b/packages/models/src/lib/category-config.ts index c634afced..f6a14e432 100644 --- a/packages/models/src/lib/category-config.ts +++ b/packages/models/src/lib/category-config.ts @@ -5,6 +5,7 @@ import { } from './implementation/checks.js'; import { metaSchema, + nonnegativeNumberSchema, scorableSchema, slugSchema, weightedRefSchema, @@ -14,18 +15,16 @@ import { formatRef } from './implementation/utils.js'; export const categoryRefSchema = weightedRefSchema( 'Weighted references to audits and/or groups for the category', 'Slug of an audit or group (depending on `type`)', -).merge( - z.object({ - type: z - .enum(['audit', 'group']) - .describe( - 'Discriminant for reference kind, affects where `slug` is looked up', - ), - plugin: slugSchema.describe( - 'Plugin slug (plugin should contain referenced audit or group)', +).extend({ + type: z + .enum(['audit', 'group']) + .describe( + 'Discriminant for reference kind, affects where `slug` is looked up', ), - }), -); + plugin: slugSchema.describe( + 'Plugin slug (plugin should contain referenced audit or group)', + ), +}); export type CategoryRef = z.infer; export const categoryConfigSchema = scorableSchema( @@ -37,24 +36,20 @@ export const categoryConfigSchema = scorableSchema( `Category has duplicate references: ${formatSerializedCategoryRefTargets(duplicates)}`, ), ) - .merge( + .extend( metaSchema({ titleDescription: 'Category Title', docsUrlDescription: 'Category docs URL', descriptionDescription: 'Category description', description: 'Meta info for category', - }), + }).shape, ) - .merge( - z.object({ - isBinary: z - .boolean() - .describe( - 'Is this a binary category (i.e. only a perfect score considered a "pass")?', - ) - .optional(), - }), - ); + .extend({ + scoreTarget: nonnegativeNumberSchema + .max(1) + .describe('Pass/fail score threshold (0-1)') + .optional(), + }); export type CategoryConfig = z.infer; diff --git a/packages/models/src/lib/category-config.unit.test.ts b/packages/models/src/lib/category-config.unit.test.ts index bc717bb30..7e7ffd091 100644 --- a/packages/models/src/lib/category-config.unit.test.ts +++ b/packages/models/src/lib/category-config.unit.test.ts @@ -92,7 +92,6 @@ describe('categoryConfigSchema', () => { title: 'Test results', description: 'This category collects test results.', docsUrl: 'https://www.cypress.io/', - isBinary: false, refs: [ { plugin: 'cypress', diff --git a/packages/plugin-lighthouse/README.md b/packages/plugin-lighthouse/README.md index d0ff7562a..04920a1a4 100644 --- a/packages/plugin-lighthouse/README.md +++ b/packages/plugin-lighthouse/README.md @@ -86,12 +86,6 @@ export default { title: 'SEO', refs: [lighthouseGroupRef('seo')], }, - { - slug: 'pwa', - title: 'PWA', - isBinary: true, - refs: [lighthouseGroupRef('pwa')], - }, ], }; ``` @@ -108,10 +102,10 @@ export default { // ... categories: [ { - slug: 'pwa', - title: 'PWA', - isBinary: true, - refs: [lighthouseAuditRef('installable-manifest', 2), lighthouseAuditRef('splash-screen', 1), lighthouseAuditRef('themed-omnibox', 1), lighthouseAuditRef('content-width', 1), lighthouseAuditRef('themed-omnibox', 2), lighthouseAuditRef('viewport', 2), lighthouseAuditRef('maskable-icon', 1), lighthouseAuditRef('pwa-cross-browser', 0), lighthouseAuditRef('pwa-page-transitions', 0), lighthouseAuditRef('pwa-each-page-has-url', 0)], + slug: 'core-web-vitals', + title: 'Core Web Vitals', + scoreTarget: 0.9, + refs: [lighthouseAuditRef('largest-contentful-paint', 3), lighthouseAuditRef('first-input-delay', 2), lighthouseAuditRef('cumulative-layout-shift', 2), lighthouseAuditRef('first-contentful-paint', 1)], }, ], }; diff --git a/packages/plugin-lighthouse/src/lib/constants.ts b/packages/plugin-lighthouse/src/lib/constants.ts index 2a79ab3f3..d1ee09fce 100644 --- a/packages/plugin-lighthouse/src/lib/constants.ts +++ b/packages/plugin-lighthouse/src/lib/constants.ts @@ -16,7 +16,6 @@ export const LIGHTHOUSE_GROUP_SLUGS = [ 'accessibility', 'best-practices', 'seo', - 'pwa', ] as const; export const SINGLE_URL_THRESHOLD = 1; diff --git a/packages/plugin-lighthouse/src/lib/merge-categories.unit.test.ts b/packages/plugin-lighthouse/src/lib/merge-categories.unit.test.ts index a3bfb2e28..44c583842 100644 --- a/packages/plugin-lighthouse/src/lib/merge-categories.unit.test.ts +++ b/packages/plugin-lighthouse/src/lib/merge-categories.unit.test.ts @@ -327,7 +327,6 @@ describe('mergeLighthouseCategories', () => { title: 'Performance', description: 'Website performance metrics', docsUrl: 'https://docs.example.com/performance', - isBinary: true, refs: [ { type: 'group', @@ -336,6 +335,7 @@ describe('mergeLighthouseCategories', () => { weight: 1, }, ], + scoreTarget: 1, }, ])[0], ).toEqual({ @@ -343,7 +343,6 @@ describe('mergeLighthouseCategories', () => { title: 'Performance', description: 'Website performance metrics', docsUrl: 'https://docs.example.com/performance', - isBinary: true, refs: [ { type: 'group', @@ -358,6 +357,7 @@ describe('mergeLighthouseCategories', () => { weight: 1, }, ], + scoreTarget: 1, }); }); }); @@ -689,7 +689,6 @@ describe('expandAggregatedCategory', () => { title: 'Performance', description: 'Website performance metrics', docsUrl: 'https://docs.example.com', - isBinary: true, refs: [ { type: 'group', @@ -698,6 +697,7 @@ describe('expandAggregatedCategory', () => { weight: 1, }, ], + scoreTarget: 1, }; expect( expandAggregatedCategory(category, { urlCount: 1, weights: { 1: 1 } }), diff --git a/packages/utils/perf/score-report/index.ts b/packages/utils/perf/score-report/index.ts index 3f477e915..8cde639f3 100644 --- a/packages/utils/perf/score-report/index.ts +++ b/packages/utils/perf/score-report/index.ts @@ -154,7 +154,6 @@ function minimalReport(opt?: MinimalReportOptions): Report { slug: `${AUDIT_P1_PREFIX}${idx}`, weight: 1, })), - isBinary: false, }, { slug: 'c2_', @@ -165,7 +164,6 @@ function minimalReport(opt?: MinimalReportOptions): Report { slug: `${AUDIT_P2_PREFIX}${idx}`, weight: 1, })), - isBinary: false, }, ], plugins: [ diff --git a/packages/utils/src/lib/reports/__snapshots__/generate-md-report-category-section.unit.test.ts.snap b/packages/utils/src/lib/reports/__snapshots__/generate-md-report-category-section.unit.test.ts.snap index 191eaf9ab..7e293956e 100644 --- a/packages/utils/src/lib/reports/__snapshots__/generate-md-report-category-section.unit.test.ts.snap +++ b/packages/utils/src/lib/reports/__snapshots__/generate-md-report-category-section.unit.test.ts.snap @@ -1,6 +1,6 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`categoriesDetailsSection > should render categories details and add "✅" when isBinary is passing 1`] = ` +exports[`categoriesDetailsSection > should render categories details and add "✅" when score >= scoreTarget 1`] = ` "## 🏷 Categories ### Bug Prevention @@ -11,7 +11,7 @@ exports[`categoriesDetailsSection > should render categories details and add " " `; -exports[`categoriesDetailsSection > should render categories details and add "❌" when isBinary is failing 1`] = ` +exports[`categoriesDetailsSection > should render categories details and add "❌" when score < scoreTarget 1`] = ` "## 🏷 Categories ### Bug Prevention @@ -72,7 +72,7 @@ exports[`categoriesOverviewSection > should render filtered categories table 1`] " `; -exports[`categoriesOverviewSection > should render targetScore icon "❌" if score fails 1`] = ` +exports[`categoriesOverviewSection > should render scoreTarget icon "❌" if score fails 1`] = ` "| 🏷 Category | ⭐ Score | 🛡 Audits | | :-------------------------------- | :---------: | :-------: | | [Bug Prevention](#bug-prevention) | 🟢 **98** ❌ | 1 | diff --git a/packages/utils/src/lib/reports/__snapshots__/generate-md-report.unit.test.ts.snap b/packages/utils/src/lib/reports/__snapshots__/generate-md-report.unit.test.ts.snap index 517d08e91..29b525112 100644 --- a/packages/utils/src/lib/reports/__snapshots__/generate-md-report.unit.test.ts.snap +++ b/packages/utils/src/lib/reports/__snapshots__/generate-md-report.unit.test.ts.snap @@ -74,7 +74,6 @@ exports[`generateMdReport > should render complete md report 1`] = ` | :-------------------------- | :----------: | :-------: | | [Performance](#performance) | 🟡 **61** | 2 | | [SEO](#seo) | 🟢 **100** ✅ | 1 | -| [PWA](#pwa) | 🔴 **0** ❌ | 1 | ## 🏷 Categories @@ -92,12 +91,6 @@ exports[`generateMdReport > should render complete md report 1`] = ` - 🟥 [Website is crawlable](#website-is-crawlable-lighthouse) (_Lighthouse_) - **0** -### PWA - -🔴 Score: **0** ❌ - -- 🟩 [Splash Screen](#splash-screen-lighthouse) (_Lighthouse_) - **1** - ## 🛡️ Audits ### Largest Contentful Paint (Lighthouse) @@ -175,7 +168,7 @@ Report was created by [Code PushUp](https://github.com/code-pushup/cli#readme) o | Commit | Version | Duration | Plugins | Categories | Audits | | :----------------------------------------------------------- | :------: | -------: | :-----: | :--------: | :----: | -| ci: update action (535b8e9e557336618a764f3fa45609d224a62837) | \`v1.0.0\` | 42.36 s | 2 | 3 | 5 | +| ci: update action (535b8e9e557336618a764f3fa45609d224a62837) | \`v1.0.0\` | 42.36 s | 2 | 2 | 5 | --- diff --git a/packages/utils/src/lib/reports/generate-md-report-category-section.ts b/packages/utils/src/lib/reports/generate-md-report-category-section.ts index 5cac4a477..3b606ab3c 100644 --- a/packages/utils/src/lib/reports/generate-md-report-category-section.ts +++ b/packages/utils/src/lib/reports/generate-md-report-category-section.ts @@ -11,7 +11,7 @@ import { getPluginNameFromSlug, scoreFilter, scoreMarker, - targetScoreIcon, + scoreTargetIcon, } from './utils.js'; export function categoriesOverviewSection( @@ -27,13 +27,12 @@ export function categoriesOverviewSection( ], categories .filter(scoreFilter(options)) - .map(({ title, refs, score, isBinary }) => [ - // @TODO refactor `isBinary: boolean` to `targetScore: number` #713 + .map(({ title, refs, score, scoreTarget }) => [ // The heading "ID" is inferred from the heading text in Markdown. md.link(`#${slugify(title)}`, title), md`${scoreMarker(score)} ${md.bold( formatReportScore(score), - )}${binaryIconSuffix(score, isBinary)}`, + )}${binaryIconSuffix(score, scoreTarget)}`, countCategoryAudits(refs, plugins).toString(), ]), ); @@ -54,7 +53,7 @@ export function categoriesDetailsSection( .paragraph( md`${scoreMarker(category.score)} Score: ${md.bold( formatReportScore(category.score), - )}${binaryIconSuffix(category.score, category.isBinary)}`, + )}${binaryIconSuffix(category.score, category.scoreTarget)}`, ) .list( category.refs.map(ref => { @@ -128,8 +127,7 @@ export function categoryGroupItem( export function binaryIconSuffix( score: number, - isBinary: boolean | undefined, + scoreTarget: number | undefined, ): string { - // @TODO refactor `isBinary: boolean` to `targetScore: number` #713 - return targetScoreIcon(score, isBinary ? 1 : undefined, { prefix: ' ' }); + return scoreTargetIcon(score, scoreTarget, { prefix: ' ' }); } diff --git a/packages/utils/src/lib/reports/generate-md-report-category-section.unit.test.ts b/packages/utils/src/lib/reports/generate-md-report-category-section.unit.test.ts index 01b00876e..fa57144b0 100644 --- a/packages/utils/src/lib/reports/generate-md-report-category-section.unit.test.ts +++ b/packages/utils/src/lib/reports/generate-md-report-category-section.unit.test.ts @@ -91,7 +91,7 @@ describe('categoriesOverviewSection', () => { ).toMatchSnapshot(); }); - it('should render targetScore icon "❌" if score fails', () => { + it('should render scoreTarget icon "❌" if score fails', () => { expect( categoriesOverviewSection({ plugins: [ @@ -105,7 +105,7 @@ describe('categoriesOverviewSection', () => { slug: 'bug-prevention', title: 'Bug Prevention', score: 0.98, - isBinary: true, + scoreTarget: 1, refs: [{ slug: 'no-let', type: 'audit' }], }, ], @@ -230,7 +230,7 @@ describe('categoriesDetailsSection', () => { slug: 'bug-prevention', title: 'Bug Prevention', score: 1, - isBinary: true, + scoreTarget: 1, refs: [{ slug: 'no-let', type: 'audit', plugin: 'eslint' }], }, { @@ -249,7 +249,7 @@ describe('categoriesDetailsSection', () => { slug: 'typescript', title: 'Typescript', score: 0.14, - isBinary: true, + scoreTarget: 1, refs: [{ slug: 'no-any', type: 'audit', plugin: 'eslint' }], }, ], @@ -288,7 +288,7 @@ describe('categoriesDetailsSection', () => { slug: 'bug-prevention', title: 'Bug Prevention', score: 1, - isBinary: true, + scoreTarget: 1, refs: [{ slug: 'no-let', type: 'audit', plugin: 'eslint' }], }, { @@ -307,7 +307,7 @@ describe('categoriesDetailsSection', () => { slug: 'typescript', title: 'Typescript', score: 0.14, - isBinary: true, + scoreTarget: 1, refs: [{ slug: 'no-any', type: 'audit', plugin: 'eslint' }], }, ], @@ -319,7 +319,7 @@ describe('categoriesDetailsSection', () => { ).toMatchSnapshot('filtered'); }); - it('should render categories details and add "❌" when isBinary is failing', () => { + it('should render categories details and add "❌" when score < scoreTarget', () => { expect( categoriesDetailsSection({ plugins: [ @@ -334,7 +334,7 @@ describe('categoriesDetailsSection', () => { slug: 'bug-prevention', title: 'Bug Prevention', score: 0.98, - isBinary: true, + scoreTarget: 1, refs: [{ slug: 'no-let', type: 'audit', plugin: 'eslint' }], }, ], @@ -342,7 +342,7 @@ describe('categoriesDetailsSection', () => { ).toMatchSnapshot(); }); - it('should render categories details and add "✅" when isBinary is passing', () => { + it('should render categories details and add "✅" when score >= scoreTarget', () => { expect( categoriesDetailsSection({ plugins: [ @@ -357,7 +357,7 @@ describe('categoriesDetailsSection', () => { slug: 'bug-prevention', title: 'Bug Prevention', score: 1, - isBinary: true, + scoreTarget: 1, refs: [{ slug: 'no-let', type: 'audit', plugin: 'eslint' }], }, ], @@ -367,15 +367,15 @@ describe('categoriesDetailsSection', () => { }); describe('binaryIconSuffix', () => { - it('should return passing binarySuffix if score is 1 and isBinary is true', () => { - expect(binaryIconSuffix(1, true)).toBe(' ✅'); + it('should return passing binarySuffix when score >= scoreTarget', () => { + expect(binaryIconSuffix(1, 1)).toBe(' ✅'); }); - it('should return failing binarySuffix if score is < then 1 and isBinary is true', () => { - expect(binaryIconSuffix(0, true)).toBe(' ❌'); + it('should return failing binarySuffix when score < scoreTarget', () => { + expect(binaryIconSuffix(0, 1)).toBe(' ❌'); }); - it('should return NO binarySuffix if score is 1 and isBinary is false', () => { - expect(binaryIconSuffix(1, false)).toBe(''); + it('should return NO binarySuffix when scoreTarget is undefined', () => { + expect(binaryIconSuffix(1, undefined)).toBe(''); }); }); diff --git a/packages/utils/src/lib/reports/generate-md-report.unit.test.ts b/packages/utils/src/lib/reports/generate-md-report.unit.test.ts index daff690c7..91f47f7c9 100644 --- a/packages/utils/src/lib/reports/generate-md-report.unit.test.ts +++ b/packages/utils/src/lib/reports/generate-md-report.unit.test.ts @@ -902,7 +902,7 @@ module.exports = { title: 'SEO', slug: 'seo', score: 1, - isBinary: true, + scoreTarget: 1, refs: [ { slug: 'is-crawlable', @@ -912,20 +912,6 @@ module.exports = { }, ], }, - { - title: 'PWA', - slug: 'pwa', - score: 0, - isBinary: true, - refs: [ - { - slug: 'splash-screen', - plugin: 'lighthouse', - type: 'audit', - weight: 1, - }, - ], - }, ], }), ).toMatchSnapshot(); diff --git a/packages/utils/src/lib/reports/log-stdout-summary.ts b/packages/utils/src/lib/reports/log-stdout-summary.ts index 4e7b481a9..0c50499bb 100644 --- a/packages/utils/src/lib/reports/log-stdout-summary.ts +++ b/packages/utils/src/lib/reports/log-stdout-summary.ts @@ -13,7 +13,7 @@ import type { ScoredReport } from './types.js'; import { applyScoreColor, countCategoryAudits, - targetScoreIcon, + scoreTargetIcon, } from './utils.js'; function log(msg = ''): void { @@ -101,9 +101,9 @@ export function logCategories({ }: Required>): void { const hAlign = (idx: number) => (idx === 0 ? 'left' : 'right'); - const rows = categories.map(({ title, score, refs, isBinary }) => [ + const rows = categories.map(({ title, score, scoreTarget, refs }) => [ title, - `${binaryIconPrefix(score, isBinary)}${applyScoreColor({ score })}`, + `${binaryIconPrefix(score, scoreTarget)}${applyScoreColor({ score })}`, countCategoryAudits(refs, plugins), ]); const table = ui().table(); @@ -130,12 +130,11 @@ export function logCategories({ log(); } -// @TODO refactor `isBinary: boolean` to `targetScore: number` #713 export function binaryIconPrefix( score: number, - isBinary: boolean | undefined, + scoreTarget: number | undefined, ): string { - return targetScoreIcon(score, isBinary ? 1 : undefined, { + return scoreTargetIcon(score, scoreTarget, { passIcon: bold(green('✓')), failIcon: bold(red('✗')), postfix: ' ', diff --git a/packages/utils/src/lib/reports/log-stdout-summary.unit.test.ts b/packages/utils/src/lib/reports/log-stdout-summary.unit.test.ts index 51b1e2777..302fa4328 100644 --- a/packages/utils/src/lib/reports/log-stdout-summary.unit.test.ts +++ b/packages/utils/src/lib/reports/log-stdout-summary.unit.test.ts @@ -72,13 +72,13 @@ describe('logCategories', () => { expect(output).toContain('1'); }); - it('should list categories with failed isBinary', () => { + it('should list categories with score < scoreTarget', () => { const categories: ScoredReport['categories'] = [ { slug: 'performance', score: 0.42, + scoreTarget: 1, title: 'Performance', - isBinary: true, refs: [ { slug: 'total-blocking-time', @@ -116,13 +116,13 @@ describe('logCategories', () => { expect(output).toContain('1'); }); - it('should list categories with passed isBinary', () => { + it('should list categories with score >= scoreTarget', () => { const categories: ScoredReport['categories'] = [ { slug: 'performance', score: 1, + scoreTarget: 1, title: 'Performance', - isBinary: true, refs: [ { slug: 'total-blocking-time', @@ -260,19 +260,15 @@ describe('logPlugins', () => { }); describe('binaryIconPrefix', () => { - it('should return passing binaryPrefix if score is 1 and isBinary is true', () => { - expect(removeColorCodes(binaryIconPrefix(1, true))).toBe('✓ '); + it('should return passing binaryPrefix when score >= scoreTarget', () => { + expect(removeColorCodes(binaryIconPrefix(1, 1))).toBe('✓ '); }); - it('should return failing binaryPrefix if score is < then 1 and isBinary is true', () => { - expect(removeColorCodes(binaryIconPrefix(0, true))).toBe('✗ '); + it('should return failing binaryPrefix when score < scoreTarget', () => { + expect(removeColorCodes(binaryIconPrefix(0, 1))).toBe('✗ '); }); - it('should return NO binaryPrefix if score is 1 and isBinary is false', () => { - expect(binaryIconPrefix(1, false)).toBe(''); - }); - - it('should return NO binaryPrefix when isBinary is undefined', () => { + it('should return NO binaryPrefix when scoreTarget is undefined', () => { expect(binaryIconPrefix(1, undefined)).toBe(''); }); }); diff --git a/packages/utils/src/lib/reports/utils.ts b/packages/utils/src/lib/reports/utils.ts index fbb0aec0f..65e6a19b3 100644 --- a/packages/utils/src/lib/reports/utils.ts +++ b/packages/utils/src/lib/reports/utils.ts @@ -297,9 +297,9 @@ export function applyScoreColor( : style.bold(style.red(formattedScore)); } -export function targetScoreIcon( +export function scoreTargetIcon( score: number, - targetScore?: number, + scoreTarget?: number, options: { passIcon?: string; failIcon?: string; @@ -307,14 +307,14 @@ export function targetScoreIcon( postfix?: string; } = {}, ): string { - if (targetScore != null) { + if (scoreTarget != null) { const { passIcon = '✅', failIcon = '❌', prefix = '', postfix = '', } = options; - if (score >= targetScore) { + if (score >= scoreTarget) { return `${prefix}${passIcon}${postfix}`; } return `${prefix}${failIcon}${postfix}`; diff --git a/packages/utils/src/lib/reports/utils.unit.test.ts b/packages/utils/src/lib/reports/utils.unit.test.ts index 087edb82a..a983af370 100644 --- a/packages/utils/src/lib/reports/utils.unit.test.ts +++ b/packages/utils/src/lib/reports/utils.unit.test.ts @@ -28,8 +28,8 @@ import { roundValue, scoreFilter, scoreMarker, + scoreTargetIcon, severityMarker, - targetScoreIcon, } from './utils.js'; describe('scoreFilter', () => { @@ -497,42 +497,42 @@ describe('applyScoreColor', () => { }); }); -describe('targetScoreIcon', () => { - it('should return target score icon "✅" for passed score', () => { - expect(targetScoreIcon(0.42, 0.4)).toBe('✅'); +describe('scoreTargetIcon', () => { + it('should return score target icon "✅" for passed score', () => { + expect(scoreTargetIcon(0.42, 0.4)).toBe('✅'); }); - it('should return target score icon "❌" for failed score', () => { - expect(targetScoreIcon(0.42, 0.5)).toBe('❌'); + it('should return score target icon "❌" for failed score', () => { + expect(scoreTargetIcon(0.42, 0.5)).toBe('❌'); }); - it('should return prefixed target score icon if prefix is provided', () => { + it('should return prefixed score target icon if prefix is provided', () => { expect( - targetScoreIcon(0.42, 0.1, { + scoreTargetIcon(0.42, 0.1, { prefix: '<', }), ).toBe('<✅'); }); - it('should return prefixed target score icon if postfix is provided', () => { + it('should return prefixed score target icon if postfix is provided', () => { expect( - targetScoreIcon(0.42, 0.1, { + scoreTargetIcon(0.42, 0.1, { postfix: '>', }), ).toBe('✅>'); }); - it('should return pre and postfixed target score icon if both are provided', () => { + it('should return pre and postfixed score target icon if both are provided', () => { expect( - targetScoreIcon(0.42, 0.1, { + scoreTargetIcon(0.42, 0.1, { prefix: '<', postfix: '>', }), ).toBe('<✅>'); }); - it('should return no target score icon if no targetScore is provided', () => { - expect(targetScoreIcon(0.42)).toBe(''); + it('should return no score target icon if no scoreTarget is provided', () => { + expect(scoreTargetIcon(0.42)).toBe(''); }); });