Skip to content

Commit 3ba4269

Browse files
committed
Code refactor
1 parent 5da3dcc commit 3ba4269

File tree

8 files changed

+104
-84
lines changed

8 files changed

+104
-84
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { RunCapabilities } from './types.js'
2+
3+
export const DEFAULT_CAPABILITIES: RunCapabilities = {
4+
canRunSuites: true,
5+
canRunTests: true
6+
}
7+
8+
export const FRAMEWORK_CAPABILITIES: Record<string, RunCapabilities> = {
9+
cucumber: { canRunSuites: true, canRunTests: false }
10+
}

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

Lines changed: 16 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,19 @@ import { consume } from '@lit/context'
55
import type { TestStats, SuiteStats } from '@wdio/reporter'
66
import type { Metadata } from '@wdio/devtools-service/types'
77
import { repeat } from 'lit/directives/repeat.js'
8-
import { TestState } from './test-suite.js'
9-
import { suiteContext, metadataContext } from '../../controller/DataManager.js'
8+
import {
9+
suiteContext,
10+
metadataContext,
11+
isTestRunningContext
12+
} from '../../controller/DataManager.js'
13+
import type {
14+
TestEntry,
15+
RunCapabilities,
16+
RunnerOptions,
17+
TestRunDetail
18+
} from './types.js'
19+
import { TestState } from './types.js'
20+
import { DEFAULT_CAPABILITIES, FRAMEWORK_CAPABILITIES } from './constants.js'
1021

1122
import '~icons/mdi/play.js'
1223
import '~icons/mdi/stop.js'
@@ -17,45 +28,9 @@ import '~icons/mdi/expand-all.js'
1728
import './test-suite.js'
1829
import { CollapseableEntry } from './collapseableEntry.js'
1930
import type { DevtoolsSidebarFilter } from './filter.js'
20-
import type { TestRunDetail } from './test-suite.js'
2131

2232
const EXPLORER = 'wdio-devtools-sidebar-explorer'
2333

