Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ exports[`transformGQLReport > should convert full GraphQL report to valid report
{
"categories": [
{
"isBinary": false,
"refs": [
{
"plugin": "eslint",
Expand All @@ -17,7 +16,6 @@ exports[`transformGQLReport > should convert full GraphQL report to valid report
"title": "Code style",
},
{
"isBinary": false,
"refs": [
{
"plugin": "bundle-stats",
Expand Down
4 changes: 3 additions & 1 deletion packages/ci/src/lib/portal/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => ({
Expand All @@ -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 }),
};
}

Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/lib/implementation/report-to-gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
18 changes: 9 additions & 9 deletions packages/models/docs/models-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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._

Expand Down
41 changes: 18 additions & 23 deletions packages/models/src/lib/category-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
} from './implementation/checks.js';
import {
metaSchema,
nonnegativeNumberSchema,
scorableSchema,
slugSchema,
weightedRefSchema,
Expand All @@ -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<typeof categoryRefSchema>;

export const categoryConfigSchema = scorableSchema(
Expand All @@ -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<typeof categoryConfigSchema>;

Expand Down
1 change: 0 additions & 1 deletion packages/models/src/lib/category-config.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
14 changes: 4 additions & 10 deletions packages/plugin-lighthouse/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,6 @@ export default {
title: 'SEO',
refs: [lighthouseGroupRef('seo')],
},
{
slug: 'pwa',
title: 'PWA',
isBinary: true,
refs: [lighthouseGroupRef('pwa')],
},
],
};
```
Expand All @@ -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)],
},
],
};
Expand Down
1 change: 0 additions & 1 deletion packages/plugin-lighthouse/src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export const LIGHTHOUSE_GROUP_SLUGS = [
'accessibility',
'best-practices',
'seo',
'pwa',
] as const;

export const SINGLE_URL_THRESHOLD = 1;
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,6 @@ describe('mergeLighthouseCategories', () => {
title: 'Performance',
description: 'Website performance metrics',
docsUrl: 'https://docs.example.com/performance',
isBinary: true,
refs: [
{
type: 'group',
Expand All @@ -336,14 +335,14 @@ describe('mergeLighthouseCategories', () => {
weight: 1,
},
],
scoreTarget: 1,
},
])[0],
).toEqual({
slug: 'performance',
title: 'Performance',
description: 'Website performance metrics',
docsUrl: 'https://docs.example.com/performance',
isBinary: true,
refs: [
{
type: 'group',
Expand All @@ -358,6 +357,7 @@ describe('mergeLighthouseCategories', () => {
weight: 1,
},
],
scoreTarget: 1,
});
});
});
Expand Down Expand Up @@ -689,7 +689,6 @@ describe('expandAggregatedCategory', () => {
title: 'Performance',
description: 'Website performance metrics',
docsUrl: 'https://docs.example.com',
isBinary: true,
refs: [
{
type: 'group',
Expand All @@ -698,6 +697,7 @@ describe('expandAggregatedCategory', () => {
weight: 1,
},
],
scoreTarget: 1,
};
expect(
expandAggregatedCategory(category, { urlCount: 1, weights: { 1: 1 } }),
Expand Down
2 changes: 0 additions & 2 deletions packages/utils/perf/score-report/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ function minimalReport(opt?: MinimalReportOptions): Report {
slug: `${AUDIT_P1_PREFIX}${idx}`,
weight: 1,
})),
isBinary: false,
},
{
slug: 'c2_',
Expand All @@ -165,7 +164,6 @@ function minimalReport(opt?: MinimalReportOptions): Report {
slug: `${AUDIT_P2_PREFIX}${idx}`,
weight: 1,
})),
isBinary: false,
},
],
plugins: [
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down Expand Up @@ -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 |

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
getPluginNameFromSlug,
scoreFilter,
scoreMarker,
targetScoreIcon,
scoreTargetIcon,
} from './utils.js';

export function categoriesOverviewSection(
Expand All @@ -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(),
]),
);
Expand All @@ -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 => {
Expand Down Expand Up @@ -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: ' ' });
}
Loading
Loading