Skip to content

Commit 6dfe4b2

Browse files
committed
fix: use indents from http
1 parent 31e6afe commit 6dfe4b2

2 files changed

Lines changed: 30 additions & 30 deletions

File tree

packages/scaffold/src/core/tester/create-proxy-plugin/mocha-setup.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,19 @@ window.debug = function (data) {
3737
send({ type: "debug", data });
3838
};
3939
40+
let indents = 0,
41+
passed = 0,
42+
failed = 0,
43+
aborted = false;
44+
4045
// Inherit the default test settings from Zotero
4146
function Reporter(runner) {
42-
var indents = 0,
43-
passed = 0,
44-
failed = 0,
45-
aborted = false;
46-
4747
function indent() {
4848
return " ".repeat(indents);
4949
}
5050
5151
function dump(str) {
52+
// console.log(str)
5253
// const p = document.createElement("p")
5354
// p.textContent = str
5455
// document.querySelector("#mocha").append(p)
@@ -57,30 +58,30 @@ function Reporter(runner) {
5758
5859
runner.on("start", async function () {
5960
console.log("start")
60-
await send({ type: "start" });
61+
await send({ type: "start", data: { indents } });
6162
});
6263
6364
runner.on("suite", async function (suite) {
6465
console.log("suite", suite)
6566
indents++;
6667
const str = indent() + suite.title + "\\n";
6768
dump(str);
68-
await send({ type: "suite", data: { title: suite.title, root: suite.root } });
69+
await send({ type: "suite", data: { title: suite.title, root: suite.root, indents } });
6970
});
7071
7172
runner.on("suite end", async function (suite) {
7273
console.log("suite end", suite)
7374
indents--;
7475
const str = indents === 1 ? "\\n" : "";
7576
dump(str);
76-
await send({ type: "suite end", data: { title: suite.title, root: suite.root } });
77+
await send({ type: "suite end", data: { title: suite.title, root: suite.root, indents } });
7778
});
7879
7980
runner.on("pending", async function (test) {
8081
console.log("pending", test)
8182
const str = indent() + "pending -" + test.title + "\\n";
8283
dump(str);
83-
await send({ type: "pending", data: { title: test.title, fulltest: test.fullTitle(), duration: test.duration } });
84+
await send({ type: "pending", data: { title: test.title, fulltest: test.fullTitle(), duration: test.duration, indents: indents + 1 } });
8485
});
8586
8687
runner.on("pass", async function (test) {
@@ -92,7 +93,7 @@ function Reporter(runner) {
9293
}
9394
str += "\\n";
9495
dump(str);
95-
await send({ type: "pass", data: { title: test.title, fulltest: test.fullTitle(), duration: test.duration } });
96+
await send({ type: "pass", data: { title: test.title, fulltest: test.fullTitle(), duration: test.duration, indents: indents + 1 } });
9697
9798
});
9899
@@ -121,7 +122,7 @@ function Reporter(runner) {
121122
"\\n\\n";
122123
dump(str);
123124
124-
await send({ type: "fail", data: { title: test.title, fulltest: test.fullTitle(), duration: test.duration, error } });
125+
await send({ type: "fail", data: { title: test.title, fulltest: test.fullTitle(), duration: test.duration, error, indents: indents + 1 } });
125126
126127
});
127128
@@ -138,7 +139,7 @@ function Reporter(runner) {
138139
139140
await send({
140141
type: "end",
141-
data: { passed: passed, failed: failed, aborted: aborted, str },
142+
data: { passed: passed, failed: failed, aborted: aborted, str, indents },
142143
});
143144
144145
// Must exit on Zotero side, otherwise the exit code will not be 0 and CI will fail

packages/scaffold/src/core/tester/reporter.ts

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,34 @@ import styleText from "node-style-text";
33
import { logger } from "../../utils/logger.js";
44
import { findFreeTcpPort } from "../../utils/zotero/remote-zotero.js";
55

6+
interface ResultDataBase {
7+
title: string;
8+
indents: number;
9+
}
10+
611
interface ResultS {
712
type: "start" | "pending" | "end" | "debug";
8-
data?: any;
13+
data?: ResultDataBase | any;
914
}
1015

1116
interface ResultSuite {
1217
type: "suite" | "suite end";
13-
data: {
14-
title: string;
18+
data: ResultDataBase & {
1519
root: boolean;
1620
};
1721
}
1822

19-
interface ResultTestData {
20-
title: string;
21-
fullTitle: string;
22-
duration: number;
23-
}
24-
2523
interface ResultTestPass {
2624
type: "pass";
27-
data: ResultTestData;
25+
data: ResultDataBase & {
26+
fullTitle: string;
27+
duration: number;
28+
};
2829
}
2930

3031
interface ResultTestFail {
3132
type: "fail";
32-
data: ResultTestData & {
33+
data: ResultTestPass["data"] & {
3334
error: {
3435
message: string;
3536
actual: unknown;
@@ -45,7 +46,6 @@ type Result = ResultS | ResultSuite | ResultTestPass | ResultTestFail;
4546
export class HttpReporter {
4647
private _server?: http.Server;
4748
private _port?: number;
48-
private indent: number = 0;
4949

5050
constructor(
5151
private onFailed?: () => void,
@@ -110,6 +110,7 @@ export class HttpReporter {
110110

111111
async onData(body: Result) {
112112
const { type, data } = body;
113+
const logger_option = { space: data.indents - 1 };
113114

114115
switch (type) {
115116
case "debug":
@@ -120,22 +121,20 @@ export class HttpReporter {
120121
break;
121122
case "suite":
122123
if (data.title)
123-
logger.tip(data.title, { space: this.indent });
124-
this.indent++;
124+
logger.tip(data.title, logger_option);
125125
break;
126126
case "pass":
127-
logger.success(`${data.title} ${styleText.gray(`${data.duration}ms`)}`, { space: this.indent });
127+
logger.success(`${data.title} ${styleText.gray(`${data.duration}ms`)}`, logger_option);
128128
break;
129129
case "fail":
130-
logger.fail(styleText.red(`${data.title}, ${body.data?.error?.message}`), { space: this.indent });
130+
logger.fail(styleText.red(`${data.title}, ${body.data?.error?.message}`), logger_option);
131131
// if (this.onFailed)
132132
// this.onFailed();
133133
break;
134134
case "pending":
135-
logger.info(`${data.title} pending`, { space: this.indent });
135+
logger.info(`${data.title} pending`, logger_option);
136136
break;
137137
case "suite end":
138-
this.indent--;
139138
break;
140139
case "end":
141140
logger.newLine();

0 commit comments

Comments
 (0)