Skip to content

Commit 8e1d7bd

Browse files
launch devtools application as part of launcher service
1 parent 4cd787d commit 8e1d7bd

File tree

15 files changed

+1336
-94
lines changed

15 files changed

+1336
-94
lines changed

example/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
"name": "examples",
33
"type": "module",
44
"devDependencies": {
5-
"@wdio/cli": "8.23.0",
6-
"@wdio/cucumber-framework": "^8.23.0",
7-
"@wdio/local-runner": "^8.23.0",
8-
"@wdio/spec-reporter": "^8.23.0",
5+
"@wdio/cli": "8.24.16",
6+
"@wdio/cucumber-framework": "^8.24.13",
7+
"@wdio/local-runner": "^8.24.12",
8+
"@wdio/spec-reporter": "^8.24.12",
99
"ts-node": "^10.9.1",
10-
"typescript": "^5.2.2"
10+
"typescript": "^5.3.3"
1111
},
1212
"scripts": {
1313
"wdio": "wdio run ./wdio.conf.ts"

example/wdio.conf.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Options } from '@wdio/types'
22
import { DevToolsHookService } from '../packages/hook/dist/index.js'
3+
import { DevToolsAppLauncher } from '../packages/hook/dist/launcher.js'
34

45
export const config: Options.Testrunner = {
56
//
@@ -119,7 +120,10 @@ export const config: Options.Testrunner = {
119120
// Services take over a specific job you don't want to take care of. They enhance
120121
// your test setup with almost no effort. Unlike plugins, they don't add new
121122
// commands. Instead, they hook themselves up into the test process.
122-
services: [[DevToolsHookService, {}]],
123+
services: [
124+
[DevToolsHookService, {}],
125+
[DevToolsAppLauncher, {}]
126+
],
123127
//
124128
// Framework you want to run your specs with.
125129
// The following are supported: Mocha, Jasmine, and Cucumber

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
"name": "devtools-monorepo",
33
"type": "module",
44
"scripts": {
5-
"dev": "pnpm --parallel dev",
65
"build": "pnpm --parallel build",
6+
"demo": "wdio run ./example/wdio.conf.ts",
7+
"dev": "pnpm --parallel dev",
78
"preview": "pnpm --parallel preview",
89
"test": "pnpm --parallel test",
910
"watch": "pnpm build --watch"

packages/app/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"@codemirror/view": "^6.22.0",
1717
"@iconify-json/mdi": "^1.1.54",
1818
"@lit/context": "^1.0.1",
19-
"@wdio/devtools-hook": "workspace:^",
2019
"@wdio/protocols": "^8.23.0",
2120
"codemirror": "^6.0.1",
2221
"lit": "^2.7.6",

packages/backend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"dependencies": {
2121
"@fastify/static": "^6.12.0",
2222
"@wdio/devtools-app": "workspace:^",
23+
"@wdio/logger": "^8.24.12",
2324
"fastify": "^4.24.3",
2425
"get-port": "^7.0.0",
2526
"import-meta-resolve": "^4.0.0"

packages/backend/src/index.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import url from 'node:url'
33
import Fastify, { type FastifyInstance } from 'fastify'
44
import staticServer from '@fastify/static'
55
import getPort from 'get-port'
6+
import logger from '@wdio/logger'
67

78
import { getDevtoolsApp } from './utils.js'
89
import { DEFAULT_PORT } from './constants.js'
@@ -13,6 +14,8 @@ interface DevtoolsBackendOptions {
1314
port?: number
1415
}
1516

17+
const log = logger('@wdio/devtools-backend')
18+
1619
export async function start (opts: DevtoolsBackendOptions = {}) {
1720
const port = opts.port || await getPort({ port: DEFAULT_PORT })
1821
const appPath = await getDevtoolsApp()
@@ -22,14 +25,9 @@ export async function start (opts: DevtoolsBackendOptions = {}) {
2225
root: appPath
2326
})
2427

25-
// Run the server!
26-
try {
27-
await server.listen({ port })
28-
console.log(`WebdriverIO Devtools started on port ${port}`)
29-
} catch (err) {
30-
server.log.error(err)
31-
process.exit(1)
32-
}
28+
log.info(`Starting WebdriverIO Devtools application on port ${port}`)
29+
await server.listen({ port })
30+
return server
3331
}
3432

3533
export async function stop () {
@@ -40,6 +38,9 @@ export async function stop () {
4038
await server.close()
4139
}
4240

41+
/**
42+
* start server if this file is called directly
43+
*/
4344
if (import.meta.url.startsWith('file:')) {
4445
const modulePath = url.fileURLToPath(import.meta.url)
4546
if (process.argv[1] === modulePath) {

packages/backend/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"outDir": "dist",
77
"rootDir": "src",
88
"noEmit": false,
9-
"allowImportingTsExtensions": false
9+
"allowImportingTsExtensions": false,
10+
"declaration": true
1011
},
1112
"include": ["src/**/*"]
1213
}

packages/hook/package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
"import": "./dist/types.ts",
1111
"types": "./dist/types.d.ts",
1212
"node": "./dist/types.js"
13+
},
14+
"./launcher": {
15+
"import": "./dist/launcher.ts",
16+
"types": "./dist/launcher.d.ts",
17+
"node": "./dist/launcher.js"
1318
}
1419
},
1520
"types": "./dist/index.d.ts",
@@ -20,19 +25,20 @@
2025
"test": "eslint ."
2126
},
2227
"dependencies": {
28+
"@wdio/devtools-backend": "workspace:^",
2329
"@wdio/devtools-script": "workspace:^",
2430
"@wdio/reporter": "^8.23.0",
2531
"@wdio/types": "^8.23.0",
2632
"import-meta-resolve": "^4.0.0",
27-
"stack-trace": "1.0.0-pre2"
33+
"stack-trace": "1.0.0-pre2",
34+
"webdriverio": "^8.23.0"
2835
},
2936
"license": "MIT",
3037
"devDependencies": {
3138
"@types/stack-trace": "^0.0.33",
3239
"@wdio/globals": "^8.23.0",
3340
"@wdio/protocols": "^8.23.0",
34-
"vite-plugin-dts": "^3.6.3",
35-
"webdriverio": "^8.23.0"
41+
"vite-plugin-dts": "^3.6.3"
3642
},
3743
"peerDependencies": {
3844
"@wdio/protocols": "^8.20.4",

packages/hook/src/constants.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,10 @@ export const PAGE_TRANSITION_COMMANDS: string[] = [
33
'navigateTo',
44
'elementClick'
55
]
6+
7+
export const DEFAULT_LAUNCH_CAPS: WebdriverIO.Capabilities = {
8+
browserName: 'chrome',
9+
'goog:chromeOptions': {
10+
args: ['--window-size=1200,800']
11+
}
12+
}

packages/hook/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ import type { Services, Reporters } from '@wdio/types'
99

1010
import { SessionCapturer } from './session.js'
1111
import { TestReporter } from './reporter.js'
12+
import { DevToolsAppLauncher } from './launcher.js'
1213
import { getBrowserObject } from './utils.ts'
1314
import { type TraceLog, TraceType } from './types.ts'
1415

16+
export const launcher = DevToolsAppLauncher
17+
1518
/**
1619
* Setup WebdriverIO Devtools hook for standalone instances
1720
*/

0 commit comments

Comments
 (0)