@wdio/globals 7.20.8-alpha.504

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,18 @@
1
+ /// <reference types="./standalone" />
2
+ /// <reference types="types" />
3
+ declare type SupportedGlobals = 'browser' | 'driver' | 'multiremotebrowser' | '$' | '$$' | 'expect';
4
+ export declare const browser: WebdriverIO.Browser;
5
+ export declare const driver: WebdriverIO.Browser;
6
+ export declare const multiremotebrowser: WebdriverIO.MultiRemoteBrowser;
7
+ export declare const $: WebdriverIO.Browser['$'];
8
+ export declare const $$: WebdriverIO.Browser['$$'];
9
+ export declare const expect: ExpectWebdriverIO.Expect;
10
+ /**
11
+ * allows to set global property to be imported and used later on
12
+ * @param key global key
13
+ * @param value actual value to be returned
14
+ * @private
15
+ */
16
+ export declare function _setGlobal(key: SupportedGlobals, value: any, setGlobal?: boolean): void;
17
+ export {};
18
+ //# 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,GAAG,QAAQ,CAAA;AAiB3F,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;AACD,eAAO,MAAM,MAAM,EAAE,iBAAiB,CAAC,MAKT,CAAA;AAU9B;;;;;GAKG;AACH,wBAAgB,UAAU,CAAE,GAAG,EAAE,gBAAgB,EAAE,KAAK,EAAE,GAAG,EAAE,SAAS,UAAO,QAO9E"}
package/build/index.js ADDED
@@ -0,0 +1,57 @@
1
+ /// <reference path="../types.d.ts" />
2
+ const globals = new Map();
3
+ const GLOBALS_ERROR_MESSAGE = 'No browser instance registered. Don\'t import @wdio/globals outside of the WDIO testrunner context. Or you have two two different "@wdio/globals" packages installed.';
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
+ export const expect = ((...args) => {
33
+ if (!globals.has('expect')) {
34
+ throw new Error(GLOBALS_ERROR_MESSAGE);
35
+ }
36
+ return globals.get('expect')(...args);
37
+ });
38
+ expect.extend = (...args) => {
39
+ if (!globals.has('expect')) {
40
+ throw new Error(GLOBALS_ERROR_MESSAGE);
41
+ }
42
+ const expect = globals.get('expect');
43
+ return expect.extend(...args);
44
+ };
45
+ /**
46
+ * allows to set global property to be imported and used later on
47
+ * @param key global key
48
+ * @param value actual value to be returned
49
+ * @private
50
+ */
51
+ export function _setGlobal(key, value, setGlobal = true) {
52
+ globals.set(key, value);
53
+ if (setGlobal) {
54
+ // @ts-expect-error
55
+ globalThis[key] = value;
56
+ }
57
+ }
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@wdio/globals",
3
+ "version": "7.20.8-alpha.504+428a9d729",
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
+ "directory": "packages/wdio-globals"
19
+ },
20
+ "keywords": [
21
+ "webdriver",
22
+ "wdio",
23
+ "wdio-utility"
24
+ ],
25
+ "bugs": {
26
+ "url": "https://github.com/webdriverio/webdriverio/issues"
27
+ },
28
+ "publishConfig": {
29
+ "access": "public"
30
+ },
31
+ "dependencies": {
32
+ "expect-webdriverio": "^4.0.0-alpha.3",
33
+ "webdriverio": "7.20.8-alpha.504+428a9d729"
34
+ },
35
+ "gitHead": "428a9d729ae6231968a60908732fa3f607d195e9"
36
+ }
package/types.d.ts ADDED
@@ -0,0 +1,36 @@
1
+ type BrowserType = import('webdriverio').Browser<'async'>
2
+ type ElementType = import('webdriverio').Element<'async'>
3
+ type ElementArrayType = import('webdriverio').ElementArray
4
+ type MultiRemoteBrowserType = import('webdriverio').MultiRemoteBrowser<'async'>
5
+ type ExpectWebdriverIO = import('expect-webdriverio')
6
+
7
+ declare namespace WebdriverIOAsync {
8
+ interface Browser {}
9
+ interface Element {}
10
+ interface ElementArray {}
11
+ interface MultiRemoteBrowser {}
12
+ }
13
+
14
+ declare namespace WebdriverIO {
15
+ interface Browser extends BrowserType, WebdriverIOAsync.Browser { }
16
+ interface Element extends ElementType, WebdriverIOAsync.Element { }
17
+ interface ElementArray extends ElementArrayType, WebdriverIOAsync.ElementArray { }
18
+ // @ts-expect-error
19
+ interface MultiRemoteBrowser extends MultiRemoteBrowserType, WebdriverIOAsync.MultiRemoteBrowser { }
20
+ }
21
+
22
+ declare module NodeJS {
23
+ interface Global {
24
+ browser: WebdriverIO.Browser
25
+ driver: WebdriverIO.Browser
26
+ multiremotebrowser: WebdriverIO.MultiRemoteBrowser
27
+ expect: ExpectWebdriverIO.Expect
28
+ }
29
+ }
30
+
31
+ declare function $(...args: Parameters<WebdriverIO.Browser['$']>): ReturnType<WebdriverIO.Browser['$']>
32
+ declare function $$(...args: Parameters<WebdriverIO.Browser['$$']>): ReturnType<WebdriverIO.Browser['$$']>
33
+ declare const browser: WebdriverIO.Browser
34
+ declare const driver: WebdriverIO.Browser
35
+ declare const multiremotebrowser: WebdriverIO.MultiRemoteBrowser
36
+ declare const expect: ExpectWebdriverIO.Expect