Skip to content

Commit 15fe344

Browse files
committed
further prep for v4 official
make migrate work as bin make plugin types aligned with side-api (so ide is documented by intellisense too)
1 parent 305a0ba commit 15fe344

File tree

17 files changed

+128
-59
lines changed

17 files changed

+128
-59
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"test:e2e": "jest --testMatch \"**/packages/**/__tests__/**/*.e2e.js\"",
1919
"lint": "pnpm run lint:scripts",
2020
"lint:scripts": "eslint --ignore-pattern node_modules --ignore-pattern third-party --ignore-pattern dist --ignore-pattern build --ignore-pattern json --ext .ts,.tsx --ext .js packages/",
21+
"test:ide": "npm-run-bg -s 'http-server -p 8080 ./tests/static::Available on::8080' 'node ./packages/side-runner/dist/bin.js -t 15000 ./tests/examples/*.side'",
2122
"test:side-runner": "npm-run-bg -s 'http-server -p 8080 ./tests/static::Available on::8080' 'node ./packages/side-runner/dist/bin.js -t 15000 ./tests/examples/*.side'",
2223
"test:side-runner:ci": "npm-run-bg -s 'http-server -p 8080 ./tests/static::Available on::8080' 'node ./packages/side-runner/dist/bin.js -c \"goog:chromeOptions.args=[headless,no-sandbox] browserName=chrome\" -t 15000 ./tests/examples/*.side'",
2324
"typecheck": "tsc --noEmit --composite false",

packages/selenium-ide/src/browser/windows/PlaybackWindow/preload/recorder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
ExpandedMutationObserver,
2525
} from 'browser/types'
2626
import initFindSelect from './find-select'
27-
import { PluginPreloadOutputShape } from '@seleniumhq/side-runtime'
27+
import { PluginPreloadOutputShape } from '@seleniumhq/side-api'
2828

