@wdio/globals 8.0.0-alpha.213

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE-MIT ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) OpenJS Foundation and other contributors
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ 'Software'), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,22 @@
1
+ WDIO Globals
2
+ ============
3
+
4
+ > A helper utility for importing global variables directly
5
+
6
+ This package can be used to import global variables explicitly, e.g.
7
+
8
+ ```ts
9
+ import { browser, $, $$, expect } from '@wdio/globals'
10
+
11
+ describe('my test', () => {
12
+ // ...
13
+
14
+ it('can do something', async () => {
15
+ // ...
16
+ })
17
+
18
+ // ...
19
+ })
20
+ ```
21
+
22
+ For more information on WebdriverIO Globals, check out the [docs](https://webdriver.io/docs/api/globals).
@@ -0,0 +1,16 @@
1
+ /// <reference types="types" />
2
+ declare type SupportedGlobals = 'browser' | 'driver' | 'multiremotebrowser' | '$' | '$$';
3
+ export declare const browser: WebdriverIO.Browser;
4
+ export declare const driver: WebdriverIO.Browser;
5
+ export declare const multiremotebrowser: WebdriverIO.MultiRemoteBrowser;
6
+ export declare const $: WebdriverIO.Browser['$'];
7
+ export declare const $$: WebdriverIO.Browser['$$'];
8
+ /**
9
+ * allows to set global property to be imported and used later on
10
+ * @param key global key
11
+ * @param value actual value to be returned
12
+ * @private
13
+ */
14
+ export declare function _setGlobal(key: SupportedGlobals, value: any, setGlobal?: boolean): void;
15
+ export {};
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,aAAK,gBAAgB,GAAG,SAAS,GAAG,QAAQ,GAAG,oBAAoB,GAAG,GAAG,GAAG,IAAI,CAAA;AAiBhF,eAAO,MAAM,OAAO,EAAE,WAAW,CAAC,OAGjC,CAAA;AACD,eAAO,MAAM,MAAM,EAAE,WAAW,CAAC,OAGhC,CAAA;AACD,eAAO,MAAM,kBAAkB,EAAE,WAAW,CAAC,kBAG5C,CAAA;AACD,eAAO,MAAM,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,CAKtC,CAAA;AACD,eAAO,MAAM,EAAE,EAAE,WAAW,CAAC,OAAO,CAAC,IAAI,CAKxC,CAAA;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAE,GAAG,EAAE,gBAAgB,EAAE,KAAK,EAAE,GAAG,EAAE,SAAS,UAAO,QAO9E"}
package/build/index.js ADDED
@@ -0,0 +1,44 @@
1
+ /// <reference path="../types.d.ts" />
2
+ const globals = new Map();
3
+ const GLOBALS_ERROR_MESSAGE = 'Don\'t import @wdio/globals outside of the WDIO testrunner context';
4
+ function proxyHandler(key) {
5
+ return {
6
+ get: (self, prop) => {
7
+ if (!globals.has(key)) {
8
+ throw new Error(GLOBALS_ERROR_MESSAGE);
9
+ }
10
+ return globals.get(key)[prop];
11
+ }
12
+ };
13
+ }
14
+ export const browser = new Proxy(class Browser {
15
+ }, proxyHandler('browser'));
16
+ export const driver = new Proxy(class Browser {
17
+ }, proxyHandler('driver'));
18
+ export const multiremotebrowser = new Proxy(class Browser {
19
+ }, proxyHandler('multiremotebrowser'));
20
+ export const $ = (...args) => {
21
+ if (!globals.has('$')) {
22
+ throw new Error(GLOBALS_ERROR_MESSAGE);
23
+ }
24
+ return globals.get('$')(...args);
25
+ };
26
+ export const $$ = (...args) => {
27
+ if (!globals.has('$$')) {
28
+ throw new Error(GLOBALS_ERROR_MESSAGE);
29
+ }
30
+ return globals.get('$$')(...args);
31
+ };
32
+ /**
33
+ * allows to set global property to be imported and used later on
34
+ * @param key global key
35
+ * @param value actual value to be returned
36
+ * @private
37
+ */
38
+ export function _setGlobal(key, value, setGlobal = true) {
39
+ globals.set(key, value);
40
+ if (setGlobal) {
41
+ // @ts-expect-error
42
+ globalThis[key] = value;
43
+ }
44
+ }
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@wdio/globals",
3
+ "version": "8.0.0-alpha.213+c5fb6d57e",
4
+ "description": "A helper utility for importing global variables directly",
5
+ "author": "Christian Bromann <mail@bromann.dev>",
6
+ "homepage": "https://github.com/webdriverio/webdriverio/tree/main/packages/wdio-globals",
7
+ "license": "MIT",
8
+ "type": "module",
9
+ "exports": "./build/index.js",
10
+ "types": "./build/index.d.ts",
11
+ "typeScriptVersion": "3.8.3",
12
+ "engines": {
13
+ "node": "^16.13 || >=18"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git://github.com/webdriverio/webdriverio.git"
18
+ },
19
+ "keywords": [
20
+ "webdriver",
21
+ "wdio",
22
+ "wdio-utility"
23
+ ],
24
+ "bugs": {
25
+ "url": "https://github.com/webdriverio/webdriverio/issues"
26
+ },
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "dependencies": {
31
+ "webdriverio": "8.0.0-alpha.213+c5fb6d57e"
32
+ },
33
+ "gitHead": "c5fb6d57e168d8bf939a5aa5c2ada5abaceec5eb"
34
+ }
package/types.d.ts ADDED
@@ -0,0 +1,30 @@
1
+ type BrowserType = import('webdriverio').Browser<'async'>
2
+ type ElementType = import('webdriverio').Element<'async'>
3
+ type MultiRemoteBrowserType = import('webdriverio').MultiRemoteBrowser<'async'>
4
+
5
+ declare namespace WebdriverIOAsync {
6
+ interface Browser {}
7
+ interface Element {}
8
+ interface MultiRemoteBrowser {}
9
+ }
10
+
11
+ declare namespace WebdriverIO {
12
+ interface Browser extends BrowserType, WebdriverIOAsync.Browser { }
13
+ interface Element extends ElementType, WebdriverIOAsync.Element { }
14
+ // @ts-expect-error
15
+ interface MultiRemoteBrowser extends MultiRemoteBrowserType, WebdriverIOAsync.MultiRemoteBrowser { }
16
+ }
17
+
18
+ declare module NodeJS {
19
+ interface Global {
20
+ browser: WebdriverIO.Browser
21
+ driver: WebdriverIO.Browser
22
+ multiremotebrowser: WebdriverIO.MultiRemoteBrowser
23
+ }
24
+ }
25
+
26
+ declare function $(...args: Parameters<WebdriverIO.Browser['$']>): ReturnType<WebdriverIO.Browser['$']>
27
+ declare function $$(...args: Parameters<WebdriverIO.Browser['$$']>): ReturnType<WebdriverIO.Browser['$$']>
28
+ declare const browser: WebdriverIO.Browser
29
+ declare const driver: WebdriverIO.Browser
30
+ declare const multiremotebrowser: WebdriverIO.MultiRemoteBrowser