@wdio/shared-store-service 9.0.0-alpha.9 → 9.0.1

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.
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAYjD,eAAO,MAAM,OAAO,SAAU,MAAM,SAQnC,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,QAAQ,QAAe,MAAM,KAAG,QAAQ,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,UAAU,GAAG,SAAS,GAAG,IAAI,GAAG,SAAS,CAWzH,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,QAAQ,QAAe,MAAM,SAAS,cAAc,GAAG,aAAa,2BAUhF,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,eAAe,QAAe,MAAM,6CAUhD,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,QAAe,MAAM,YAAY,eAAe,iBAW5E,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,cAAc,QAAe,MAAM,SAAS,aAAa,GAAG,cAAc,oBAWtF,CAAA"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAYjD,eAAO,MAAM,OAAO,SAAU,MAAM,SAQnC,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,QAAQ,QAAe,MAAM,KAAG,OAAO,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,UAAU,GAAG,SAAS,GAAG,IAAI,GAAG,SAAS,CAWzH,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,QAAQ,QAAe,MAAM,SAAS,cAAc,GAAG,aAAa,2BAUhF,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,eAAe,QAAe,MAAM,SAAS,SAAS,2BAUlE,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,QAAe,MAAM,YAAY,eAAe,iBAW5E,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,cAAc,QAAe,MAAM,SAAS,aAAa,GAAG,cAAc,oBAWtF,CAAA"}
@@ -0,0 +1,47 @@
1
+ const __importMetaUrl = require('url').pathToFileURL(__filename).href;
2
+ "use strict";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
18
+ // If the importer is in node compatibility mode or this is not an ESM
19
+ // file that has been converted to a CommonJS file using a Babel-
20
+ // compatible transform (i.e. "__esModule" has not been set), then set
21
+ // "default" to the CommonJS "module.exports" for node compatibility.
22
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
23
+ mod
24
+ ));
25
+
26
+ // src/index.cts
27
+ var esmModule = import("./index.js");
28
+ exports.setValue = async function(key, value) {
29
+ const m = await esmModule;
30
+ return m.setValue(key, value);
31
+ };
32
+ exports.getValue = async function(key) {
33
+ const m = await esmModule;
34
+ return m.getValue(key);
35
+ };
36
+ exports.setResourcePool = async function(key, value) {
37
+ const m = await esmModule;
38
+ return m.setResourcePool(key, value);
39
+ };
40
+ exports.getValueFromPool = async function(key, options) {
41
+ const m = await esmModule;
42
+ return m.getValueFromPool(key, options);
43
+ };
44
+ exports.addValueToPool = async function(key, value) {
45
+ const m = await esmModule;
46
+ return m.addValueToPool(key, value);
47
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.cts"],"names":[],"mappings":""}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAE3E,OAAO,mBAAmB,MAAM,eAAe,CAAA;AAC/C,OAAO,kBAAkB,MAAM,cAAc,CAAA;AAC7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAEjD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,eAAe,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AACnG,eAAe,kBAAkB,CAAA;AACjC,eAAO,MAAM,QAAQ,4BAAsB,CAAA;AAE3C,MAAM,WAAW,gBAAgB;IAC7B,WAAW,EAAE;QACT,GAAG,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,aAAa,GAAG,cAAc,CAAC;QACrD,GAAG,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,GAAG,cAAc,KAAK,IAAI,CAAC;QAClE,eAAe,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,KAAK,IAAI,CAAC;QACzD,gBAAgB,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,KAAK,aAAa,GAAG,cAAc,CAAC;QAC5F,cAAc,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,GAAG,cAAc,KAAK,IAAI,CAAC;KAChF,CAAA;CACJ;AAED,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,WAAW,CAAC;QAClB,UAAU,OAAQ,SAAQ,gBAAgB;SAAI;QAC9C,UAAU,kBAAmB,SAAQ,gBAAgB;SAAI;KAC5D;CACJ"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAE3E,OAAO,mBAAmB,MAAM,eAAe,CAAA;AAC/C,OAAO,kBAAkB,MAAM,cAAc,CAAA;AAC7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAEjD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,eAAe,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AACnG,eAAe,kBAAkB,CAAA;AACjC,eAAO,MAAM,QAAQ,4BAAsB,CAAA;AAE3C,MAAM,WAAW,gBAAgB;IAC7B,WAAW,EAAE;QACT,GAAG,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,aAAa,GAAG,cAAc,CAAC;QACrD,GAAG,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,GAAG,cAAc,KAAK,IAAI,CAAC;QAClE,eAAe,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,KAAK,IAAI,CAAC;QACzD,gBAAgB,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,KAAK,aAAa,GAAG,cAAc,CAAC;QAC5F,cAAc,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,GAAG,cAAc,KAAK,IAAI,CAAC;KAChF,CAAA;CACJ;AAED,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,WAAW,CAAC;QAClB,UAAU,OAAQ,SAAQ,gBAAgB;SAAI;QAC9C,UAAU,kBAAmB,SAAQ,gBAAgB;SAAI;KAC5D;CACJ"}
package/build/index.js CHANGED
@@ -1,5 +1,268 @@
1
- import SharedStoreLauncher from './launcher.js';
2
- import SharedStoreService from './service.js';
3
- export { getValue, setValue, setResourcePool, getValueFromPool, addValueToPool } from './client.js';
4
- export default SharedStoreService;
5
- export const launcher = SharedStoreLauncher;
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
+ var __esm = (fn, res) => function __init() {
4
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
5
+ };
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+
11
+ // src/server.ts
12
+ var server_exports = {};
13
+ __export(server_exports, {
14
+ __resourcePoolStore: () => __resourcePoolStore,
15
+ __store: () => __store,
16
+ startServer: () => startServer
17
+ });
18
+ import polka from "polka";
19
+ import { json } from "@polka/parse";
20
+ var store, resourcePoolStore, __store, __resourcePoolStore, validateBody, MAX_TIMEOUT, DEFAULT_TIMEOUT, startServer;
21
+ var init_server = __esm({
22
+ "src/server.ts"() {
23
+ "use strict";
24
+ store = {};
25
+ resourcePoolStore = /* @__PURE__ */ new Map();
26
+ __store = store;
27
+ __resourcePoolStore = resourcePoolStore;
28
+ validateBody = (req, res, next) => {
29
+ if (!req.path.endsWith("/get") && !req.path.endsWith("/set")) {
30
+ return next();
31
+ }
32
+ if (req.method === "POST" && typeof req.body.key !== "string") {
33
+ res.end(JSON.stringify({ error: "Invalid payload, key is required." }));
34
+ }
35
+ next();
36
+ };
37
+ MAX_TIMEOUT = 15e3;
38
+ DEFAULT_TIMEOUT = 1e3;
39
+ startServer = () => new Promise((resolve, reject) => {
40
+ const app = polka().use(json(), validateBody).post("/", (req, res) => {
41
+ const key = req.body.key;
42
+ if (key === "*") {
43
+ throw new Error(`You can't set a value with key "*" as this is a reserved key`);
44
+ }
45
+ store[key] = req.body.value;
46
+ return res.end();
47
+ }).get("/:key", (req, res) => {
48
+ const key = req.params.key;
49
+ const value = key === "*" ? store : store[key];
50
+ res.end(JSON.stringify({ value }));
51
+ }).post("/pool", (req, res, next) => {
52
+ const key = req.body.key;
53
+ const value = req.body.value;
54
+ if (!Array.isArray(value)) {
55
+ return next("Resource pool must be an array of values");
56
+ }
57
+ resourcePoolStore.set(key, value);
58
+ return res.end();
59
+ }).get("/pool/:key", async (req, res, next) => {
60
+ const key = req.params.key;
61
+ if (!resourcePoolStore.has(key)) {
62
+ return next(`'${key}' resource pool does not exist. Set it first using 'setResourcePool'`);
63
+ }
64
+ let pool = resourcePoolStore.get(key) || [];
65
+ if (pool.length > 0) {
66
+ return res.end(JSON.stringify({ value: pool.shift() }));
67
+ }
68
+ const timeout = Math.min(parseInt(req.query.timeout) || DEFAULT_TIMEOUT, MAX_TIMEOUT);
69
+ try {
70
+ const result = await new Promise((resolve2, reject2) => {
71
+ setTimeout(function secondAttempt() {
72
+ pool = resourcePoolStore.get(key) || [];
73
+ if (pool.length > 0) {
74
+ resolve2({ value: pool.shift() });
75
+ }
76
+ reject2(`'${key}' resource pool is empty. Set values to it first using 'setResourcePool' or 'addValueToPool'`);
77
+ }, timeout);
78
+ });
79
+ res.end(JSON.stringify(result));
80
+ } catch (err) {
81
+ return next(err);
82
+ }
83
+ }).post("/pool/:key", (req, res, next) => {
84
+ const key = req.params.key;
85
+ const value = req.body.value;
86
+ const pool = resourcePoolStore.get(key);
87
+ if (!pool) {
88
+ return next(`'${key}' resource pool does not exist. Set it first using 'setResourcePool'`);
89
+ }
90
+ pool.push(value);
91
+ return res.end();
92
+ });
93
+ app.listen(0, (err) => {
94
+ if (err) {
95
+ return reject(err);
96
+ }
97
+ resolve({ app, port: app.server.address().port });
98
+ });
99
+ });
100
+ }
101
+ });
102
+
103
+ // src/launcher.ts
104
+ import logger from "@wdio/logger";
105
+
106
+ // src/client.ts
107
+ var baseUrlResolve;
108
+ var baseUrlPromise = new Promise((resolve) => {
109
+ baseUrlResolve = resolve;
110
+ });
111
+ var headers = {
112
+ "Content-Type": "application/json"
113
+ };
114
+ var isBaseUrlReady = false;
115
+ var setPort = (port) => {
116
+ baseUrlResolve(`http://localhost:${port}`);
117
+ isBaseUrlReady = true;
118
+ };
119
+ var getValue = async (key) => {
120
+ if (!isBaseUrlReady) {
121
+ throw new Error("Attempting to use `getValue` before the server has been initialized.");
122
+ }
123
+ const baseUrl = await baseUrlPromise;
124
+ const res = await fetch(`${baseUrl}/${key}`, {
125
+ method: "get",
126
+ headers
127
+ }).catch(errHandler);
128
+ const responseBody = await res.json();
129
+ return responseBody.value ?? void 0;
130
+ };
131
+ var setValue = async (key, value) => {
132
+ const setPromise = baseUrlPromise.then((baseUrl) => {
133
+ return fetch(`${baseUrl}/`, {
134
+ method: "post",
135
+ body: JSON.stringify({ key, value }),
136
+ headers
137
+ }).catch(errHandler);
138
+ });
139
+ return isBaseUrlReady ? (await setPromise).status : Promise.resolve();
140
+ };
141
+ var setResourcePool = async (key, value) => {
142
+ const setPromise = baseUrlPromise.then((baseUrl) => {
143
+ return fetch(`${baseUrl}/pool`, {
144
+ method: "post",
145
+ body: JSON.stringify({ key, value }),
146
+ headers
147
+ }).catch(errHandler);
148
+ });
149
+ return isBaseUrlReady ? (await setPromise).status : Promise.resolve();
150
+ };
151
+ var getValueFromPool = async (key, options) => {
152
+ if (!isBaseUrlReady) {
153
+ throw new Error("Attempting to use `getValueFromPool` before the server has been initialized.");
154
+ }
155
+ const baseUrl = await baseUrlPromise;
156
+ const res = await fetch(`${baseUrl}/pool/${key}${typeof options?.timeout === "number" ? `?timeout=${options.timeout}` : ""}`, {
157
+ method: "get",
158
+ headers
159
+ }).catch(errHandler);
160
+ const responseBody = await res.json();
161
+ return responseBody.value ?? void 0;
162
+ };
163
+ var addValueToPool = async (key, value) => {
164
+ if (!isBaseUrlReady) {
165
+ throw new Error("Attempting to use `addValueToPool` before the server has been initialized.");
166
+ }
167
+ const baseUrl = await baseUrlPromise;
168
+ const res = await fetch(`${baseUrl}/pool/${key}`, {
169
+ method: "post",
170
+ body: JSON.stringify({ value }),
171
+ headers
172
+ }).catch(errHandler);
173
+ return res.status;
174
+ };
175
+ var errHandler = async (err) => {
176
+ throw new Error(`${err.message || "Shared store server threw an error"}`);
177
+ };
178
+
179
+ // src/constants.ts
180
+ var CUSTOM_CAP = "wdio:sharedStoreServicePort";
181
+
182
+ // src/launcher.ts
183
+ var log = logger("@wdio/shared-store-service");
184
+ var server;
185
+ var SharedStoreLauncher = class {
186
+ _app;
187
+ async onPrepare(_, capabilities) {
188
+ server = await Promise.resolve().then(() => (init_server(), server_exports));
189
+ const { port, app } = await server.startServer();
190
+ this._app = app;
191
+ setPort(port);
192
+ const capsList = Array.isArray(capabilities) ? capabilities : Object.values(capabilities).map((multiremoteOption) => multiremoteOption.capabilities);
193
+ const caps = capsList.flatMap((c) => {
194
+ const multiremote = c;
195
+ if (!multiremote.browserName && multiremote[Object.keys(multiremote)[0]].capabilities) {
196
+ return Object.values(multiremote).map(
197
+ (options) => options.capabilities?.alwaysMatch || options.capabilities
198
+ );
199
+ }
200
+ const w3cCaps = c;
201
+ return w3cCaps.alwaysMatch || c;
202
+ });
203
+ caps.forEach((c) => {
204
+ c[CUSTOM_CAP] = port;
205
+ });
206
+ log.info(`Started shared server on port ${port}`);
207
+ }
208
+ async onComplete() {
209
+ return new Promise((resolve) => {
210
+ if (this._app && this._app.server.close) {
211
+ this._app.server.close(() => resolve());
212
+ }
213
+ return resolve();
214
+ });
215
+ }
216
+ };
217
+
218
+ // src/service.ts
219
+ var SharedStoreService = class {
220
+ _browser;
221
+ constructor(_, caps) {
222
+ const port = caps[CUSTOM_CAP] || caps.alwaysMatch?.[CUSTOM_CAP] || (Object.values(caps)[0]?.capabilities)[CUSTOM_CAP];
223
+ if (!port) {
224
+ throw new Error("SharedStoreService: port not found in capabilities");
225
+ }
226
+ setPort(port);
227
+ }
228
+ before(caps, specs, _browser) {
229
+ this._browser = _browser;
230
+ const sharedStore = Object.create({}, {
231
+ get: {
232
+ value: (key) => getValue(key)
233
+ },
234
+ set: {
235
+ value: (key, value) => setValue(key, value)
236
+ },
237
+ setResourcePool: {
238
+ value: (key, value) => setResourcePool(key, value)
239
+ },
240
+ getValueFromPool: {
241
+ value: (key, options) => getValueFromPool(key, options)
242
+ },
243
+ addValueToPool: {
244
+ value: (key, value) => addValueToPool(key, value)
245
+ }
246
+ });
247
+ this._browser.sharedStore = sharedStore;
248
+ const browser = this._browser;
249
+ if (!this._browser.capabilities && browser.instances) {
250
+ browser.instances.forEach((browserName) => {
251
+ browser.getInstance(browserName).sharedStore = sharedStore;
252
+ });
253
+ }
254
+ }
255
+ };
256
+
257
+ // src/index.ts
258
+ var src_default = SharedStoreService;
259
+ var launcher = SharedStoreLauncher;
260
+ export {
261
+ addValueToPool,
262
+ src_default as default,
263
+ getValue,
264
+ getValueFromPool,
265
+ launcher,
266
+ setResourcePool,
267
+ setValue
268
+ };
@@ -1,7 +1,7 @@
1
1
  import type { Capabilities, Services } from '@wdio/types';
2
2
  export default class SharedStoreLauncher implements Services.HookFunctions {
3
3
  private _app?;
4
- onPrepare(_: never, capabilities: Capabilities.RemoteCapabilities): Promise<void>;
4
+ onPrepare(_: never, capabilities: Capabilities.TestrunnerCapabilities): Promise<void>;
5
5
  onComplete(): Promise<void>;
6
6
  }
7
7
  //# sourceMappingURL=launcher.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"launcher.d.ts","sourceRoot":"","sources":["../src/launcher.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAUzD,MAAM,CAAC,OAAO,OAAO,mBAAoB,YAAW,QAAQ,CAAC,aAAa;IACtE,OAAO,CAAC,IAAI,CAAC,CAAe;IAEtB,SAAS,CAAE,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,YAAY,CAAC,kBAAkB;IA6BlE,UAAU;CAQnB"}
1
+ {"version":3,"file":"launcher.d.ts","sourceRoot":"","sources":["../src/launcher.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAUzD,MAAM,CAAC,OAAO,OAAO,mBAAoB,YAAW,QAAQ,CAAC,aAAa;IACtE,OAAO,CAAC,IAAI,CAAC,CAAe;IAEtB,SAAS,CAAE,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,YAAY,CAAC,sBAAsB;IA6BtE,UAAU;CAQnB"}
@@ -1,7 +1,7 @@
1
1
  import type { Services, Capabilities } from '@wdio/types';
2
2
  export default class SharedStoreService implements Services.ServiceInstance {
3
3
  private _browser?;
4
- constructor(_: never, caps: Capabilities.RemoteCapability);
4
+ constructor(_: never, caps: Capabilities.ResolvedTestrunnerCapabilities);
5
5
  before(caps: never, specs: never, _browser: WebdriverIO.Browser | WebdriverIO.MultiRemoteBrowser): void;
6
6
  }
7
7
  //# sourceMappingURL=service.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiC,QAAQ,EAAa,YAAY,EAAE,MAAM,aAAa,CAAA;AAOnG,MAAM,CAAC,OAAO,OAAO,kBAAmB,YAAW,QAAQ,CAAC,eAAe;IACvE,OAAO,CAAC,QAAQ,CAAC,CAAsD;gBAE3D,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,YAAY,CAAC,gBAAgB;IAczD,MAAM,CACF,IAAI,EAAE,KAAK,EACX,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,WAAW,CAAC,OAAO,GAAG,WAAW,CAAC,kBAAkB;CA0CrE"}
1
+ {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiC,QAAQ,EAAa,YAAY,EAAE,MAAM,aAAa,CAAA;AAOnG,MAAM,CAAC,OAAO,OAAO,kBAAmB,YAAW,QAAQ,CAAC,eAAe;IACvE,OAAO,CAAC,QAAQ,CAAC,CAAsD;gBAE3D,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,YAAY,CAAC,8BAA8B;IAcvE,MAAM,CACF,IAAI,EAAE,KAAK,EACX,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,WAAW,CAAC,OAAO,GAAG,WAAW,CAAC,kBAAkB;CA0CrE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wdio/shared-store-service",
3
- "version": "9.0.0-alpha.9+9220932b7",
3
+ "version": "9.0.1",
4
4
  "description": "A WebdriverIO service to exchange data across processes",
5
5
  "author": "Mykola Grybyk <mykola.grybyk@gmail.com>",
6
6
  "homepage": "https://github.com/webdriverio/webdriverio/tree/main/packages/wdio-shared-store-service",
@@ -22,34 +22,31 @@
22
22
  "bugs": {
23
23
  "url": "https://github.com/webdriverio/webdriverio/issues"
24
24
  },
25
- "main": "./build/cjs/index.js",
25
+ "main": "./build/index.cjs",
26
26
  "type": "module",
27
27
  "module": "./build/index.js",
28
28
  "exports": {
29
- ".": [
30
- {
31
- "types": "./build/index.d.ts",
32
- "import": "./build/index.js",
33
- "require": "./build/cjs/index.js"
34
- },
35
- "./build/cjs/index.js"
36
- ],
37
- "./package.json": "./package.json"
29
+ ".": {
30
+ "types": "./build/index.d.ts",
31
+ "import": "./build/index.js",
32
+ "requireSource": "./src/index.cts",
33
+ "require": "./build/index.cjs"
34
+ }
38
35
  },
39
36
  "types": "./build/index.d.ts",
40
37
  "typeScriptVersion": "3.8.3",
41
38
  "dependencies": {
42
39
  "@polka/parse": "^1.0.0-next.0",
43
- "@wdio/logger": "9.0.0-alpha.9+9220932b7",
44
- "@wdio/types": "9.0.0-alpha.9+9220932b7",
40
+ "@wdio/logger": "9.0.0",
41
+ "@wdio/types": "9.0.0",
45
42
  "polka": "^0.5.2",
46
- "webdriverio": "9.0.0-alpha.9+9220932b7"
43
+ "webdriverio": "9.0.1"
47
44
  },
48
45
  "devDependencies": {
49
- "@wdio/globals": "9.0.0-alpha.9+9220932b7"
46
+ "@wdio/globals": "9.0.1"
50
47
  },
51
48
  "publishConfig": {
52
49
  "access": "public"
53
50
  },
54
- "gitHead": "9220932b7048d9b5b6c8397dda54842625be7ef2"
51
+ "gitHead": "2a869e5661b2f867d00997c8a17ed0efee0fd15b"
55
52
  }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cjs/index.ts"],"names":[],"mappings":""}
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const esmModule = import('../index.js');
4
- exports.setValue = async function (key, value) {
5
- const m = await esmModule;
6
- return m.setValue(key, value);
7
- };
8
- exports.getValue = async function (key) {
9
- const m = await esmModule;
10
- return m.getValue(key);
11
- };
12
- exports.setResourcePool = async function (key, value) {
13
- const m = await esmModule;
14
- return m.setResourcePool(key, value);
15
- };
16
- exports.getValueFromPool = async function (key, options) {
17
- const m = await esmModule;
18
- return m.getValueFromPool(key, options);
19
- };
20
- exports.addValueToPool = async function (key, value) {
21
- const m = await esmModule;
22
- return m.addValueToPool(key, value);
23
- };
@@ -1,5 +0,0 @@
1
- {
2
- "name": "@wdio/shared-store-service-cjs",
3
- "type": "commonjs",
4
- "private": true
5
- }
package/build/client.js DELETED
@@ -1,101 +0,0 @@
1
- let baseUrlResolve;
2
- const baseUrlPromise = new Promise((resolve) => {
3
- baseUrlResolve = resolve;
4
- });
5
- const headers = {
6
- 'Content-Type': 'application/json'
7
- };
8
- let isBaseUrlReady = false;
9
- export const setPort = (port) => {
10
- /**
11
- * if someone calls `setValue` in `onPrepare` we don't have a base url
12
- * set as the launcher is called after user hooks. In this case we need
13
- * to wait until it is set and flush all messages.
14
- */
15
- baseUrlResolve(`http://localhost:${port}`);
16
- isBaseUrlReady = true;
17
- };
18
- /**
19
- * make a request to the server to get a value from the store
20
- * @param {string} key
21
- * @returns {*}
22
- */
23
- export const getValue = async (key) => {
24
- if (!isBaseUrlReady) {
25
- throw new Error('Attempting to use `getValue` before the server has been initialized.');
26
- }
27
- const baseUrl = await baseUrlPromise;
28
- const res = await fetch(`${baseUrl}/${key}`, {
29
- method: 'get',
30
- headers
31
- }).catch(errHandler);
32
- const responseBody = await res.json();
33
- return responseBody.value ?? undefined;
34
- };
35
- /**
36
- * make a request to the server to set a value to the store
37
- * @param {string} key
38
- * @param {*} value `store[key]` value (plain object)
39
- */
40
- export const setValue = async (key, value) => {
41
- const setPromise = baseUrlPromise.then((baseUrl) => {
42
- return fetch(`${baseUrl}/`, {
43
- method: 'post',
44
- body: JSON.stringify({ key, value }),
45
- headers
46
- }).catch(errHandler);
47
- });
48
- return isBaseUrlReady ? (await setPromise).status : Promise.resolve();
49
- };
50
- /**
51
- *
52
- * @param {string} key
53
- * @param {*} value
54
- */
55
- export const setResourcePool = async (key, value) => {
56
- const setPromise = baseUrlPromise.then((baseUrl) => {
57
- return fetch(`${baseUrl}/pool`, {
58
- method: 'post',
59
- body: JSON.stringify({ key, value }),
60
- headers
61
- }).catch(errHandler);
62
- });
63
- return isBaseUrlReady ? (await setPromise).status : Promise.resolve();
64
- };
65
- /**
66
- *
67
- * @param {string} key
68
- * @param {*} value
69
- */
70
- export const getValueFromPool = async (key, options) => {
71
- if (!isBaseUrlReady) {
72
- throw new Error('Attempting to use `getValueFromPool` before the server has been initialized.');
73
- }
74
- const baseUrl = await baseUrlPromise;
75
- const res = await fetch(`${baseUrl}/pool/${key}${typeof options?.timeout === 'number' ? `?timeout=${options.timeout}` : ''}`, {
76
- method: 'get',
77
- headers
78
- }).catch(errHandler);
79
- const responseBody = await res.json();
80
- return responseBody.value ?? undefined;
81
- };
82
- /**
83
- *
84
- * @param {string} key
85
- * @param {*} value
86
- */
87
- export const addValueToPool = async (key, value) => {
88
- if (!isBaseUrlReady) {
89
- throw new Error('Attempting to use `addValueToPool` before the server has been initialized.');
90
- }
91
- const baseUrl = await baseUrlPromise;
92
- const res = await fetch(`${baseUrl}/pool/${key}`, {
93
- method: 'post',
94
- body: JSON.stringify({ value }),
95
- headers
96
- }).catch(errHandler);
97
- return res.status;
98
- };
99
- const errHandler = async (err) => {
100
- throw new Error(`${err.message || 'Shared store server threw an error'}`);
101
- };
@@ -1 +0,0 @@
1
- export const CUSTOM_CAP = 'wdio:sharedStoreServicePort';
package/build/launcher.js DELETED
@@ -1,39 +0,0 @@
1
- import logger from '@wdio/logger';
2
- import { setPort } from './client.js';
3
- import { CUSTOM_CAP } from './constants.js';
4
- const log = logger('@wdio/shared-store-service');
5
- let server;
6
- export default class SharedStoreLauncher {
7
- _app;
8
- async onPrepare(_, capabilities) {
9
- /**
10
- * import during runtime to avoid unnecessary dependency loading
11
- */
12
- server = (await import('./server.js'));
13
- const { port, app } = await server.startServer();
14
- this._app = app;
15
- setPort(port);
16
- const capsList = Array.isArray(capabilities)
17
- ? capabilities
18
- : Object.values(capabilities).map((multiremoteOption) => multiremoteOption.capabilities);
19
- const caps = capsList.flatMap((c) => {
20
- const multiremote = c;
21
- if (!multiremote.browserName && multiremote[Object.keys(multiremote)[0]].capabilities) {
22
- return Object.values(multiremote).map((options) => options.capabilities?.alwaysMatch ||
23
- options.capabilities);
24
- }
25
- const w3cCaps = c;
26
- return w3cCaps.alwaysMatch || c;
27
- });
28
- caps.forEach((c) => { c[CUSTOM_CAP] = port; });
29
- log.info(`Started shared server on port ${port}`);
30
- }
31
- async onComplete() {
32
- return new Promise((resolve) => {
33
- if (this._app && this._app.server.close) {
34
- this._app.server.close(() => resolve());
35
- }
36
- return resolve();
37
- });
38
- }
39
- }
package/build/server.js DELETED
@@ -1,102 +0,0 @@
1
- import polka from 'polka';
2
- import { json } from '@polka/parse';
3
- const store = {};
4
- const resourcePoolStore = new Map();
5
- /**
6
- * @private
7
- */
8
- export const __store = store;
9
- export const __resourcePoolStore = resourcePoolStore;
10
- const validateBody = (req, res, next) => {
11
- if (!req.path.endsWith('/get') && !req.path.endsWith('/set')) {
12
- return next();
13
- }
14
- if (req.method === 'POST' && typeof req.body.key !== 'string') {
15
- res.end(JSON.stringify({ error: 'Invalid payload, key is required.' }));
16
- }
17
- next();
18
- };
19
- const MAX_TIMEOUT = 15000;
20
- const DEFAULT_TIMEOUT = 1000;
21
- export const startServer = () => new Promise((resolve, reject) => {
22
- const app = polka()
23
- /**
24
- * middleware
25
- * `json` middleware transforms body to json for every request or returns empty object
26
- */
27
- .use(json(), validateBody)
28
- // routes
29
- .post('/', (req, res) => {
30
- const key = req.body.key;
31
- if (key === '*') {
32
- throw new Error('You can\'t set a value with key "*" as this is a reserved key');
33
- }
34
- store[key] = req.body.value;
35
- return res.end();
36
- })
37
- .get('/:key', (req, res) => {
38
- const key = req.params.key;
39
- const value = key === '*'
40
- ? store
41
- : store[key];
42
- res.end(JSON.stringify({ value }));
43
- })
44
- .post('/pool', (req, res, next) => {
45
- const key = req.body.key;
46
- const value = req.body.value;
47
- if (!Array.isArray(value)) {
48
- return next('Resource pool must be an array of values');
49
- }
50
- resourcePoolStore.set(key, value);
51
- return res.end();
52
- })
53
- .get('/pool/:key', async (req, res, next) => {
54
- const key = req.params.key;
55
- if (!resourcePoolStore.has(key)) {
56
- return next(`'${key}' resource pool does not exist. Set it first using 'setResourcePool'`);
57
- }
58
- let pool = resourcePoolStore.get(key) || [];
59
- if (pool.length > 0) {
60
- return res.end(JSON.stringify({ value: pool.shift() }));
61
- }
62
- const timeout = Math.min(parseInt(req.query.timeout) || DEFAULT_TIMEOUT, MAX_TIMEOUT);
63
- try {
64
- const result = await new Promise((resolve, reject) => {
65
- setTimeout(function secondAttempt() {
66
- pool = resourcePoolStore.get(key) || [];
67
- if (pool.length > 0) {
68
- resolve({ value: pool.shift() });
69
- }
70
- reject(`'${key}' resource pool is empty. Set values to it first using 'setResourcePool' or 'addValueToPool'`);
71
- }, timeout);
72
- });
73
- res.end(JSON.stringify(result));
74
- }
75
- catch (err) {
76
- return next(err);
77
- }
78
- })
79
- .post('/pool/:key', (req, res, next) => {
80
- const key = req.params.key;
81
- const value = req.body.value;
82
- const pool = resourcePoolStore.get(key);
83
- if (!pool) {
84
- return next(`'${key}' resource pool does not exist. Set it first using 'setResourcePool'`);
85
- }
86
- pool.push(value);
87
- return res.end();
88
- });
89
- /**
90
- * run server on a random port, `0` stands for random port
91
- * > If port is omitted or is 0, the operating system will assign
92
- * > an arbitrary unused port, which can be retrieved by using `server.address().port`
93
- * https://nodejs.org/api/net.html#net_server_listen_port_host_backlog_callback
94
- */
95
- app.listen(0, (err) => {
96
- /* istanbul ignore next */
97
- if (err) {
98
- return reject(err);
99
- }
100
- resolve({ app, port: app.server.address().port });
101
- });
102
- });
package/build/service.js DELETED
@@ -1,41 +0,0 @@
1
- import { getValue, setValue, setPort, setResourcePool, getValueFromPool, addValueToPool } from './client.js';
2
- import { CUSTOM_CAP } from './constants.js';
3
- export default class SharedStoreService {
4
- _browser;
5
- constructor(_, caps) {
6
- const port = (caps[CUSTOM_CAP] ||
7
- caps.alwaysMatch?.[CUSTOM_CAP] ||
8
- (Object.values(caps)[0]?.capabilities)[CUSTOM_CAP]);
9
- if (!port) {
10
- throw new Error('SharedStoreService: port not found in capabilities');
11
- }
12
- setPort(port);
13
- }
14
- before(caps, specs, _browser) {
15
- this._browser = _browser;
16
- const sharedStore = Object.create({}, {
17
- get: {
18
- value: (key) => getValue(key)
19
- },
20
- set: {
21
- value: (key, value) => setValue(key, value)
22
- },
23
- setResourcePool: {
24
- value: (key, value) => setResourcePool(key, value)
25
- },
26
- getValueFromPool: {
27
- value: (key, options) => getValueFromPool(key, options)
28
- },
29
- addValueToPool: {
30
- value: (key, value) => addValueToPool(key, value)
31
- }
32
- });
33
- this._browser.sharedStore = sharedStore;
34
- const browser = this._browser;
35
- if (!this._browser.capabilities && browser.instances) {
36
- browser.instances.forEach((browserName) => {
37
- browser.getInstance(browserName).sharedStore = sharedStore;
38
- });
39
- }
40
- }
41
- }
package/build/types.js DELETED
@@ -1 +0,0 @@
1
- export {};
File without changes