Skip to content

Commit b334fd7

Browse files
committed
Test lens feature intial commit
1 parent 30b63ac commit b334fd7

File tree

7 files changed

+574
-13
lines changed

7 files changed

+574
-13
lines changed

packages/app/src/components/sidebar/explorer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ interface TestEntry {
2323
uid: string
2424
state?: string
2525
label: string
26+
callSource?: string
2627
children: TestEntry[]
2728
}
2829

@@ -66,7 +67,7 @@ export class DevtoolsSidebarExplorer extends CollapseableEntry {
6667

6768
#renderEntry (entry: TestEntry): TemplateResult {
6869
return html`
69-
<wdio-test-entry state="${entry.state as any}">
70+
<wdio-test-entry state="${entry.state as any}" call-source="${entry.callSource || ''}">
7071
<label slot="label">${entry.label}</label>
7172
${entry.children && entry.children.length
7273
? html`
@@ -116,6 +117,7 @@ export class DevtoolsSidebarExplorer extends CollapseableEntry {
116117
: entry.tests.find((t) => t.state === 'failed')
117118
? TestState.FAILED
118119
: TestState.PASSED,
120+
callSource: (entry as any).callSource,
119121
children: Object.values(entries)
120122
.map(this.#getTestEntry.bind(this))
121123
.filter(this.#filterEntry.bind(this))
@@ -129,6 +131,7 @@ export class DevtoolsSidebarExplorer extends CollapseableEntry {
129131
: entry.state === 'failed'
130132
? TestState.FAILED
131133
: TestState.PASSED,
134+
callSource: (entry as any).callSource,
132135
children: []
133136
}
134137
}

packages/app/src/components/sidebar/test-suite.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ export class ExplorerTestEntry extends CollapseableEntry {
4848
@property({ type: String })
4949
state?: TestState
5050

51+
@property({ type: String, attribute: 'call-source' })
52+
callSource?: string
53+
5154
static styles = [...Element.styles, css`
5255
:host {
5356
display: block;
@@ -71,6 +74,13 @@ export class ExplorerTestEntry extends CollapseableEntry {
7174
this.requestUpdate()
7275
}
7376

77+
#viewSource() {
78+
if (!this.callSource) return
79+
window.dispatchEvent(new CustomEvent('app-source-highlight', {
80+
detail: this.callSource
81+
}))
82+
}
83+
7484
get hasPassed () {
7585
return this.state === TestState.PASSED
7686
}
@@ -126,7 +136,7 @@ export class ExplorerTestEntry extends CollapseableEntry {
126136
</button>
127137
`
128138
}
129-
<button class="p-1 rounded hover:bg-toolbarHoverBackground my-1 group">
139+
<button class="p-1 rounded hover:bg-toolbarHoverBackground my-1 group" @click="${() => this.#viewSource()}">
130140
<icon-mdi-eye class="group-hover:text-chartsYellow"></icon-mdi-eye>
131141
</button>
132142
${!hasNoChildren ? html`

packages/app/src/components/workbench/source.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export class DevtoolsSource extends Element {
2424
2525
.cm-editor {
2626
width: 100%;
27+
height: 100%;
2728
padding: 10px 0px;
2829
}
2930
.cm-content {
@@ -63,20 +64,23 @@ export class DevtoolsSource extends Element {
6364
const editorView = new EditorView(opts)
6465
container.replaceWith(editorView.dom)
6566

66-
/**
67-
* highlight line of call source
68-
*/
69-
const lines = [...(this.shadowRoot?.querySelectorAll('.cm-line') || [])]
70-
if (highlightLine && lines.length && highlightLine < lines.length) {
71-
setTimeout(() => {
72-
lines[highlightLine].classList.add('cm-activeLine')
73-
}, 100)
67+
// Use CodeMirror API to select and scroll to the target line (1-based index)
68+
if (highlightLine && highlightLine > 0) {
69+
try {
70+
const lineInfo = editorView.state.doc.line(highlightLine) // 1-based
71+
requestAnimationFrame(() => {
72+
editorView.dispatch({
73+
selection: { anchor: lineInfo.from },
74+
effects: EditorView.scrollIntoView(lineInfo.from, { y: 'center' }) // center the line
75+
})
76+
})
77+
} catch { /* ignore */ }
7478
}
7579
}
7680

7781
#highlightCallSource (ev: CustomEvent<string>) {
7882
const [filePath, line] = ev.detail.split(':')
79-
this.#renderEditor(filePath, parseInt(line, 10) + 1)
83+
this.#renderEditor(filePath, parseInt(line, 10))
8084
}
8185

8286
render() {

packages/service/package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,26 @@
2525
"test": "eslint ."
2626
},
2727
"dependencies": {
28+
"@babel/types": "^7.28.4",
2829
"@wdio/devtools-backend": "workspace:^",
2930
"@wdio/devtools-script": "workspace:^",
3031
"@wdio/logger": "9.18.0",
3132
"@wdio/reporter": "9.18.0",
3233
"@wdio/types": "9.16.2",
3334
"import-meta-resolve": "^4.1.0",
34-
"stack-trace": "1.0.0-pre2",
3535
"ws": "^8.18.3"
3636
},
3737
"license": "MIT",
3838
"devDependencies": {
39+
"@babel/parser": "^7.28.4",
40+
"@babel/traverse": "^7.28.4",
41+
"@types/babel__core": "^7.20.5",
42+
"@types/babel__traverse": "^7.28.0",
3943
"@types/stack-trace": "^0.0.33",
4044
"@types/ws": "^8.18.1",
4145
"@wdio/globals": "9.17.0",
4246
"@wdio/protocols": "9.16.2",
47+
"stack-trace": "1.0.0-pre2",
4348
"vite-plugin-dts": "^4.5.4"
4449
},
4550
"peerDependencies": {

packages/service/src/reporter.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import WebdriverIOReporter, { type SuiteStats, type TestStats } from '@wdio/reporter'
2+
import { enrichTestStats, setCurrentSpecFile } from './utils.js'
23

34
export class TestReporter extends WebdriverIOReporter {
45
#report: (data: any) => void
6+
#currentSpecFile?: string
57

68
constructor (options: any, report: (data: any) => void) {
79
super(options)
@@ -10,10 +12,17 @@ export class TestReporter extends WebdriverIOReporter {
1012

1113
onSuiteStart(suiteStats: SuiteStats): void {
1214
super.onSuiteStart(suiteStats)
15+
this.#currentSpecFile = suiteStats.file
16+
setCurrentSpecFile(suiteStats.file)
1317
this.#sendUpstream()
1418
}
1519

1620
onTestStart(testStats: TestStats): void {
21+
//Enrich testStats with file + line info
22+
enrichTestStats(testStats, this.#currentSpecFile)
23+
if ((testStats as any).file && (testStats as any).line != null) {
24+
;(testStats as any).callSource = `${(testStats as any).file}:${(testStats as any).line}`
25+
}
1726
super.onTestStart(testStats)
1827
this.#sendUpstream()
1928
}
@@ -25,6 +34,8 @@ export class TestReporter extends WebdriverIOReporter {
2534

2635
onSuiteEnd(suiteStats: SuiteStats): void {
2736
super.onSuiteEnd(suiteStats)
37+
this.#currentSpecFile = undefined
38+
setCurrentSpecFile(undefined)
2839
this.#sendUpstream()
2940
}
3041

packages/service/src/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,11 @@ declare module WebdriverIO {
6666
interface ServiceOption extends ServiceOptions {}
6767
interface Capabilities {}
6868
}
69+
70+
declare module '@wdio/reporter' {
71+
interface TestStats {
72+
file?: string
73+
line?: number
74+
column?: number
75+
}
76+
}

0 commit comments

Comments
 (0)