Skip to content

Commit 4817bb2

Browse files
committed
refactor: replace tuple return with named methods in TestRunWriter
Split resolve() into toLocation() and toTestItem() for better readability and single responsibility.
1 parent e01adda commit 4817bb2

1 file changed

Lines changed: 15 additions & 11 deletions

File tree

packages/extension/src/Observers/Writers/TestRunWriter.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,32 @@ export class TestRunWriter implements OutputWriter {
99
) {}
1010

1111
append(text: string, location?: OutputLocation, testId?: string): void {
12-
const [loc, item] = this.resolve(location, testId);
13-
this.testRun.appendOutput(this.toCRLF(text), loc, item);
12+
this.testRun.appendOutput(
13+
this.toCRLF(text),
14+
this.toLocation(location),
15+
this.toTestItem(testId),
16+
);
1417
}
1518

1619
appendLine(text: string, location?: OutputLocation, testId?: string): void {
17-
const [loc, item] = this.resolve(location, testId);
18-
this.testRun.appendOutput(this.toCRLF(`${text}\n`), loc, item);
20+
this.testRun.appendOutput(
21+
this.toCRLF(`${text}\n`),
22+
this.toLocation(location),
23+
this.toTestItem(testId),
24+
);
1925
}
2026

2127
private toCRLF(text: string): string {
2228
return text.replace(/\r?\n/g, '\r\n');
2329
}
2430

25-
private resolve(
26-
location?: OutputLocation,
27-
testId?: string,
28-
): [Location | undefined, TestItem | undefined] {
29-
const loc = location
31+
private toLocation(location?: OutputLocation): Location | undefined {
32+
return location
3033
? new Location(Uri.file(location.file), new Position(location.line - 1, 0))
3134
: undefined;
32-
const item = testId ? this.testItemById.get(testId) : undefined;
35+
}
3336

34-
return [loc, item];
37+
private toTestItem(testId?: string): TestItem | undefined {
38+
return testId ? this.testItemById.get(testId) : undefined;
3539
}
3640
}

0 commit comments

Comments
 (0)