From 7eed3d7add9acd7ec3bcd9d86b56283cd969c17b Mon Sep 17 00:00:00 2001 From: Giovanny Andres Gongora Granada Date: Mon, 26 Sep 2022 21:29:38 +0200 Subject: [PATCH 1/8] make the test results fit in a table with timestamps --- .gitignore | 3 +- src/test-runner/index.ts | 3 ++ src/utils/tableReporter.ts | 64 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 src/utils/tableReporter.ts diff --git a/.gitignore b/.gitignore index c2a49246b..f3b13d9c6 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ node_modules dist log.md .env -bins \ No newline at end of file +bins +.DS_Store diff --git a/src/test-runner/index.ts b/src/test-runner/index.ts index 37ee23ad6..74be9e333 100644 --- a/src/test-runner/index.ts +++ b/src/test-runner/index.ts @@ -246,6 +246,9 @@ export async function run( test.timeout(0); } + // pass the file path, don't load the reporter as a module + mocha.reporter(process.cwd() + "/dist/utils/tableReporter"); + // run mocha.run(exitMocha); } diff --git a/src/utils/tableReporter.ts b/src/utils/tableReporter.ts new file mode 100644 index 000000000..d810550b6 --- /dev/null +++ b/src/utils/tableReporter.ts @@ -0,0 +1,64 @@ +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; + stats: Mocha.Stats; + on: any; +} + +class TableReporter { + constructor(runner: TableReporterProps) { + const stats = 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: Mocha.Test) => { + logTable.pushTo([ + [ + new Date().toLocaleString(), + `✅ ${test.title} ${decorators.red(`(${test.duration}ms)`)}`, + ], + ]); + }) + .on(EVENT_TEST_FAIL, (test: Mocha.Test, err: any) => { + logTable.pushTo([ + [ + new Date().toLocaleString(), + `❌ ${test.title} ${decorators.red(`(${test.duration}ms)`)}`, + ], + ]); + }) + .once(EVENT_RUN_END, () => { + logTable.pushTo([ + [ + { + colSpan: 2, + hAlign: "left", + content: `Result: ${stats.passes}/${ + stats.passes + stats.failures + }`, + }, + ], + ]); + logTable.print(); + }); + } +} + +module.exports = TableReporter; From 204d65f87bb244802b08684c5183eac01fabb808 Mon Sep 17 00:00:00 2001 From: wirednkod Date: Mon, 17 Oct 2022 09:50:15 +0300 Subject: [PATCH 2/8] run linter --- src/utils/tableReporter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/tableReporter.ts b/src/utils/tableReporter.ts index d810550b6..70e4f2a3a 100644 --- a/src/utils/tableReporter.ts +++ b/src/utils/tableReporter.ts @@ -1,7 +1,7 @@ import Mocha from "mocha"; -import { CreateLogTable } from "../utils/tableCli"; import { decorators } from "../utils/colors"; +import { CreateLogTable } from "../utils/tableCli"; const { EVENT_RUN_END, EVENT_TEST_FAIL, EVENT_TEST_PASS } = Mocha.Runner.constants; From 4164833b23ddb0c9c8c9ac5dc8ce191230e3015b Mon Sep 17 00:00:00 2001 From: wirednkod Date: Mon, 17 Oct 2022 10:16:39 +0300 Subject: [PATCH 3/8] Test fix of gitlab tests --- src/test-runner/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test-runner/index.ts b/src/test-runner/index.ts index 0e64ef174..5f1ae1c9e 100644 --- a/src/test-runner/index.ts +++ b/src/test-runner/index.ts @@ -223,7 +223,7 @@ export async function run( } // pass the file path, don't load the reporter as a module - mocha.reporter(process.cwd() + "/dist/utils/tableReporter"); + mocha.reporter("../utils/tableReporter"); // run mocha.run(exitMocha); From 1a8b358a563f14f2da7d692edebab9b2c349f633 Mon Sep 17 00:00:00 2001 From: wirednkod Date: Mon, 17 Oct 2022 10:48:01 +0300 Subject: [PATCH 4/8] Revert url changes --- src/test-runner/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test-runner/index.ts b/src/test-runner/index.ts index 5f1ae1c9e..0e64ef174 100644 --- a/src/test-runner/index.ts +++ b/src/test-runner/index.ts @@ -223,7 +223,7 @@ export async function run( } // pass the file path, don't load the reporter as a module - mocha.reporter("../utils/tableReporter"); + mocha.reporter(process.cwd() + "/dist/utils/tableReporter"); // run mocha.run(exitMocha); From 99823bd8b410f03c0e4837d3b9bc143024a55c06 Mon Sep 17 00:00:00 2001 From: Javier Viola Date: Mon, 17 Oct 2022 09:19:54 -0300 Subject: [PATCH 5/8] try fix reporter file path --- src/test-runner/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test-runner/index.ts b/src/test-runner/index.ts index 0e64ef174..74fc10944 100644 --- a/src/test-runner/index.ts +++ b/src/test-runner/index.ts @@ -223,7 +223,8 @@ export async function run( } // pass the file path, don't load the reporter as a module - mocha.reporter(process.cwd() + "/dist/utils/tableReporter"); + const resolvedReporterPath = path.resolve(__dirname, "../utils/tableReporter"); + mocha.reporter(resolvedReporterPath); // run mocha.run(exitMocha); From 7e89d96c7cbe4d6cfef45f1b21626384e95e3d64 Mon Sep 17 00:00:00 2001 From: Javier Viola Date: Mon, 17 Oct 2022 10:20:52 -0300 Subject: [PATCH 6/8] fmt --- src/test-runner/index.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/test-runner/index.ts b/src/test-runner/index.ts index 74fc10944..3764dfe31 100644 --- a/src/test-runner/index.ts +++ b/src/test-runner/index.ts @@ -223,7 +223,10 @@ export async function run( } // pass the file path, don't load the reporter as a module - const resolvedReporterPath = path.resolve(__dirname, "../utils/tableReporter"); + const resolvedReporterPath = path.resolve( + __dirname, + "../utils/tableReporter", + ); mocha.reporter(resolvedReporterPath); // run From d28098a86521b4cde358ec4dbf7c2566b6aae8c2 Mon Sep 17 00:00:00 2001 From: Giovanny Gongora Date: Tue, 18 Oct 2022 07:56:30 +0200 Subject: [PATCH 7/8] wip --- src/test-runner/index.ts | 5 +--- .../{tableReporter.ts => testReporter.ts} | 24 +++++++++++++++---- 2 files changed, 20 insertions(+), 9 deletions(-) rename src/utils/{tableReporter.ts => testReporter.ts} (69%) diff --git a/src/test-runner/index.ts b/src/test-runner/index.ts index 3764dfe31..ac9415c7e 100644 --- a/src/test-runner/index.ts +++ b/src/test-runner/index.ts @@ -223,10 +223,7 @@ export async function run( } // pass the file path, don't load the reporter as a module - const resolvedReporterPath = path.resolve( - __dirname, - "../utils/tableReporter", - ); + const resolvedReporterPath = path.resolve(__dirname, "../utils/testReporter"); mocha.reporter(resolvedReporterPath); // run diff --git a/src/utils/tableReporter.ts b/src/utils/testReporter.ts similarity index 69% rename from src/utils/tableReporter.ts rename to src/utils/testReporter.ts index 70e4f2a3a..b975e66d8 100644 --- a/src/utils/tableReporter.ts +++ b/src/utils/testReporter.ts @@ -3,17 +3,18 @@ import Mocha from "mocha"; import { decorators } from "../utils/colors"; import { CreateLogTable } from "../utils/tableCli"; -const { EVENT_RUN_END, EVENT_TEST_FAIL, EVENT_TEST_PASS } = +const { EVENT_RUN_END, EVENT_TEST_FAIL, EVENT_TEST_PASS, EVENT_RUN_BEGIN } = Mocha.Runner.constants; -interface TableReporterProps { +interface TestReporterProps { runner: Mocha.Runner; stats: Mocha.Stats; on: any; + once: any; } -class TableReporter { - constructor(runner: TableReporterProps) { +class TestReporter { + constructor(runner: TestReporterProps) { const stats = runner.stats!; const logTable = new CreateLogTable({ @@ -27,7 +28,20 @@ class TableReporter { colWidths: [30, 100], }); + let announcement = new CreateLogTable({ + colWidths: [120], + }); + announcement.pushToPrint([ + [ + decorators.green( + "🛎️ Tests are currently running. Results will appear at the end", + ), + ], + ]); runner + .once(EVENT_RUN_BEGIN, () => { + announcement.print(); + }) .on(EVENT_TEST_PASS, (test: Mocha.Test) => { logTable.pushTo([ [ @@ -61,4 +75,4 @@ class TableReporter { } } -module.exports = TableReporter; +module.exports = TestReporter; From a78d413010673ecda36dbd1632218096f9067656 Mon Sep 17 00:00:00 2001 From: Giovanny Gongora Date: Tue, 18 Oct 2022 07:59:27 +0200 Subject: [PATCH 8/8] lint --- src/utils/testReporter.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/utils/testReporter.ts b/src/utils/testReporter.ts index b975e66d8..30704d328 100644 --- a/src/utils/testReporter.ts +++ b/src/utils/testReporter.ts @@ -28,16 +28,16 @@ class TestReporter { colWidths: [30, 100], }); - let announcement = new CreateLogTable({ - colWidths: [120], - }); - announcement.pushToPrint([ - [ - decorators.green( - "🛎️ Tests are currently running. Results will appear at the end", - ), - ], - ]); + let announcement = new CreateLogTable({ + colWidths: [120], + }); + announcement.pushToPrint([ + [ + decorators.green( + "🛎️ Tests are currently running. Results will appear at the end", + ), + ], + ]); runner .once(EVENT_RUN_BEGIN, () => { announcement.print();