forked from webdriverio/webdriverio
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(webdriver): use undici for requests in Node.js (webdriverio#13852)
* fix(webdriver): use undici for requests in Node.js * apply changes from webdriverio#13783 * conditional environment * fix tests * fix interop
- Loading branch information
1 parent
6e2650c
commit 5218796
Showing
30 changed files
with
487 additions
and
398 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,13 +5,16 @@ | |
"author": "Christian Bromann <[email protected]>", | ||
"homepage": "https://github.com/webdriverio/webdriverio/tree/main/packages/webdriver", | ||
"license": "MIT", | ||
"main": "./build/index.cjs", | ||
"type": "module", | ||
"main": "./build/index.cjs", | ||
"module": "./build/index.js", | ||
"exports": { | ||
".": { | ||
"types": "./build/index.d.ts", | ||
"import": "./build/index.js", | ||
"browserSource": "./src/browser.js", | ||
"browser": "./build/index.js", | ||
"importSource": "./src/node.ts", | ||
"import": "./build/node.js", | ||
"requireSource": "./src/index.cts", | ||
"require": "./build/index.cjs" | ||
} | ||
|
@@ -41,6 +44,7 @@ | |
"@wdio/types": "workspace:*", | ||
"@wdio/utils": "workspace:*", | ||
"deepmerge-ts": "^7.0.3", | ||
"undici": "^6.20.1", | ||
"ws": "^8.8.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import WebDriver from './index.js' | ||
import { BrowserSocket } from './bidi/socket.js' | ||
import { FetchRequest } from './request/web.js' | ||
|
||
export default WebDriver | ||
export * from './index.js' | ||
|
||
import { environment } from './environment.js' | ||
|
||
environment.value = { | ||
Request: FetchRequest, | ||
Socket: BrowserSocket, | ||
variables: {} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import type { BrowserSocket } from './bidi/socket.js' | ||
import type { FetchRequest } from './request/web.js' | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const isNode = !!(typeof process !== 'undefined' && process.version) | ||
|
||
export interface EnvironmentVariables { | ||
WEBDRIVER_CACHE_DIR?: string | ||
PROXY_URL?: string | ||
} | ||
|
||
export interface EnvironmentDependencies { | ||
Request: typeof FetchRequest, | ||
Socket: typeof BrowserSocket, | ||
variables: EnvironmentVariables | ||
} | ||
|
||
/** | ||
* Holder for environment dependencies. These dependencies cannot | ||
* be used during the module instantiation. | ||
*/ | ||
export const environment: { | ||
value: EnvironmentDependencies; | ||
} = { | ||
value: { | ||
get Request(): EnvironmentDependencies['Request'] { | ||
throw new Error('Request is not available in this environment') | ||
}, | ||
get Socket(): EnvironmentDependencies['Socket'] { | ||
throw new Error('Socket is not available in this environment') | ||
}, | ||
get variables(): EnvironmentDependencies['variables'] { | ||
return {} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import os from 'node:os' | ||
import ws from 'ws' | ||
|
||
import WebDriver from './index.js' | ||
import { FetchRequest } from './request/node.js' | ||
import { FetchRequest as WebFetchRequest } from './request/web.js' | ||
import type { BrowserSocket } from './bidi/socket.js' | ||
|
||
export default WebDriver | ||
export * from './index.js' | ||
|
||
import { environment } from './environment.js' | ||
|
||
environment.value = { | ||
Request: ( | ||
/** | ||
* Currently Nock doesn't support the mocking of undici requests, therefore for all | ||
* Smoke test we use the native fetch implementation. | ||
* | ||
* @see https://github.com/nock/nock/issues/2183#issuecomment-2252525890 | ||
*/ | ||
process.env.WDIO_USE_NATIVE_FETCH || | ||
/** | ||
* For unit tests we use the WebFetchRequest implementation as we can better mock the | ||
* requests in the unit tests. | ||
*/ | ||
process.env.WDIO_UNIT_TESTS | ||
) ? WebFetchRequest : FetchRequest, | ||
Socket: ws as unknown as typeof BrowserSocket, | ||
variables: { | ||
WEBDRIVER_CACHE_DIR: process.env.WEBDRIVER_CACHE_DIR || os.tmpdir(), | ||
PROXY_URL: process.env.HTTP_PROXY || process.env.HTTPS_PROXY | ||
} | ||
} | ||
|
Oops, something went wrong.