Skip to content

Commit 66a063d

Browse files
committed
feat: hide internal stack entries
1 parent cdb7c19 commit 66a063d

File tree

3 files changed

+38
-11
lines changed

3 files changed

+38
-11
lines changed

src/conductor/TestRun/TestSuite.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { createTestElements } from './createTestElements'
1111
import { CoverageMapData } from './TestCoverage'
1212
import { TestHook } from './TestHook'
1313
import { TestRunState } from './enum'
14+
import { XError } from '../../error/XError'
1415

1516
export class TestSuiteStack extends TestNodeStack {
1617
static create(
@@ -175,10 +176,13 @@ export class TestSuite extends TestNodeInstance {
175176
throw new Error(`Can not add error for node #${String(data.nodeId)}`)
176177
}
177178

178-
node.errors.add(new TestError(
179+
const error = new TestError(
179180
data.error,
180181
data.hook && new TestHook(data.hook.type, data.hook.index, data.hook.name, data.hook.cleanup),
181-
))
182+
)
183+
this.setStackEntriesMain(error)
184+
185+
node.errors.add(error)
182186
}
183187

184188
private reportResult(data: TestResultData) {
@@ -189,7 +193,23 @@ export class TestSuite extends TestNodeInstance {
189193
throw new Error(`Can not add result for node #${data.nodeId}`)
190194
}
191195

192-
node.result.set(new TestResult(data.type, data.error, data.duration))
196+
const result = new TestResult(data.type, data.error, data.duration)
197+
if (result.error) {
198+
this.setStackEntriesMain(result.error)
199+
}
200+
201+
node.result.set(result)
202+
}
203+
204+
protected setStackEntriesMain(error: XError) {
205+
if (error.stackEntries) {
206+
const i = error.stackEntries.findLastIndex(
207+
e => e.file === this.url,
208+
)
209+
if (i >= 0) {
210+
error.stackEntriesMain = i
211+
}
212+
}
193213
}
194214

195215
protected _coverage?: CoverageMapData

src/error/XError.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ export class XError implements Error {
3535

3636
text: string
3737
stackEntries?: StackEntry[]
38+
/** Index of the "entry point" */
39+
stackEntriesMain?: number
3840
}
3941

4042
function forEach<T, R>(
@@ -66,23 +68,26 @@ function* genStackEntries(stack: string) {
6668
}
6769
const raw = l.substring(pre.length)
6870

69-
const m0 = raw.match(/(?<name>.+) \((?<file>[^)]+):(?<line>\d+):(?<column>\d+)\)$/)
71+
const m0 = raw.match(/(?<async>async )?(?<name>.+) \((?<file>[^)]+):(?<line>\d+):(?<column>\d+)\)$/)
7072
if (m0?.groups) {
7173
yield new StackEntry(
7274
raw,
7375
m0.groups.file,
7476
{line: Number(m0.groups.line), column: Number(m0.groups.column)},
7577
m0.groups.name,
78+
!!m0.groups.async,
7679
)
7780
continue
7881
}
7982

80-
const m1 = raw.match(/(?<file>.*):(?<line>\d+):(?<column>\d+)$/)
83+
const m1 = raw.match(/(?<async>async )?(?<file>.*):(?<line>\d+):(?<column>\d+)$/)
8184
if (m1?.groups) {
8285
yield new StackEntry(
8386
raw,
8487
m1.groups.file,
8588
{line: Number(m1.groups.line), column: Number(m1.groups.column)},
89+
undefined,
90+
!!m1.groups.async,
8691
)
8792
continue
8893
}
@@ -105,6 +110,7 @@ export class StackEntry {
105110
readonly file?: string,
106111
readonly position?: Position,
107112
readonly name?: string,
113+
readonly async: boolean = false,
108114
) {
109115
this.resolved = new ResolvedValue<SourceLocation>({file, position, name})
110116
}
@@ -115,15 +121,16 @@ export class StackEntry {
115121
) {
116122
const e = this.resolved.get()
117123

124+
const async = this.async ? 'async ' : ''
118125
const pos = e.position ? `:${e.position.line}:${e.position.column}` : ''
119126
if (useUrl && e.url && e.name) {
120-
return `${e.name} (${e.url})`
127+
return `${async}${e.name} (${e.url})`
121128
} else if (useUrl && e.url) {
122-
return `${e.url}`
129+
return `${async}${e.url}`
123130
} else if (e.name && e.file) {
124-
return `${e.name} (${e.file}${pos})`
131+
return `${async}${e.name} (${e.file}${pos})`
125132
} else if (e.file) {
126-
return `${e.file}${pos}`
133+
return `${async}${e.file}${pos}`
127134
}
128135
return this.raw
129136
}

src/ui/cli/Error.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export function XErrorComponent({
4141
<Text color="redBright">{t}</Text>
4242
</Line>
4343
))}
44-
{error.stackEntries?.map((entry, i, a) => (
44+
{error.stackEntries?.map((entry, i, a) => ((error.stackEntriesMain === undefined || i <= error.stackEntriesMain) && (
4545
<Line key={`stack-${i}`}
4646
// If overflowX is set, Links are truncated although the box measurements are correct.
4747
overflow="visible"
@@ -52,6 +52,6 @@ export function XErrorComponent({
5252
}</Text>)}
5353
<StackEntryText entry={entry}/>
5454
</Line>
55-
))}
55+
)))}
5656
</Block>
5757
}

0 commit comments

Comments
 (0)