Skip to content

Commit

Permalink
feat: show the status icon for ancestors.
Browse files Browse the repository at this point in the history
  • Loading branch information
tasshi-me committed Jul 3, 2022
1 parent eddbb55 commit a7550f8
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 20 deletions.
12 changes: 6 additions & 6 deletions src/__tests__/fixtures/expected.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand All @@ -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" },
Expand All @@ -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" },
Expand All @@ -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" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand All @@ -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" },
Expand All @@ -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" },
Expand All @@ -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" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand All @@ -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" },
Expand All @@ -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" },
Expand All @@ -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" },
Expand Down
18 changes: 17 additions & 1 deletion src/dashboard/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import path from "path";
import {
AggregatedResult,
AssertionResult,
Status,
TestResult,
} from "@jest/test-result";

Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 3 additions & 1 deletion src/dashboard/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions src/dashboard/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export type TestFile = {
export type Describe = {
type: "describe";
describe: string;
status: Status;
children: Array<Describe | Test>;
};

Expand Down

0 comments on commit a7550f8

Please sign in to comment.