Skip to content

Commit

Permalink
test: fix the plugin api test
Browse files Browse the repository at this point in the history
  • Loading branch information
naugtur authored and RafaelGSS committed Nov 16, 2024
1 parent c16cf34 commit be8ec69
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions test/plugin-api-doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { describe, it } = require("node:test");
const assert = require("node:assert");

class ExamplePlugin {
#aggregation = 0;
#aggregation = {};
constructor() {}

isSupported() {
Expand All @@ -24,21 +24,24 @@ class ExamplePlugin {
];
}

onCompleteBenchmark([time, iterations, results]) {
this.#aggregation += results.example;
onCompleteBenchmark([time, iterations, results], { name }) {
if (undefined === this.#aggregation[name]) {
this.#aggregation[name] = 0;
}
this.#aggregation[name] += results.example;
}

toString() {
return "ExamplePlugin";
}

getReport() {
return `examplePlugin report`;
getReport(name) {
return `examplePlugin report for ${name}`;
}

getResult() {
getResult(name) {
return {
examplePluginAggregation: this.#aggregation,
examplePluginAggregation: this.#aggregation[name],
};
}
}
Expand All @@ -61,10 +64,11 @@ describe("plugin API", async () => {
assert.deepStrictEqual(recordedMethodSignatures, [
"afterClockTemplate({awaitOrEmpty, bench, context, timer})",
"beforeClockTemplate({awaitOrEmpty, bench, context, timer})",
"getReport()",
"getResult()",
"getReport(string)",
"getResult(string)",
"isSupported()",
"onCompleteBenchmark([number, number, object])",
"onCompleteBenchmark([number, number, object], {fn, maxTime, minTime, name, plugins})",
"toJSON(string)",
"toString()",
]);
});
Expand All @@ -74,7 +78,10 @@ describe("plugin API", async () => {
it("aggregates results", async () => {
console.log("Benchmark results plugins field:", bench1.plugins);
assert(bench1.plugins[0].result.examplePluginAggregation > 1);
assert.strictEqual(bench1.plugins[0].report, "examplePlugin report");
assert.strictEqual(
bench1.plugins[0].report,
"examplePlugin report for task1",
);
});
});

Expand Down Expand Up @@ -106,7 +113,7 @@ function printExcerptFromHistory(n = 25) {
([name, count, args]) =>
`${name} ${count > 1 ? "x" + count : ""}${
args ? " with args: " + args : ""
}`
}`,
)
.join("\n| ");
console.log("+----------------------------------");
Expand All @@ -124,9 +131,11 @@ function getSignatures() {
if (!a) return "";
if (Array.isArray(a))
return "[" + a.map((a) => typeof a).join(", ") + "]";
return "{" + Object.keys(a).sort().join(", ") + "}";
if (typeof a === "object")
return "{" + Object.keys(a).sort().join(", ") + "}";
return typeof a;
})
.join(", ")})`
.join(", ")})`,
)
.sort();
}
Expand Down

0 comments on commit be8ec69

Please sign in to comment.