Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(webdriver): re-export command #10731

Merged
merged 3 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions e2e/interop/webdriver.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const assert = require('node:assert')
const chromedriver = require('chromedriver')
const WebDriver = require('../../packages/webdriver')

assert.equal(typeof WebDriver.command, 'function')

;(async () => {
await chromedriver.start(['--port=4444'])
const client = await WebDriver.newSession({
Expand Down
24 changes: 15 additions & 9 deletions packages/webdriver/src/cjs/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import type { Options } from '@wdio/types'
import type { Client, AttachOptions } from '../types.js'

function command (method: string, encodeUri: string, commandInfo: any, doubleEncodeVariables = false) {
return async function protocolCommand(this: unknown, ...args: unknown[]) {
const commandESM = await import('../command.js')
return commandESM.default(method, encodeUri, commandInfo, doubleEncodeVariables).apply(this, args)
}
}

class WebDriver {
static async newSession(
options: Options.WebDriver,
Expand All @@ -15,7 +22,7 @@ class WebDriver {
/**
* allows user to attach to existing sessions
*/
static async attachToSession(
static async attachToSession (
options?: AttachOptions,
modifier?: (...args: any[]) => any,
userPrototype = {},
Expand All @@ -32,20 +39,19 @@ class WebDriver {
* @param {object} instance the object we get from a new browser session.
* @returns {string} the new session id of the browser
*/
static async reloadSession(instance: Client) {
static async reloadSession (instance: Client) {
const WebDriver = (await import('../index.js')).default
return WebDriver.reloadSession(instance)
}

static get WebDriver() {
static get WebDriver () {
return WebDriver
}
}

module.exports = WebDriver
exports.command = (method: string, encodeUri: string, commandInfo: any, doubleEncodeVariables = false) => {
return async function protocolCommand(this: unknown, ...args: unknown[]) {
const commandESM = await import('../command.js')
return commandESM.default(method, encodeUri, commandInfo, doubleEncodeVariables).apply(this, args)
static get command () {
return command
}
}

module.exports = WebDriver
exports.command = command
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
exports.command = command
module.exports.command = command

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

module.exports = WebDriver which has command as static property, so it should be the same, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the test seem to pass:

const WebDriver = require('../../packages/webdriver')
const command = require('../../packages/webdriver').command

assert.equal(typeof WebDriver.command, 'function')
assert.equal(typeof command, 'function')

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh I didn't see the refactor above, this was a suggestion based on the initial commit. let me try.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep this should work now

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