Skip to content

Commit 960cb87

Browse files
jdmarshallRafaelGSS
authored andcommitted
feat: export to<format> functions and rework some of the tests.
1 parent db850ca commit 960cb87

File tree

2 files changed

+23
-38
lines changed

2 files changed

+23
-38
lines changed

lib/report.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
const { textReport, toText } = require("./reporter/text");
2-
const { prettyReport, toPretty } = require("./reporter/pretty");
3-
const { chartReport, toChart } = require("./reporter/chart");
4-
const { htmlReport } = require("./reporter/html");
5-
const { jsonReport, toJSON } = require("./reporter/json");
6-
const { csvReport, toCSV } = require("./reporter/csv");
1+
const textReport = require("./reporter/text");
2+
const prettyReport = require("./reporter/pretty");
3+
const chartReport = require("./reporter/chart");
4+
const htmlReport = require("./reporter/html");
5+
const jsonReport = require("./reporter/json");
6+
const csvReport = require("./reporter/csv");
77

88
/**
99
* @typedef {Object} BenchmarkResult
@@ -24,11 +24,10 @@ const { csvReport, toCSV } = require("./reporter/csv");
2424
* @property {function(BenchmarkResult[]): string} csvReport - Generates a CSV report of benchmark results
2525
*/
2626
module.exports = {
27-
chartReport,
28-
textReport,
29-
prettyReport,
30-
htmlReport,
31-
jsonReport,
32-
csvReport,
33-
toCSV,
27+
...chartReport,
28+
...textReport,
29+
...prettyReport,
30+
...htmlReport,
31+
...jsonReport,
32+
...csvReport,
3433
};

test/reporter.js

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@ const { Suite } = require("../lib");
55

66
const {
77
chartReport,
8+
toChart,
89
htmlReport,
910
jsonReport,
11+
toJSON,
1012
csvReport,
13+
toCSV,
1114
prettyReport,
15+
toPretty,
1216
textReport,
13-
toCSV,
17+
toText,
1418
} = require("../lib/report");
1519

1620
const { analyze, summarize } = require("../lib/utils/analyze.js");
@@ -463,17 +467,11 @@ describe("baseline comparisons", async (t) => {
463467
});
464468
});
465469

466-
describe("for prettyReport", async (t) => {
470+
describe("for pretty report", async (t) => {
467471
let output = "";
468472

469473
before(async () => {
470-
const originalStdoutWrite = process.stdout.write;
471-
process.stdout.write = (data) => {
472-
output += data;
473-
};
474-
475-
prettyReport(results);
476-
process.stdout.write = originalStdoutWrite;
474+
output = toPretty(results);
477475
});
478476

479477
it("should include a summary section", () => {
@@ -491,17 +489,11 @@ describe("baseline comparisons", async (t) => {
491489
});
492490
});
493491

494-
describe("for textReport", async (t) => {
492+
describe("for text Report", async (t) => {
495493
let output = "";
496494

497495
before(async () => {
498-
const originalStdoutWrite = process.stdout.write;
499-
process.stdout.write = (data) => {
500-
output += data;
501-
};
502-
503-
textReport(results);
504-
process.stdout.write = originalStdoutWrite;
496+
output = toText(results);
505497
});
506498

507499
it("should include a summary section", () => {
@@ -519,17 +511,11 @@ describe("baseline comparisons", async (t) => {
519511
});
520512
});
521513

522-
describe("for chartReport", async (t) => {
514+
describe("for chart Report", async (t) => {
523515
let output = "";
524516

525517
before(async () => {
526-
const originalStdoutWrite = process.stdout.write;
527-
process.stdout.write = (data) => {
528-
output += data;
529-
};
530-
531-
chartReport(results, { labelWidth: 30 });
532-
process.stdout.write = originalStdoutWrite;
518+
output = toChart(results, { labelWidth: 30 });
533519
});
534520

535521
it("should include a summary section", () => {

0 commit comments

Comments
 (0)