From 3fe94c499a6cba65917a85f59148f901a75771f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Chalk?= Date: Wed, 13 Mar 2024 16:34:20 +0100 Subject: [PATCH] test(test-utils): add alternative reports diff mock (has regressions as well) --- .../utils/dynamic-mocks/eslint-plugin.mock.ts | 2 +- .../utils/dynamic-mocks/report-diff.mock.ts | 94 ++++++++++++++++++- 2 files changed, 94 insertions(+), 2 deletions(-) diff --git a/testing/test-utils/src/lib/utils/dynamic-mocks/eslint-plugin.mock.ts b/testing/test-utils/src/lib/utils/dynamic-mocks/eslint-plugin.mock.ts index a9642d447..8b93a92af 100644 --- a/testing/test-utils/src/lib/utils/dynamic-mocks/eslint-plugin.mock.ts +++ b/testing/test-utils/src/lib/utils/dynamic-mocks/eslint-plugin.mock.ts @@ -87,7 +87,7 @@ export function eslintPluginReportAltMock(): PluginReport { }; } -type ESLintAuditSlug = keyof typeof ESLINT_AUDITS_MAP; +export type ESLintAuditSlug = keyof typeof ESLINT_AUDITS_MAP; export function eslintAuditRefMock( slug: ESLintAuditSlug, diff --git a/testing/test-utils/src/lib/utils/dynamic-mocks/report-diff.mock.ts b/testing/test-utils/src/lib/utils/dynamic-mocks/report-diff.mock.ts index 6b30de6cb..57864671a 100644 --- a/testing/test-utils/src/lib/utils/dynamic-mocks/report-diff.mock.ts +++ b/testing/test-utils/src/lib/utils/dynamic-mocks/report-diff.mock.ts @@ -8,7 +8,7 @@ import { COMMIT_ALT_MOCK, COMMIT_MOCK } from '../commit.mock'; import { CATEGORIES_MAP, CATEGORY_SLUGS, - type CategorySlug, + CategorySlug, } from './categories.mock'; import { ESLINT_AUDITS_FIXED_SLUGS, @@ -18,6 +18,7 @@ import { import { ESLINT_PLUGIN_GROUP_MAX_LINES, ESLINT_PLUGIN_META, + ESLintAuditSlug, } from './eslint-plugin.mock'; import { LIGHTHOUSE_AUDITS_CHANGES, @@ -155,6 +156,97 @@ export function reportsDiffMock(): ReportsDiff { }; } +export function reportsDiffAltMock(): ReportsDiff { + const originalDiff = reportsDiffMock(); + return { + ...originalDiff, + categories: { + changed: [ + { + slug: 'performance' satisfies CategorySlug, + title: CATEGORIES_MAP['performance'].title, + scores: { before: 0.92, after: 0.94, diff: 0.02 }, + }, + { + slug: 'bug-prevention' satisfies CategorySlug, + title: CATEGORIES_MAP['bug-prevention'].title, + scores: { before: 0.68, after: 0.63, diff: -0.05 }, + }, + ], + unchanged: [ + { + slug: 'code-style' satisfies CategorySlug, + title: CATEGORIES_MAP['code-style'].title, + score: 0.54, + }, + ], + added: [], + removed: [], + }, + groups: { + changed: [ + { + slug: LH_PLUGIN_GROUP_PERFORMANCE.slug, + title: LH_PLUGIN_GROUP_PERFORMANCE.title, + plugin: { slug: LH_PLUGIN_META.slug, title: LH_PLUGIN_META.title }, + scores: { before: 0.92, after: 0.94, diff: 0.02 }, + }, + ], + unchanged: [ + { + slug: ESLINT_PLUGIN_GROUP_MAX_LINES.slug, + title: ESLINT_PLUGIN_GROUP_MAX_LINES.title, + plugin: { + slug: ESLINT_PLUGIN_META.slug, + title: ESLINT_PLUGIN_META.title, + }, + score: 0.5, + }, + ], + added: [], + removed: [], + }, + audits: { + changed: [ + { + slug: 'no-unused-vars' satisfies ESLintAuditSlug, + title: ESLINT_AUDITS_MAP['no-unused-vars'].title, + plugin: { + slug: ESLINT_PLUGIN_META.slug, + title: ESLINT_PLUGIN_META.title, + }, + scores: { before: 1, after: 0, diff: -1 }, + values: { before: 0, after: 1, diff: 1 }, + displayValues: { before: 'passed', after: '1 error' }, + }, + ...originalDiff.audits.changed.filter( + ({ plugin }) => plugin.slug === 'lighthouse', + ), + ], + unchanged: [ + ...ESLINT_AUDIT_SLUGS.filter(slug => slug !== 'no-unused-vars').map( + (slug): AuditResult => ({ + slug, + title: ESLINT_AUDITS_MAP[slug].title, + plugin: { + slug: ESLINT_PLUGIN_META.slug, + title: ESLINT_PLUGIN_META.title, + }, + score: ESLINT_AUDITS_MAP[slug].score, + value: ESLINT_AUDITS_MAP[slug].value, + displayValue: ESLINT_AUDITS_MAP[slug].displayValue, + }), + ), + ...originalDiff.audits.unchanged.filter( + ({ plugin }) => plugin.slug === 'lighthouse', + ), + ], + added: [], + removed: [], + }, + }; +} + function categoryScores(slug: CategorySlug): CategoryDiff['scores'] { switch (slug) { case 'performance':