Skip to content

Commit

Permalink
make the test results fit in a table with timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
Gioyik committed Sep 27, 2022
1 parent 9c6102b commit 75ab9c5
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/test-runner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const debug = require("debug")("zombie::test-runner");
const { assert, expect } = chai;
const { Test, Suite } = Mocha;
const mocha = new Mocha();
mocha.reporter("../utils/tableReporter");

import { JSDOM } from "jsdom";
import { Environment } from "nunjucks";
Expand Down
49 changes: 49 additions & 0 deletions src/utils/tableReporter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import Mocha from "mocha";

import { CreateLogTable } from "../utils/tableCli";
import { decorators } from "../utils/colors";

const { EVENT_RUN_END, EVENT_TEST_FAIL, EVENT_TEST_PASS } =
Mocha.Runner.constants;

interface TableReporterProps {
runner: Mocha.Runner;
}

export class TableReporter {
constructor({ runner }: TableReporterProps) {
const stats: any = runner.stats;

const logTable = new CreateLogTable({
head: [
{
colSpan: 2,
hAlign: "center",
content: `${decorators.green("Test Results")}`,
},
],
colWidths: [30, 100],
});

runner
.on(EVENT_TEST_PASS, (test: any) => {
logTable.pushTo([[new Date(), test.fullTitle()]]);
})
.on(EVENT_TEST_FAIL, (test: any, err: any) => {
logTable.pushTo([[new Date(), test.fullTitle()]]);
})
.once(EVENT_RUN_END, () => {
logTable.pushTo([
[
{
colSpan: 2,
hAlign: "left",
content: `end: ${stats.passes}/${
stats.passes + stats.failures
} ok`,
},
],
]);
});
}
}

0 comments on commit 75ab9c5

Please sign in to comment.