-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlogs.ts
More file actions
140 lines (128 loc) · 3.77 KB
/
logs.ts
File metadata and controls
140 lines (128 loc) · 3.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import { Element } from '@core/element'
import { html, css } from 'lit'
import { customElement, property } from 'lit/decorators.js'
import type { CommandLog } from '@wdio/devtools-service/types'
import type { CommandEndpoint } from '@wdio/protocols'
import './list.js'
const SOURCE_COMPONENT = 'wdio-devtools-logs'
@customElement(SOURCE_COMPONENT)
export class DevtoolsSource extends Element {
#commandDefinition?: CommandEndpoint
@property({ type: Object })
command?: CommandLog
@property({ type: Number })
elapsedTime?: number
static styles = [
...Element.styles,
css`
:host {
display: block;
width: 100%;
height: 100%;
min-height: 200px;
}
`
]
connectedCallback(): void {
super.connectedCallback()
window.addEventListener('show-command', async (ev: CustomEvent) => {
const command = ev.detail.command
this.elapsedTime = ev.detail.elapsedTime
const {
WebDriverProtocol,
MJsonWProtocol,
AppiumProtocol,
ChromiumProtocol,
SauceLabsProtocol,
SeleniumProtocol,
GeckoProtocol,
WebDriverBidiProtocol
} = await import('@wdio/protocols')
const endpoints = Object.values({
...WebDriverProtocol,
...MJsonWProtocol,
...AppiumProtocol,
...ChromiumProtocol,
...SauceLabsProtocol,
...SeleniumProtocol,
...GeckoProtocol,
...WebDriverBidiProtocol
}).reduce(
(acc, endpoint) => {
for (const cmdDesc of Object.values(endpoint)) {
acc[cmdDesc.command] = cmdDesc as CommandEndpoint
}
return acc
},
{} as Record<string, CommandEndpoint>
)
this.#commandDefinition = endpoints[command.command]
this.command = command
window.dispatchEvent(
new CustomEvent('app-source-highlight', {
detail: this.command?.callSource
})
)
this.closest('wdio-devtools-tabs')?.activateTab('Log')
})
}
render() {
if (!this.command) {
return html`
<section class="flex items-center justify-center text-sm w-full h-full">
Please select a command to view details!
</section>
`
}
return html`
<section
class="flex flex-column border-b-[1px] border-b-panelBorder px-2 py-1"
>
<h1 class="font-bold">${this.command.command}</h1>
${this.#commandDefinition &&
html`<a
class="ml-auto text-xs flex items-center text-textLinkForeground"
href="${this.#commandDefinition.ref}"
target="_blank"
>Reference</a
>`}
</section>
${this.#commandDefinition &&
html`
<wdio-devtools-list
label="Description"
class="text-xs"
.list="${[this.#commandDefinition.description]}"
>
</wdio-devtools-list>
`}
<wdio-devtools-list
label="Parameters"
class="text-xs"
.list="${(this.command.args || []).reduce(
(acc: Record<string, unknown>, val: unknown, i: number) => {
const def = this.#commandDefinition
const paramName = def?.parameters?.[i]?.name ?? i
acc[paramName] = val
return acc
},
{} as Record<string, unknown>
)}"
></wdio-devtools-list>
${this.command.result !== null && this.command.result !== undefined
? html`<wdio-devtools-list
label="Result"
class="text-xs"
.list="${typeof this.command.result === 'object'
? this.command.result
: [this.command.result]}"
></wdio-devtools-list>`
: ''}
`
}
}
declare global {
interface HTMLElementTagNameMap {
[SOURCE_COMPONENT]: DevtoolsSource
}
}