Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add at risk section #49

Merged
merged 20 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from 10 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
32 changes: 32 additions & 0 deletions lib/extensions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*!
* Copyright (c) 2024 Digital Bazaar, Inc. All rights reserved.
*/
import {atRisk} from './utils.js';

/**
* Extensions are functions that extend test data reports.
* Extensions maybe toggled off or on.
*/
export const extensions = {
templateData: {
addAtRisk({templateData}) {
if(templateData.matrices.length) {
templateData.matrices = templateData.matrices.flatMap(addAtRisk);
}
}
}
};

function addAtRisk(matrix) {
const {rows = [], columns} = matrix;
const atRiskRows = rows.filter(({cells}) => atRisk(cells));
if(atRiskRows.length) {
return [matrix, {
...matrix,
title: matrix?.title + ' At Risk',
columns: [...columns],
rows: atRiskRows
}];
}
return [matrix];
}
9 changes: 9 additions & 0 deletions lib/generate.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**!
* Copyright (c) 2019-2022 Digital Bazaar, Inc. All rights reserved.
*/
import {extensions} from './extensions.js';
import {makeTemplate} from './handlebars.js';
import {getJson, getPartial, writeJSON} from './files.js';
import {findReports, makeTemplateData} from './handlers.js';
Expand All @@ -20,6 +21,14 @@ export async function makeReport({suite, stats, config}) {
const reports = findReports({suite});
const {summary = new Set()} = suite.suites.find(s => s.summary) || {};
const templateData = makeTemplateData({reports});
// seee if any template extensions have been registered
const templateExtensions = extensions.templateData;
if(templateExtensions) {
// run each registered extension on the templateData
for(const prop in templateExtensions) {
await templateExtensions[prop]({templateData});
}
}
templateData.respecConfig = config.respecConfig = await getJson(respecConfig);
templateData.title = title;
templateData.stats = stats;
Expand Down
4 changes: 3 additions & 1 deletion lib/handlebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import Handlebars from 'handlebars';
import {statusMarks} from './statusMarks.js';
import {formatJSON} from './files.js';
import {UTCDateTime} from './utils.js';
import {UTCDateTime, atRisk} from './utils.js';

// helpersFile is a path to a project specific helpers file.
const registerHelpers = ({config}) => {
Expand All @@ -25,6 +25,8 @@ const registerHelpers = ({config}) => {

Handlebars.registerHelper(
'getOptional', optional => optional ? 'optional' : 'not-optional');
// add a css class to rows that are at risk
Handlebars.registerHelper('atRisk', c => atRisk(c) ? 'at-risk' : 'confirmed');
try {
if(!helpersFile) {
return;
Expand Down
1 change: 1 addition & 0 deletions lib/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ export function formatTest(test, parentSuite = '') {
.trim();
return {
// optional means the test is non-normative
// FIXME remove this optional check in a major release
optional: false,
...test,
fullTitle,
Expand Down
5 changes: 5 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,8 @@ export const UTCDateTime = (lang = 'en-AU') => {
minute: 'numeric'
});
};

// at risk statements have less than 2 conforming implementations
export const atRisk = cells => !(cells.filter(
c => c.state === 'passed').length >= 2);

3 changes: 3 additions & 0 deletions templates/head.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,8 @@
align-items: center;
justify-content: center;
width: fit-content;
}
.at-risk {
opacity: 0.6;
}
</style>
Loading