Skip to content

Commit

Permalink
feat: aggregate metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentsenta committed Sep 6, 2023
1 parent b9b4655 commit 84cfbb1
Showing 1 changed file with 41 additions and 3 deletions.
44 changes: 41 additions & 3 deletions aggregate.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ lines = lines.filter((line) => {
// # extract test metadata
// action is output, and starts with ".* --- META: (.*)"
// see details in https://github.com/ipfs/gateway-conformance/pull/125
const getMetadata = (line) => {
const extractMetadata = (line) => {
const { Action, Output } = line;

if (Action !== "output") {
Expand All @@ -34,7 +34,7 @@ const getMetadata = (line) => {
}

lines = lines.map((line) => {
const metadata = getMetadata(line);
const metadata = extractMetadata(line);

if (!metadata) {
return line;
Expand Down Expand Up @@ -87,6 +87,44 @@ lines.forEach((line) => {
});
})

// prepare metadata up the tree
const metadataTree = {};

// sort lines so that the one with the longest path is processed first
const sortedLines = lines.sort((a, b) => {
return b.Path.length - a.Path.length;
});

sortedLines.forEach((line) => {
const { Path, Action, Metadata } = line;
let current = metadataTree;

if (Action !== "meta") {
return;
}

Path.forEach((path) => {
if (!current[path]) {
current[path] = {};
}
current = current[path];
current["meta"] = { ...current["meta"], ...Metadata };
});
});

const getMetadata = (path) => {
let current = metadataTree;

path.forEach((path) => {
if (!current[path]) {
return null;
}
current = current[path];
});

return current["meta"];
}

// # Drop all lines where the Test "Path" does not point to a leaf
// if the test has children then we don't really care about it's pass / fail / skip status,
// we'll aggregate its children results'
Expand Down Expand Up @@ -118,7 +156,7 @@ lines.forEach((line) => {
const key = path.join(" > ");

if (!current[key]) {
current[key] = { Path: path, "pass": 0, "fail": 0, "skip": 0, "total": 0, "meta": {} };
current[key] = { Path: path, "pass": 0, "fail": 0, "skip": 0, "total": 0, "meta": getMetadata(path) || {} };
}
current = current[key];

Expand Down

0 comments on commit 84cfbb1

Please sign in to comment.