24-
interface TestEntry {
25-
uid: string
26-
state?: string
27-
label: string
28-
callSource?: string
29-
children: TestEntry[]
30-
type: 'suite' | 'test'
31-
specFile?: string
32-
fullTitle?: string
33-
featureFile?: string
34-
featureLine?: number
35-
suiteType?: string
36-
}
37-
38-
interface RunCapabilities {
39-
canRunSuites: boolean
40-
canRunTests: boolean
41-
}
42-
43-
type RunnerOptions = {
44-
framework?: string
45-
configFile?: string
46-
configFilePath?: string
47-
runCapabilities?: Partial<RunCapabilities>
48-
}
49-
50-
const DEFAULT_CAPABILITIES: RunCapabilities = {
51-
canRunSuites: true,
52-
canRunTests: true
53-
}
54-
55-
const FRAMEWORK_CAPABILITIES: Record<string, RunCapabilities> = {
56-
cucumber: { canRunSuites: true, canRunTests: false }
57-
}
58-
5934
@customElement(EXPLORER)
6035
export class DevtoolsSidebarExplorer extends CollapseableEntry {
6136
#testFilter: DevtoolsSidebarFilter | undefined
@@ -93,6 +68,9 @@ export class DevtoolsSidebarExplorer extends CollapseableEntry {
9368
@consume({ context: metadataContext, subscribe: true })
9469
metadata: Metadata | undefined = undefined
9570

71+
@consume({ context: isTestRunningContext, subscribe: true })
72+
isTestRunning = false
73+
9674
connectedCallback(): void {
9775
super.connectedCallback()
9876
window.addEventListener('app-test-filter', this.#filterListener)

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

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { html, css, nothing } from 'lit'
33
import { customElement, property } from 'lit/decorators.js'
44

55
import { CollapseableEntry } from './collapseableEntry.js'
6+
import type { TestRunDetail } from './types.js'
7+
import { TestState } from './types.js'
68

79
import '~icons/mdi/chevron-right.js'
810
import '~icons/mdi/play.js'
@@ -18,19 +20,6 @@ import '~icons/mdi/checkbox-blank-circle-outline.js'
1820

1921
const TEST_SUITE = 'wdio-test-suite'
2022

21-
export interface TestRunDetail {
22-
uid: string
23-
entryType: 'suite' | 'test'
24-
specFile?: string
25-
fullTitle?: string
26-
label?: string
27-
callSource?: string
28-
configFile?: string
29-
featureFile?: string
30-
featureLine?: number
31-
suiteType?: string
32-
}
33-
3423
@customElement(TEST_SUITE)
3524
export class ExplorerTestSuite extends Element {
3625
static styles = [
@@ -49,13 +38,6 @@ export class ExplorerTestSuite extends Element {
4938
}
5039
}
5140

52-
export enum TestState {
53-
PASSED = 'passed',
54-
FAILED = 'failed',
55-
RUNNING = 'running',
56-
SKIPPED = 'skipped'
57-
}
58-
5941
const TEST_ENTRY = 'wdio-test-entry'
6042
@customElement(TEST_ENTRY)
6143
export class ExplorerTestEntry extends CollapseableEntry {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
export interface TestEntry {
2+
uid: string
3+
state?: string
4+
label: string
5+
callSource?: string
6+
children: TestEntry[]
7+
type: 'suite' | 'test'
8+
specFile?: string
9+
fullTitle?: string
10+
featureFile?: string
11+
featureLine?: number
12+
suiteType?: string
13+
}
14+
15+
export interface RunCapabilities {
16+
canRunSuites: boolean
17+
canRunTests: boolean
18+
}
19+
20+
export interface RunnerOptions {
21+
framework?: string
22+
configFile?: string
23+
configFilePath?: string
24+
runCapabilities?: Partial<RunCapabilities>
25+
}
26+
27+
export interface TestRunDetail {
28+
uid: string
29+
entryType: 'suite' | 'test'
30+
specFile?: string
31+
fullTitle?: string
32+
label?: string
33+
callSource?: string
34+
configFile?: string
35+
featureFile?: string
36+
featureLine?: number
37+
suiteType?: string
38+
}
39+
40+
export enum TestState {
41+
PASSED = 'passed',
42+
FAILED = 'failed',
43+
RUNNING = 'running',
44+
SKIPPED = 'skipped'
45+
}

packages/app/src/controller/DataManager.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ export const suiteContext = createContext<Record<string, any>[]>(
4141
)
4242

4343
const hasConnection = createContext<boolean>(Symbol('hasConnection'))
44+
export const isTestRunningContext = createContext<boolean>(
45+
Symbol('isTestRunning')
46+
)
4447

4548
interface SocketMessage<
4649
T extends keyof TraceLog | 'testStopped' = keyof TraceLog | 'testStopped'

packages/backend/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import { WebSocket } from 'ws'
99

1010
import { getDevtoolsApp } from './utils.js'
1111
import { DEFAULT_PORT } from './constants.js'
12-
import { testRunner, type RunnerRequestBody } from './runner.js'
12+
import { testRunner } from './runner.js'
13+
import type { RunnerRequestBody } from './types.js'
1314

1415
let server: FastifyInstance | undefined
1516

packages/backend/src/runner.ts

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,19 @@ import path from 'node:path'
44
import url from 'node:url'
55
import { createRequire } from 'node:module'
66
import kill from 'tree-kill'
7+
import type { RunnerRequestBody } from './types.js'
8+
import { WDIO_CONFIG_FILENAMES } from './types.js'
79

810
const require = createRequire(import.meta.url)
911
const wdioBin = resolveWdioBin()
1012

11-
const WDIO_CONFIG_FILENAMES = [
12-
'wdio.conf.ts',
13-
'wdio.conf.js',
14-
'wdio.conf.cjs',
15-
'wdio.conf.mjs'
16-
]
17-
1813
/**
1914
* Escape special regex characters in a string
2015
*/
2116
function escapeRegex(str: string): string {
2217
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
2318
}
2419

25-
export interface RunnerRequestBody {
26-
uid: string
27-
entryType: 'suite' | 'test'
28-
specFile?: string
29-
fullTitle?: string
30-
label?: string
31-
callSource?: string
32-
runAll?: boolean
33-
framework?: string
34-
configFile?: string
35-
lineNumber?: number
36-
devtoolsHost?: string
37-
devtoolsPort?: number
38-
featureFile?: string
39-
featureLine?: number
40-
suiteType?: string
41-
}
42-
4320
const FRAMEWORK_FILTERS: Record<
4421
string,
4522
(ctx: { specArg?: string; payload: RunnerRequestBody }) => string[]

packages/backend/src/types.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export const WDIO_CONFIG_FILENAMES = [
2+
'wdio.conf.ts',
3+
'wdio.conf.js',
4+
'wdio.conf.cjs',
5+
'wdio.conf.mjs'
6+
] as const
7+
8+
export interface RunnerRequestBody {
9+
uid: string
10+
entryType: 'suite' | 'test'
11+
specFile?: string
12+
fullTitle?: string
13+
label?: string
14+
callSource?: string
15+
runAll?: boolean
16+
framework?: string
17+
configFile?: string
18+
lineNumber?: number
19+
devtoolsHost?: string
20+
devtoolsPort?: number
21+
featureFile?: string
22+
featureLine?: number
23+
suiteType?: string
24+
}

0 commit comments

Comments
 (0)