Skip to content

Commit 65573f6

Browse files
implement better data management
1 parent d537671 commit 65573f6

File tree

11 files changed

+192
-126
lines changed

11 files changed

+192
-126
lines changed

packages/app/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"author": "Christian Bromann <[email protected]>",
2727
"license": "MIT",
2828
"devDependencies": {
29-
"@wdio/devtools-service": "workspace:^"
29+
"@wdio/devtools-service": "workspace:^",
30+
"@wdio/reporter": "^8.23.0"
3031
}
3132
}

packages/app/src/app.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { css, html, nothing } from 'lit'
2-
import { provide } from '@lit/context'
3-
import { customElement, query, property } from 'lit/decorators.js'
4-
import { type TraceLog } from '@wdio/devtools-service/types'
2+
import { customElement, query } from 'lit/decorators.js'
3+
import { TraceType, type TraceLog } from '@wdio/devtools-service/types'
54

65
import { Element } from '@core/element'
7-
import { context, cacheTraceData } from './context.js'
6+
import { DataManagerController } from './controller/DataManager.js'
87
import { DragController, Direction } from './utils/DragController.js'
98

109
import './components/header.js'
@@ -16,9 +15,7 @@ const SIDEBAR_MIN_WIDTH = 200
1615

1716
@customElement('wdio-devtools')
1817
export class WebdriverIODevtoolsApplication extends Element {
19-
@provide({ context })
20-
@property({ type: Object })
21-
data: Partial<TraceLog> = {}
18+
dataManager = new DataManagerController(this)
2219

2320
static styles = [...Element.styles, css`
2421
:host {
@@ -59,21 +56,20 @@ export class WebdriverIODevtoolsApplication extends Element {
5956
}
6057

6158
#loadTrace ({ detail }: { detail: TraceLog }) {
62-
this.data = detail
63-
cacheTraceData(detail)
59+
this.dataManager.loadTraceFile(detail)
6460
this.requestUpdate()
6561
}
6662

6763
#mainContent () {
68-
if (!this.data) {
64+
if (!this.dataManager.hasConnection) {
6965
return html`<wdio-devtools-start></wdio-devtools-start>`
7066
}
7167

7268
return html`
7369
<section class="flex h-[calc(100%-40px)] w-full relative">
7470
${
7571
// only render sidebar if trace file is captured using testrunner
76-
this.data?.suites
72+
this.dataManager.traceType === TraceType.Testrunner
7773
? html`<wdio-devtools-sidebar style="${this.#drag.getPosition()}"></wdio-devtools-sidebar>`
7874
: nothing
7975
}

packages/app/src/components/browser/snapshot.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { consume } from '@lit/context'
55
import { type ComponentChildren, h, render, type VNode } from 'preact'
66
import { customElement, query } from 'lit/decorators.js'
77

8-
import { context, type TraceLog } from '../../context.js'
8+
import { mutationContext, type TraceMutation, metadataContext, type Metadata } from '../../controller/DataManager.js'
99

1010
import '~icons/mdi/world.js'
1111
import '../placeholder.js'
@@ -38,8 +38,11 @@ export class DevtoolsBrowser extends Element {
3838
#vdom = document.createDocumentFragment()
3939
#activeUrl = ''
4040

41-
@consume({ context })
42-
data: Partial<TraceLog> = {}
41+
@consume({ context: metadataContext })
42+
metadata: Metadata | undefined = undefined
43+
44+
@consume({ context: mutationContext })
45+
mutations: TraceMutation[] = []
4346

4447
static styles = [...Element.styles, css`
4548
:host {
@@ -85,7 +88,7 @@ export class DevtoolsBrowser extends Element {
8588
}
8689

8790
#setIframeSize () {
88-
const metadata = this.data.metadata
91+
const metadata = this.metadata
8992
if (!this.section || !this.iframe || !this.header || !metadata) {
9093
return
9194
}
@@ -190,7 +193,7 @@ export class DevtoolsBrowser extends Element {
190193

191194
#handleChildListMutation (mutation: TraceMutation) {
192195
if (mutation.addedNodes.length === 1 && !mutation.target) {
193-
const baseUrl = this.data.metadata?.url || 'unknown'
196+
const baseUrl = this.metadata?.url || 'unknown'
194197
this.#renderNewDocument(mutation.addedNodes[0] as SimplifiedVNode, baseUrl)
195198
return this.#renderVdom()
196199
}
@@ -254,7 +257,7 @@ export class DevtoolsBrowser extends Element {
254257
}
255258

256259
async #renderBrowserState (mutationEntry?: TraceMutation) {
257-
const mutations = this.data.mutations
260+
const mutations = this.mutations
258261
if (!mutations) {
259262
return
260263
}
@@ -274,7 +277,7 @@ export class DevtoolsBrowser extends Element {
274277
.map(([, i]) => i)
275278
.pop() || 0
276279

277-
this.#activeUrl = mutations[rootIndex].url || this.data.metadata?.url || 'unknown'
280+
this.#activeUrl = mutations[rootIndex].url || this.metadata?.url || 'unknown'
278281
for (let i = rootIndex; i <= mutationIndex; i++) {
279282
await this.#handleMutation(mutations[i]).catch(
280283
(err) => console.warn(`Failed to render mutation: ${err.message}`))
@@ -306,9 +309,9 @@ export class DevtoolsBrowser extends Element {
306309
${this.#activeUrl}
307310
</div>
308311
</header>
309-
${this.data.mutations
312+
${this.mutations
310313
? html`<iframe class="origin-top-left"></iframe>`
311-
: html`<wdio-devtools-placeholder style="height: 500px"></wdio-devtools-placeholder>`
314+
: html`<wdio-devtools-placeholder style="height: 100%"></wdio-devtools-placeholder>`
312315
}
313316
</section>
314317
`

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import { Element } from '@core/element'
22
import { html, css, nothing, type TemplateResult } from 'lit'
33
import { customElement } from 'lit/decorators.js'
44
import { consume } from '@lit/context'
5+
import { type SuiteStats } from '@wdio/reporter'
56

67
import { TestState } from './test-suite.js'
7-
import { context, type TraceLog } from '../../context.js'
8+
import { suiteContext } from '../../controller/DataManager.js'
89

910
import '~icons/mdi/play.js'
1011
import '~icons/mdi/stop.js'
@@ -35,8 +36,8 @@ export class DevtoolsSidebarExplorer extends CollapseableEntry {
3536
}
3637
`]
3738

38-
@consume({ context })
39-
data: TraceLog = {} as TraceLog
39+
@consume({ context: suiteContext })
40+
suites: Record<string, SuiteStats> = {}
4041

4142
connectedCallback(): void {
4243
super.connectedCallback()
@@ -84,10 +85,10 @@ export class DevtoolsSidebarExplorer extends CollapseableEntry {
8485
}
8586

8687
render() {
87-
if (typeof this.data.suites !== 'object') {
88+
if (typeof this.suites !== 'object') {
8889
return
8990
}
90-
const suites = Object.values(this.data.suites[0]).map((suite) => {
91+
const suites = Object.values(this.suites[0]).map((suite: SuiteStats) => {
9192
const state = !suite.tests.find((t) => t.end)
9293
? TestState.RUNNING
9394
: suite.tests.find((t) => t.state === 'failed')

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { html, css } from 'lit'
33
import { customElement } from 'lit/decorators.js'
44
import { consume } from '@lit/context'
55

6-
import { context, type TraceLog } from '../../context.js'
6+
import { mutationContext, type TraceMutation, commandContext, type CommandLog } from '../../controller/DataManager.js'
77
import { type ActionEntry } from './actionItems/item.js'
88

99
import '~icons/mdi/pencil.js'
@@ -30,17 +30,20 @@ export class DevtoolsActions extends Element {
3030
}
3131
`]
3232

33-
@consume({ context })
34-
data: Partial<TraceLog> = {}
33+
@consume({ context: mutationContext })
34+
mutations: TraceMutation[] = []
35+
36+
@consume({ context: commandContext })
37+
commands: CommandLog[] = []
3538

3639
connectedCallback(): void {
3740
super.connectedCallback()
38-
this.#entries = [...this.data.mutations || [], ...this.data.commands || []]
41+
this.#entries = [...this.mutations || [], ...this.commands || []]
3942
.sort((a, b) => a.timestamp - b.timestamp)
4043
}
4144

4245
render() {
43-
const mutations = this.data.mutations || []
46+
const mutations = this.mutations || []
4447
if (!this.#entries.length || !mutations.length) {
4548
return html`<wdio-devtools-placeholder></wdio-devtools-placeholder>`
4649
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { html, css } from 'lit'
55
import { customElement } from 'lit/decorators.js'
66
import { consume } from '@lit/context'
77

8-
import { context, type TraceLog } from '../../context.js'
8+
import { consoleLogContext } from '../../controller/DataManager.js'
99

1010
import '~icons/mdi/chevron-right.js'
1111
import '../placeholder.js'
@@ -30,16 +30,16 @@ export class DevtoolsConsoleLogs extends Element {
3030
}
3131
`]
3232

33-
@consume({ context })
34-
data: Partial<TraceLog> = {}
33+
@consume({ context: consoleLogContext })
34+
logs: Partial<ConsoleLogs> = {}
3535

3636
render() {
37-
if (!this.data.consoleLogs || this.data.consoleLogs.length === 0) {
37+
if (!this.logs || this.logs.length === 0) {
3838
return html`<wdio-devtools-placeholder></wdio-devtools-placeholder>`
3939
}
4040

4141
return html`
42-
${Object.values(this.data.consoleLogs).map((log) => html`
42+
${Object.values(this.logs).map((log: any) => html`
4343
<dl class="w-full flex grow-0">
4444
<dt class="flex">
4545
<icon-mdi-chevron-right class="text-base transition-transform block"></icon-mdi-chevron-right>

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { html, css } from 'lit'
33
import { customElement } from 'lit/decorators.js'
44
import { consume } from '@lit/context'
55

6-
import { context, type TraceLog } from '../../context.js'
6+
import { metadataContext, type Metadata } from '../../controller/DataManager.js'
77

88
import './list.js'
99
import '../placeholder.js'
@@ -12,8 +12,8 @@ import '~icons/mdi/chevron-right.js'
1212
const SOURCE_COMPONENT = 'wdio-devtools-metadata'
1313
@customElement(SOURCE_COMPONENT)
1414
export class DevtoolsMetadata extends Element {
15-
@consume({ context })
16-
data: Partial<TraceLog> = {}
15+
@consume({ context: metadataContext })
16+
metadata: Partial<Metadata> = {}
1717

1818
static styles = [...Element.styles, css`
1919
:host {
@@ -26,21 +26,21 @@ export class DevtoolsMetadata extends Element {
2626
`]
2727

2828
render() {
29-
if (!this.data.metadata) {
30-
return html`<wdio-devtools-placeholder style="height: 500px"></wdio-devtools-placeholder>`
29+
if (!this.metadata) {
30+
return html`<wdio-devtools-placeholder></wdio-devtools-placeholder>`
3131
}
3232

33-
const { url } = this.data.metadata
33+
const { url } = this.metadata
3434
return html`
3535
<wdio-devtools-list
3636
label="Metadata"
3737
.list="${({ url })}"></wdio-devtools-list>
3838
<wdio-devtools-list
3939
label="Capabilities"
40-
.list="${this.data.metadata.capabilities}"></wdio-devtools-list>
40+
.list="${this.metadata.capabilities}"></wdio-devtools-list>
4141
<wdio-devtools-list
4242
label="Options"
43-
.list="${this.data.metadata.options}"></wdio-devtools-list>
43+
.list="${this.metadata.options}"></wdio-devtools-list>
4444
`
4545
}
4646
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type { EditorViewConfig } from '@codemirror/view'
88
import { javascript } from '@codemirror/lang-javascript'
99
import { oneDark } from '@codemirror/theme-one-dark'
1010

11-
import { context, type TraceLog } from '../../context.js'
11+
import { sourceContext } from '../../controller/DataManager.js'
1212

1313
import '../placeholder.js'
1414

@@ -31,21 +31,21 @@ export class DevtoolsSource extends Element {
3131
}
3232
`]
3333

34-
@consume({ context })
35-
data: Partial<TraceLog> = {}
34+
@consume({ context: sourceContext })
35+
sources: Record<string, string> = {}
3636

3737
connectedCallback(): void {
3838
super.connectedCallback()
3939
window.addEventListener('app-source-highlight', this.#highlightCallSource.bind(this))
40-
setTimeout(() => this.#renderEditor(Object.keys(this.data.sources || {})[0]))
40+
setTimeout(() => this.#renderEditor(Object.keys(this.sources || {})[0]))
4141
}
4242

4343
#renderEditor (filePath: string, highlightLine?: number) {
44-
if (!this.data.sources) {
44+
if (!this.sources) {
4545
return
4646
}
4747

48-
const source = this.data.sources[filePath]
48+
const source = this.sources[filePath]
4949
if (!source) {
5050
return
5151
}

packages/app/src/context.ts

Lines changed: 0 additions & 76 deletions
This file was deleted.

0 commit comments

Comments
 (0)