Skip to content

Commit

Permalink
feat(chartReport): include node-v (#53)
Browse files Browse the repository at this point in the history
* feat(chartReport): include node-v

* test: add test for chartRepport

* fix: code format
  • Loading branch information
AugustinMauroy authored Jan 20, 2025
1 parent 2d0d11a commit 695842e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/reporter/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function drawBar(label, value, total, samples, length = 30) {
}

const environment = {
nodeVersion: `Node.js version: ${process.version}`,
platform: `${platform()} ${arch()}`,
hardware: `${cpus().length} vCPUs | ${(totalmem() / 1024 ** 3).toFixed(1)}GB Mem`,
};
Expand All @@ -32,9 +33,11 @@ function chartReport(results) {
const maxOpsSec = Math.max(...results.map((b) => b.opsSec));

process.stdout.write(
`Platform: ${environment.platform}\n` +
`${environment.nodeVersion}\n` +
`Platform: ${environment.platform}\n` +
`CPU Cores: ${environment.hardware}\n\n`,
);

for (const result of results) {
drawBar(result.name, result.opsSec, maxOpsSec, result.histogram.samples);
}
Expand Down
6 changes: 6 additions & 0 deletions test/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ describe("chartReport outputs benchmark results as a bar chart", async (t) => {
it("should include sample count", () => {
assert.ok(output.includes("samples"));
});

it("should include Node.js version", () => {
const regex = /Node\.js version: v\d+\.\d+\.\d+/;

assert.ok(output.match(regex));
});
});

describe("htmlReport should create a file", async (t) => {
Expand Down

0 comments on commit 695842e

Please sign in to comment.