From a7550f836c0be1144c2fb710951fd0ca61342d41 Mon Sep 17 00:00:00 2001 From: Masaharu TASHIRO Date: Mon, 4 Jul 2022 03:52:05 +0900 Subject: [PATCH] feat: show the status icon for ancestors. --- src/__tests__/fixtures/expected.md | 12 ++++++------ .../fixtures/converter/expected-dashboard.ts | 6 ++++++ .../printer/default/expected-dashboard.md | 12 ++++++------ .../printer/default/input-dashboard.ts | 6 ++++++ .../printer/no-permalink/expected-dashboard.md | 12 ++++++------ .../printer/no-permalink/input-dashboard.ts | 6 ++++++ src/dashboard/converter.ts | 18 +++++++++++++++++- src/dashboard/printer.ts | 4 +++- src/dashboard/types.ts | 1 + 9 files changed, 57 insertions(+), 20 deletions(-) diff --git a/src/__tests__/fixtures/expected.md b/src/__tests__/fixtures/expected.md index 812c2ed5..30985aa1 100644 --- a/src/__tests__/fixtures/expected.md +++ b/src/__tests__/fixtures/expected.md @@ -14,21 +14,21 @@ 0 passed, 0 failed, 0 todo, done in 0 s -- describe depth 1 +- :white_check_mark: describe depth 1 - :white_check_mark: test 1 - :white_check_mark: test 2 - - describe depth 2 + - :white_check_mark: describe depth 2 - :white_check_mark: test 1 - :white_check_mark: test 2 - - describe depth 3 + - :white_check_mark: describe depth 3 - :white_check_mark: test 1 - :white_check_mark: test 2 - - describe depth 2-2 + - :white_check_mark: describe depth 2-2 - :white_check_mark: test 1 - :construction: test 2 - :white_check_mark: test 3 - :white_check_mark: test 4 -- describe depth 1-2 +- :white_check_mark: describe depth 1-2 - :white_check_mark: parametarized: 1 - :white_check_mark: parametarized: 2 - :white_check_mark: parametarized: 1 @@ -38,7 +38,7 @@ 0 passed, 0 failed, 0 todo, done in 0 s -- describe depth 1 +- :white_check_mark: describe depth 1 - :white_check_mark: test 1 - :white_check_mark: test 2 - :white_check_mark: test 3 diff --git a/src/dashboard/__tests__/fixtures/converter/expected-dashboard.ts b/src/dashboard/__tests__/fixtures/converter/expected-dashboard.ts index 72b865c7..7a55d2ae 100644 --- a/src/dashboard/__tests__/fixtures/converter/expected-dashboard.ts +++ b/src/dashboard/__tests__/fixtures/converter/expected-dashboard.ts @@ -14,18 +14,21 @@ const testFiles: TestFile[] = [ { type: "describe", describe: "describe depth 1", + status: "passed", children: [ { type: "test", title: "test 1", status: "passed" }, { type: "test", title: "test 2", status: "passed" }, { type: "describe", describe: "describe depth 2", + status: "passed", children: [ { type: "test", title: "test 1", status: "passed" }, { type: "test", title: "test 2", status: "passed" }, { type: "describe", describe: "describe depth 3", + status: "passed", children: [ { type: "test", title: "test 1", status: "passed" }, { type: "test", title: "test 2", status: "passed" }, @@ -36,6 +39,7 @@ const testFiles: TestFile[] = [ { type: "describe", describe: "describe depth 2-2", + status: "passed", children: [ { type: "test", title: "test 1", status: "passed" }, { type: "test", title: "test 2", status: "todo" }, @@ -48,6 +52,7 @@ const testFiles: TestFile[] = [ { type: "describe", describe: "describe depth 1-2", + status: "passed", children: [ { type: "test", title: "parametarized: 1", status: "passed" }, { type: "test", title: "parametarized: 2", status: "passed" }, @@ -69,6 +74,7 @@ const testFiles: TestFile[] = [ { type: "describe", describe: "describe depth 1", + status: "passed", children: [ { type: "test", title: "test 1", status: "passed" }, { type: "test", title: "test 2", status: "passed" }, diff --git a/src/dashboard/__tests__/fixtures/printer/default/expected-dashboard.md b/src/dashboard/__tests__/fixtures/printer/default/expected-dashboard.md index 8c0a6ada..dd623b6e 100644 --- a/src/dashboard/__tests__/fixtures/printer/default/expected-dashboard.md +++ b/src/dashboard/__tests__/fixtures/printer/default/expected-dashboard.md @@ -14,21 +14,21 @@ 13 passed, 0 failed, 1 todo, done in 0.513 s -- describe depth 1 +- :white_check_mark: describe depth 1 - :white_check_mark: test 1 - :white_check_mark: test 2 - - describe depth 2 + - :white_check_mark: describe depth 2 - :white_check_mark: test 1 - :white_check_mark: test 2 - - describe depth 3 + - :white_check_mark: describe depth 3 - :white_check_mark: test 1 - :white_check_mark: test 2 - - describe depth 2-2 + - :white_check_mark: describe depth 2-2 - :white_check_mark: test 1 - :construction: test 2 - :white_check_mark: test 3 - :white_check_mark: test 4 -- describe depth 1-2 +- :white_check_mark: describe depth 1-2 - :white_check_mark: parametarized: 1 - :white_check_mark: parametarized: 2 - :white_check_mark: parametarized: 1 @@ -38,7 +38,7 @@ 4 passed, 0 failed, 0 todo, done in 3.869 s -- describe depth 1 +- :white_check_mark: describe depth 1 - :white_check_mark: test 1 - :white_check_mark: test 2 - :white_check_mark: test 3 diff --git a/src/dashboard/__tests__/fixtures/printer/default/input-dashboard.ts b/src/dashboard/__tests__/fixtures/printer/default/input-dashboard.ts index a19b65ef..a6b0e078 100644 --- a/src/dashboard/__tests__/fixtures/printer/default/input-dashboard.ts +++ b/src/dashboard/__tests__/fixtures/printer/default/input-dashboard.ts @@ -14,18 +14,21 @@ const testFiles: TestFile[] = [ { type: "describe", describe: "describe depth 1", + status: "passed", children: [ { type: "test", title: "test 1", status: "passed" }, { type: "test", title: "test 2", status: "passed" }, { type: "describe", describe: "describe depth 2", + status: "passed", children: [ { type: "test", title: "test 1", status: "passed" }, { type: "test", title: "test 2", status: "passed" }, { type: "describe", describe: "describe depth 3", + status: "passed", children: [ { type: "test", title: "test 1", status: "passed" }, { type: "test", title: "test 2", status: "passed" }, @@ -36,6 +39,7 @@ const testFiles: TestFile[] = [ { type: "describe", describe: "describe depth 2-2", + status: "passed", children: [ { type: "test", title: "test 1", status: "passed" }, { type: "test", title: "test 2", status: "todo" }, @@ -48,6 +52,7 @@ const testFiles: TestFile[] = [ { type: "describe", describe: "describe depth 1-2", + status: "passed", children: [ { type: "test", title: "parametarized: 1", status: "passed" }, { type: "test", title: "parametarized: 2", status: "passed" }, @@ -69,6 +74,7 @@ const testFiles: TestFile[] = [ { type: "describe", describe: "describe depth 1", + status: "passed", children: [ { type: "test", title: "test 1", status: "passed" }, { type: "test", title: "test 2", status: "passed" }, diff --git a/src/dashboard/__tests__/fixtures/printer/no-permalink/expected-dashboard.md b/src/dashboard/__tests__/fixtures/printer/no-permalink/expected-dashboard.md index d6189f86..9bea4932 100644 --- a/src/dashboard/__tests__/fixtures/printer/no-permalink/expected-dashboard.md +++ b/src/dashboard/__tests__/fixtures/printer/no-permalink/expected-dashboard.md @@ -14,21 +14,21 @@ 13 passed, 0 failed, 1 todo, done in 0.513 s -- describe depth 1 +- :white_check_mark: describe depth 1 - :white_check_mark: test 1 - :white_check_mark: test 2 - - describe depth 2 + - :white_check_mark: describe depth 2 - :white_check_mark: test 1 - :white_check_mark: test 2 - - describe depth 3 + - :white_check_mark: describe depth 3 - :white_check_mark: test 1 - :white_check_mark: test 2 - - describe depth 2-2 + - :white_check_mark: describe depth 2-2 - :white_check_mark: test 1 - :construction: test 2 - :white_check_mark: test 3 - :white_check_mark: test 4 -- describe depth 1-2 +- :white_check_mark: describe depth 1-2 - :white_check_mark: parametarized: 1 - :white_check_mark: parametarized: 2 - :white_check_mark: parametarized: 1 @@ -38,7 +38,7 @@ 4 passed, 0 failed, 0 todo, done in 3.869 s -- describe depth 1 +- :white_check_mark: describe depth 1 - :white_check_mark: test 1 - :white_check_mark: test 2 - :white_check_mark: test 3 diff --git a/src/dashboard/__tests__/fixtures/printer/no-permalink/input-dashboard.ts b/src/dashboard/__tests__/fixtures/printer/no-permalink/input-dashboard.ts index 16e236e2..a1178a10 100644 --- a/src/dashboard/__tests__/fixtures/printer/no-permalink/input-dashboard.ts +++ b/src/dashboard/__tests__/fixtures/printer/no-permalink/input-dashboard.ts @@ -12,18 +12,21 @@ const testFiles: TestFile[] = [ { type: "describe", describe: "describe depth 1", + status: "passed", children: [ { type: "test", title: "test 1", status: "passed" }, { type: "test", title: "test 2", status: "passed" }, { type: "describe", describe: "describe depth 2", + status: "passed", children: [ { type: "test", title: "test 1", status: "passed" }, { type: "test", title: "test 2", status: "passed" }, { type: "describe", describe: "describe depth 3", + status: "passed", children: [ { type: "test", title: "test 1", status: "passed" }, { type: "test", title: "test 2", status: "passed" }, @@ -34,6 +37,7 @@ const testFiles: TestFile[] = [ { type: "describe", describe: "describe depth 2-2", + status: "passed", children: [ { type: "test", title: "test 1", status: "passed" }, { type: "test", title: "test 2", status: "todo" }, @@ -46,6 +50,7 @@ const testFiles: TestFile[] = [ { type: "describe", describe: "describe depth 1-2", + status: "passed", children: [ { type: "test", title: "parametarized: 1", status: "passed" }, { type: "test", title: "parametarized: 2", status: "passed" }, @@ -65,6 +70,7 @@ const testFiles: TestFile[] = [ { type: "describe", describe: "describe depth 1", + status: "passed", children: [ { type: "test", title: "test 1", status: "passed" }, { type: "test", title: "test 2", status: "passed" }, diff --git a/src/dashboard/converter.ts b/src/dashboard/converter.ts index 9b4177a2..bb4e1290 100644 --- a/src/dashboard/converter.ts +++ b/src/dashboard/converter.ts @@ -3,6 +3,7 @@ import path from "path"; import { AggregatedResult, AssertionResult, + Status, TestResult, } from "@jest/test-result"; @@ -104,11 +105,26 @@ const convertChildren = ( lastIndex > 0 ? results.slice(index, index + lastIndex) : results.slice(index); + const _children = convertChildren(testsInThisDescribe, currentLevel + 1); + let status: Status = "passed"; + if (_children.some((child) => child.status === "failed")) { + status = "failed"; + } else if (_children.some((child) => child.status === "pending")) { + status = "pending"; + } else if (_children.every((child) => child.status === "skipped")) { + status = "skipped"; + } else if (_children.every((child) => child.status === "todo")) { + status = "todo"; + } else if (_children.every((child) => child.status === "disabled")) { + status = "disabled"; + } + children.push({ type: "describe", describe: result.ancestorTitles[currentLevel], // TODO: need a recursion limit - children: convertChildren(testsInThisDescribe, currentLevel + 1), + status, + children: _children, }); index = lastIndex > 0 ? index + lastIndex - 1 : results.length; } diff --git a/src/dashboard/printer.ts b/src/dashboard/printer.ts index 57aaf6fa..6c8f58ce 100644 --- a/src/dashboard/printer.ts +++ b/src/dashboard/printer.ts @@ -56,7 +56,9 @@ const printChildren = ( )} ${child.title}\n`; break; case "describe": - resultText += `${" ".repeat(currentLevel)}- ${child.describe}\n`; + resultText += `${" ".repeat(currentLevel)}- ${printStatus( + child.status + )} ${child.describe}\n`; resultText += printChildren(child.children, currentLevel + 1); break; default: diff --git a/src/dashboard/types.ts b/src/dashboard/types.ts index ecbdc450..df2fc3cc 100644 --- a/src/dashboard/types.ts +++ b/src/dashboard/types.ts @@ -34,6 +34,7 @@ export type TestFile = { export type Describe = { type: "describe"; describe: string; + status: Status; children: Array; };