2929
export interface RecordingState {
3030
typeTarget: HTMLElement | null

packages/selenium-ide/src/main/session/controllers/Commands/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Commands from '@seleniumhq/side-model/dist/Commands'
2-
import { CustomCommandShape, PluginShape } from '@seleniumhq/side-runtime'
2+
import { CustomCommandShape } from '@seleniumhq/side-runtime'
33
import BaseController from '../Base'
4+
import { PluginShape } from '@seleniumhq/side-api'
45

56
const serializeCustomCommands = (commands: PluginShape['commands'] = {}) =>
67
Object.fromEntries(

packages/selenium-ide/src/main/session/controllers/Plugins/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { correctPluginPaths, loadPlugins, PluginShape } from '@seleniumhq/side-runtime'
1+
import { PluginShape } from '@seleniumhq/side-api'
2+
import { correctPluginPaths, loadPlugins } from '@seleniumhq/side-runtime'
23
import { ipcMain } from 'electron'
34
import storage from 'main/store'
45
import BaseController from '../Base'

packages/selenium-ide/src/main/session/controllers/Windows/index.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,24 @@ export default class WindowsController extends BaseController {
173173
return true
174174
}
175175

176+
async openCustom(
177+
name: string,
178+
filepath: string,
179+
opts: BrowserWindowConstructorOptions = {}
180+
) {
181+
const window = new BrowserWindow({
182+
...opts,
183+
webPreferences: {
184+
// This should be the default preload, which just adds the sideAPI to the window
185+
preload: join(__dirname, `project-editor-preload-bundle.js`),
186+
...opts?.webPreferences ?? {},
187+
},
188+
})
189+
this.windows[name] = window
190+
await window.loadURL(`file://${filepath}`)
191+
return true
192+
}
193+
176194
async openPlaybackWindow(opts: BrowserWindowConstructorOptions = {}) {
177195
const window = this.windowLoaders[playbackWindowName](opts)
178196
this.handlePlaybackWindow(window)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
import type { Shape as Close } from './close'
2+
import type { Shape as OpenCustom } from './openCustom'
23
import type { Shape as Open } from './open'
34

45
import * as close from './close'
56
import * as open from './open'
7+
import * as openCustom from './openCustom'
68

79
export const commands = {
810
close,
911
open,
12+
openCustom,
1013
}
1114

1215
export type Shape = {
1316
close: Close
1417
open: Open
18+
openCustom: OpenCustom
1519
}

packages/side-api/src/types.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { ProjectShape } from '@seleniumhq/side-model'
22
import { Chrome } from '@seleniumhq/browser-info'
33
import { Browser } from '@seleniumhq/get-driver'
44
import { StateShape } from './models/state'
5+
import { PluginRuntimeShape } from '@seleniumhq/side-runtime'
56

67
export interface BrowserInfo extends Pick<Chrome.BrowserInfo, 'version'> {
78
browser: Browser
@@ -78,6 +79,33 @@ export type EventListenerParams<LISTENER extends BaseListener<any>> =
7879

7980
export type LocatorFields = 'target' | 'value'
8081

82+
export interface NewCommandShape {
83+
command: string
84+
target: string | [string, string][]
85+
value: string | [string, string][]
86+
insertBeforeLastCommand: boolean
87+
frameLocation: string
88+
winHandleId: string
89+
}
90+
91+
export interface onCommandRecordedDropResult {
92+
action: 'drop'
93+
}
94+
export interface OnCommandRecordedUpdateResult {
95+
action: 'update'
96+
command: NewCommandShape
97+
}
98+
99+
export type OnCommandRecordedResult =
100+
| void
101+
| onCommandRecordedDropResult
102+
| OnCommandRecordedUpdateResult
103+
104+
export type PluginHookInput = {
105+
logger: Console
106+
project: ProjectShape
107+
} & Record<string, unknown>
108+
81109
export interface RecordNewCommandInput {
82110
command: string
83111
target: string | [string, string][]
@@ -86,3 +114,30 @@ export interface RecordNewCommandInput {
86114
frameLocation?: string
87115
winHandleId?: string
88116
}
117+
118+
export type PluginMenuConfigurator = (api: BaseApi) => void
119+
120+
export interface PluginShape extends PluginRuntimeShape {
121+
menus?: {
122+
[key: string]: (
123+
session: CoreSessionData
124+
) => (
125+
...args: any[]
126+
) => (Electron.MenuItemConstructorOptions | Electron.MenuItem)[]
127+
}
128+
}
129+
130+
export interface PluginPreloadOutputShape {
131+
hooks: {
132+
onCommandRecorded?: (
133+
command: NewCommandShape,
134+
event: Event | KeyboardEvent | MouseEvent | MutationRecord[] | undefined
135+
) => OnCommandRecordedResult
136+
}
137+
}
138+
139+
export type SendMessage = (...args: any[]) => void
140+
141+
export type PluginPreloadShape = (
142+
sendMessage: SendMessage
143+
) => PluginPreloadOutputShape

packages/side-example-suite/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"@seleniumhq/code-export-python-pytest": "4.0.0-alpha.2"
2222
},
2323
"devDependencies": {
24+
"@seleniumhq/side-api": "^4.0.0-alpha.26",
2425
"@seleniumhq/side-runtime": "^4.0.0-alpha.26"
2526
},
2627
"repository": {

packages/side-example-suite/src/plugins/custom-click/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PluginShape } from '@seleniumhq/side-runtime'
1+
import { PluginShape } from '@seleniumhq/side-api'
22

33
/**
44
* This is a demo plugin that takes the default click command, adds a new "customClick" command,

packages/side-example-suite/src/plugins/custom-click/preload/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { PluginPreloadShape } from '@seleniumhq/side-runtime'
1+
import { PluginPreloadShape, SendMessage } from '@seleniumhq/side-api'
22

33
export let clickCount = 0
4-
export type SendMessage = (...args: any[]) => void
54

65
/**
76
* This is the preload script for the plugin. It runs in the browser context

0 commit comments

Comments
 (0)