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
9 changes: 5 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"node": ">=22.14"
},
"dependencies": {
"@code-pushup/portal-client": "^0.9.0",
"@code-pushup/portal-client": "^0.13.0",
"@isaacs/cliui": "^8.0.2",
"@nx/devkit": "19.8.13",
"@poppinss/cliui": "6.4.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"ansis": "^3.3.0"
},
"peerDependencies": {
"@code-pushup/portal-client": "^0.9.0"
"@code-pushup/portal-client": "^0.13.0"
},
"peerDependenciesMeta": {
"@code-pushup/portal-client": {
Expand Down
65 changes: 63 additions & 2 deletions packages/core/src/lib/implementation/report-to-gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,27 @@ import type {
TableAlignment as PortalTableAlignment,
AuditReportTableCell as PortalTableCell,
AuditReportTableColumn as PortalTableColumn,
AuditReportTree as PortalTree,
AuditReportTreeNode as PortalTreeNode,
TreeType as PortalTreeType,
SaveReportMutationVariables,
} from '@code-pushup/portal-client';
import type {
AuditReport,
BasicTree,
BasicTreeNode,
CategoryConfig,
CategoryRef,
CoverageTree,
CoverageTreeNode,
Group,
Issue,
IssueSeverity,
PluginReport,
Report,
Table,
TableAlignment,
Tree,
} from '@code-pushup/models';

export function reportToGQL(
Expand Down Expand Up @@ -75,7 +83,7 @@ function auditToGQL(audit: AuditReport): PortalAudit {
displayValue: formattedValue,
details,
} = audit;
const { issues, table } = details ?? {};
const { issues, table, trees } = details ?? {};
return {
slug,
title,
Expand All @@ -88,6 +96,7 @@ function auditToGQL(audit: AuditReport): PortalAudit {
details: {
...(issues && { issues: issues.map(issueToGQL) }),
...(table && { tables: [tableToGQL(table)] }),
...(trees && { trees: trees.map(treeToGQL) }),
},
}),
};
Expand Down Expand Up @@ -134,6 +143,57 @@ export function tableToGQL(table: Table): PortalTable {
};
}

export function treeToGQL(tree: Tree): PortalTree {
if (tree.type === 'coverage') {
return coverageTreeToGQL(tree);
}
return basicTreeToGQL(tree);
}

function basicTreeToGQL(tree: BasicTree): PortalTree {
return {
type: safeEnum<PortalTreeType>('Basic'),
...(tree.title && { title: tree.title }),
root: basicTreeNodeToGQL(tree.root),
};
}

function basicTreeNodeToGQL(node: BasicTreeNode): PortalTreeNode {
return {
name: node.name,
...(node.values && {
values: Object.entries(node.values).map(([key, value]) => ({
key,
value: value.toString(),
})),
}),
...(node.children?.length && {
children: node.children.map(basicTreeNodeToGQL),
}),
};
}

function coverageTreeToGQL(tree: CoverageTree): PortalTree {
return {
type: safeEnum<PortalTreeType>('Coverage'),
...(tree.title && { title: tree.title }),
root: coverageTreeNodeToGQL(tree.root),
};
}

function coverageTreeNodeToGQL(node: CoverageTreeNode): PortalTreeNode {
return {
name: node.name,
coverage: node.values.coverage,
...(node.values.missing?.length && {
missing: node.values.missing,
}),
...(node.children?.length && {
children: node.children.map(coverageTreeNodeToGQL),
}),
};
}

function categoryToGQL(category: CategoryConfig): PortalCategory {
return {
slug: category.slug,
Expand Down Expand Up @@ -188,7 +248,8 @@ function safeEnum<
| PortalCategoryRefType
| PortalIssueSeverity
| PortalIssueSourceType
| PortalTableAlignment,
| PortalTableAlignment
| PortalTreeType,
>(value: `${T}`): T {
return value as T;
}
122 changes: 121 additions & 1 deletion packages/core/src/lib/implementation/report-to-gql.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe } from 'vitest';
import { issueToGQL, tableToGQL } from './report-to-gql.js';
import { type AuditReportTree, TreeType } from '@code-pushup/portal-client';
import { issueToGQL, tableToGQL, treeToGQL } from './report-to-gql.js';

describe('issueToGQL', () => {
it('transforms issue to GraphQL input type', () => {
Expand Down Expand Up @@ -81,3 +82,122 @@ describe('tableToGQL', () => {
});
});
});

describe('treeToGQL', () => {
it('should transform basic tree', () => {
expect(
treeToGQL({
title: 'Critical request chain',
root: {
name: 'https://example.com',
children: [
{
name: 'https://example.com/styles/base.css',
values: { size: '2 kB', duration: 20 },
},
{
name: 'https://example.com/styles/theme.css',
values: { size: '10 kB', duration: 100 },
},
],
},
}),
).toStrictEqual<AuditReportTree>({
type: TreeType.Basic,
title: 'Critical request chain',
root: {
name: 'https://example.com',
children: [
{
name: 'https://example.com/styles/base.css',
values: [
{ key: 'size', value: '2 kB' },
{ key: 'duration', value: '20' },
],
},
{
name: 'https://example.com/styles/theme.css',
values: [
{ key: 'size', value: '10 kB' },
{ key: 'duration', value: '100' },
],
},
],
},
});
});

it('should transform coverage tree', () => {
expect(
treeToGQL({
type: 'coverage',
title: 'Function coverage',
root: {
name: '.',
values: { coverage: 0.7 },
children: [
{
name: 'src',
values: { coverage: 0.7 },
children: [
{
name: 'App.tsx',
values: {
coverage: 0.8,
missing: [
{
startLine: 42,
endLine: 50,
name: 'login',
kind: 'function',
},
],
},
},
{
name: 'index.ts',
values: {
coverage: 0,
missing: [{ startLine: 1, endLine: 10 }],
},
},
],
},
],
},
}),
).toStrictEqual<AuditReportTree>({
type: TreeType.Coverage,
title: 'Function coverage',
root: {
name: '.',
coverage: 0.7,
children: [
{
name: 'src',
coverage: 0.7,
children: [
{
name: 'App.tsx',
coverage: 0.8,
missing: [
{
startLine: 42,
endLine: 50,
name: 'login',
kind: 'function',
},
],
},
{
name: 'index.ts',
coverage: 0,
missing: [{ startLine: 1, endLine: 10 }],
},
],
},
],
},
});
});
});
2 changes: 1 addition & 1 deletion packages/models/src/lib/tree.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('treeSchema', () => {
expect(() =>
treeSchema.parse({
type: 'coverage',
title: 'Critical request chain',
title: 'Function coverage',
root: {
name: '.',
values: { coverage: 0.7 },
Expand Down