@badisi/wdio-harness 4.4.0 → 4.4.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.
- package/README.md +1 -1
- package/index.d.mts +15 -15
- package/index.mjs +24 -20
- package/package.json +4 -5
package/README.md
CHANGED
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
|
|
29
29
|
> A component harness is a class that lets a test interact with a component via a supported API. Each harness's API interacts with a component the same way a user would. By using the harness API, a test insulates itself against updates to the internals of a component, such as changing its DOM structure. The idea for component harnesses comes from the [PageObject](https://martinfowler.com/bliki/PageObject.html) pattern commonly used for integration testing.
|
|
30
30
|
|
|
31
|
-
[More info](https://material.angular.io/cdk/test-harnesses/overview)
|
|
31
|
+
[More info...](https://material.angular.io/cdk/test-harnesses/overview)
|
|
32
32
|
|
|
33
33
|
<hr/>
|
|
34
34
|
|
package/index.d.mts
CHANGED
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
import { ComponentHarness, ComponentHarnessConstructor, ElementDimensions, EventData, HarnessEnvironment, HarnessQuery, ModifierKeys, TestElement, TestKey, TextOptions } from "@angular/cdk/testing";
|
|
2
2
|
//#region src/WebdriverIOTestElement.d.ts
|
|
3
|
-
/** Module augmentation to expose the host element as a public api */
|
|
4
|
-
declare module "@angular/cdk/testing" {
|
|
5
|
-
interface ComponentHarness {
|
|
6
|
-
element(): WebdriverIO.Element;
|
|
7
|
-
}
|
|
8
|
-
interface TestElement {
|
|
9
|
-
element(): WebdriverIO.Element;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
3
|
/**
|
|
13
4
|
* A `TestElement` implementation for WebdriverIO.
|
|
14
5
|
*/
|
|
@@ -131,13 +122,23 @@ declare class WebdriverIOHarnessEnvironment extends HarnessEnvironment<Webdriver
|
|
|
131
122
|
}
|
|
132
123
|
//#endregion
|
|
133
124
|
//#region src/index.d.ts
|
|
125
|
+
/** Module augmentation to expose the host element as a public api */
|
|
126
|
+
declare module "@angular/cdk/testing" {
|
|
127
|
+
interface ComponentHarness {
|
|
128
|
+
element(): WebdriverIO.Element;
|
|
129
|
+
}
|
|
130
|
+
interface TestElement {
|
|
131
|
+
element(): WebdriverIO.Element;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
export declare const patchComponentHarness: () => void;
|
|
134
135
|
/**
|
|
135
136
|
* Searches for all instances of the component corresponding to the given harness type under the
|
|
136
137
|
* `HarnessLoader`'s root element, and returns a list of `ComponentHarness` for each instance.
|
|
137
138
|
* @param query A query for a harness to create
|
|
138
139
|
* @return A list of instances of the given harness type
|
|
139
140
|
*/
|
|
140
|
-
declare const getAllHarnesses: <T extends ComponentHarness>(query: HarnessQuery<T>) => Promise<T[]>;
|
|
141
|
+
export declare const getAllHarnesses: <T extends ComponentHarness>(query: HarnessQuery<T>) => Promise<T[]>;
|
|
141
142
|
/**
|
|
142
143
|
* Searches for an instance of the component corresponding to the given harness type or host element
|
|
143
144
|
* under the `HarnessLoader`'s root element, and returns a `ComponentHarness` for that instance. If
|
|
@@ -148,17 +149,16 @@ declare const getAllHarnesses: <T extends ComponentHarness>(query: HarnessQuery<
|
|
|
148
149
|
* @return An instance of the given harness type
|
|
149
150
|
* @throws If a matching component instance can't be found
|
|
150
151
|
*/
|
|
151
|
-
declare const getHarness: <T extends ComponentHarness>(query: HarnessQuery<T>, element?: WebdriverIO.Element) => Promise<T>;
|
|
152
|
+
export declare const getHarness: <T extends ComponentHarness>(query: HarnessQuery<T>, element?: WebdriverIO.Element) => Promise<T>;
|
|
152
153
|
/**
|
|
153
154
|
* Returns a base harness environment instance.
|
|
154
155
|
* @return An HarnessLoader instance for the current HTML document, rooted at the document's root element
|
|
155
156
|
*/
|
|
156
|
-
declare const createHarnessEnvironment: (rootElement?: WebdriverIO.Element) => Promise<WebdriverIOHarnessEnvironment>;
|
|
157
|
+
export declare const createHarnessEnvironment: (rootElement?: WebdriverIO.Element) => Promise<WebdriverIOHarnessEnvironment>;
|
|
157
158
|
/**
|
|
158
159
|
* Returns a promise that resolves when the application is "stable".
|
|
159
160
|
* The promise might be rejected due to timeouts, or async tasks in the client
|
|
160
161
|
* app that never finish (timers, etc).
|
|
161
162
|
*/
|
|
162
|
-
declare const waitForAngular: () => Promise<void>;
|
|
163
|
-
//#endregion
|
|
164
|
-
export { createHarnessEnvironment, getAllHarnesses, getHarness, waitForAngular };
|
|
163
|
+
export declare const waitForAngular: () => Promise<void>;
|
|
164
|
+
//#endregion
|
package/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { $, browser } from "@wdio/globals";
|
|
2
1
|
import { ComponentHarness, HarnessEnvironment, TestKey } from "@angular/cdk/testing";
|
|
2
|
+
import { $, browser } from "@wdio/globals";
|
|
3
3
|
import logger from "@wdio/logger";
|
|
4
4
|
//#region src/utils.ts
|
|
5
5
|
const colorize = (msg, color) => process.stdout.isTTY ? `${color}${msg}\x1b[0m` : msg;
|
|
@@ -7,10 +7,8 @@ const magenta = (msg) => colorize(msg, "\x1B[35m");
|
|
|
7
7
|
const green = (msg) => colorize(msg, "\x1B[32m");
|
|
8
8
|
//#endregion
|
|
9
9
|
//#region src/WebdriverIOTestElement.ts
|
|
10
|
-
/** Registers the element logger. */
|
|
11
|
-
const log$1 = logger("wdio-harness");
|
|
12
10
|
/** Maps the `TestKey` constants to WebdriverIO's `Key` constants. */
|
|
13
|
-
const
|
|
11
|
+
const getKey = (key) => ({
|
|
14
12
|
[TestKey.BACKSPACE]: "Backspace",
|
|
15
13
|
[TestKey.TAB]: "Tab",
|
|
16
14
|
[TestKey.ENTER]: "Enter",
|
|
@@ -42,17 +40,14 @@ const keyMap = {
|
|
|
42
40
|
[TestKey.F12]: "F12",
|
|
43
41
|
[TestKey.META]: "Meta",
|
|
44
42
|
[TestKey.COMMA]: ","
|
|
45
|
-
};
|
|
46
|
-
ComponentHarness.prototype.element = function() {
|
|
47
|
-
return this.locatorFactory.rootElement.element();
|
|
48
|
-
};
|
|
43
|
+
})[key];
|
|
49
44
|
/** Converts a `ModifierKeys` object to a list of WebdriverIO `Key`s. */
|
|
50
45
|
const toWebdriverIOModifierKeys = (modifiers) => {
|
|
51
46
|
const result = [];
|
|
52
|
-
if (modifiers.control) result.push(
|
|
53
|
-
if (modifiers.alt) result.push(
|
|
54
|
-
if (modifiers.shift) result.push(
|
|
55
|
-
if (modifiers.meta) result.push(
|
|
47
|
+
if (modifiers.control) result.push(getKey(TestKey.CONTROL));
|
|
48
|
+
if (modifiers.alt) result.push(getKey(TestKey.ALT));
|
|
49
|
+
if (modifiers.shift) result.push(getKey(TestKey.SHIFT));
|
|
50
|
+
if (modifiers.meta) result.push(getKey(TestKey.META));
|
|
56
51
|
return result;
|
|
57
52
|
};
|
|
58
53
|
/**
|
|
@@ -120,7 +115,7 @@ var WebdriverIOTestElement = class {
|
|
|
120
115
|
}
|
|
121
116
|
const KeyNULL = String.fromCharCode(57344);
|
|
122
117
|
const modifierKeys = toWebdriverIOModifierKeys(modifiers);
|
|
123
|
-
const keys = rest.map((k) => typeof k === "string" ? k.split("") : [
|
|
118
|
+
const keys = rest.map((k) => typeof k === "string" ? k.split("") : [getKey(k)]).reduce((arr, k) => arr.concat(k), []).reduce((arr, k) => {
|
|
124
119
|
if (modifierKeys.length > 0) return arr.concat(...modifierKeys, k, KeyNULL);
|
|
125
120
|
return arr.concat(k);
|
|
126
121
|
}, []);
|
|
@@ -205,9 +200,9 @@ var WebdriverIOTestElement = class {
|
|
|
205
200
|
if (options.length && indexes.size) {
|
|
206
201
|
await this.setInputValue("");
|
|
207
202
|
for (let i = 0; i < options.length; i++) if (indexes.has(i)) {
|
|
208
|
-
await this.keyDown(
|
|
203
|
+
await this.keyDown(getKey(TestKey.CONTROL));
|
|
209
204
|
await options[i].click();
|
|
210
|
-
await this.keyUp(
|
|
205
|
+
await this.keyUp(getKey(TestKey.CONTROL));
|
|
211
206
|
}
|
|
212
207
|
}
|
|
213
208
|
}
|
|
@@ -267,13 +262,11 @@ var WebdriverIOTestElement = class {
|
|
|
267
262
|
}
|
|
268
263
|
/** Writes info to the console outputs. */
|
|
269
264
|
logAction(action, args) {
|
|
270
|
-
|
|
265
|
+
logger("wdio-harness").info(`${magenta(action)} ${green(this.hostElement.selector.toString())} ${args ? args : ""}`);
|
|
271
266
|
}
|
|
272
267
|
};
|
|
273
268
|
//#endregion
|
|
274
269
|
//#region src/WebdriverIOHarnessEnvironment.ts
|
|
275
|
-
/** Registers the environment logger. */
|
|
276
|
-
const log = logger("wdio-harness");
|
|
277
270
|
/**
|
|
278
271
|
* A `HarnessEnvironment` implementation for WebdriverIO.
|
|
279
272
|
*/
|
|
@@ -301,7 +294,7 @@ var WebdriverIOHarnessEnvironment = class WebdriverIOHarnessEnvironment extends
|
|
|
301
294
|
}
|
|
302
295
|
/** Gets a list of all elements matching the given selector under this environment's root element. */
|
|
303
296
|
async getAllRawElements(selector) {
|
|
304
|
-
|
|
297
|
+
logger("wdio-harness").info(`${magenta("GET_ALL_RAW_ELEMENTS")} ${green(selector.toString())}`);
|
|
305
298
|
return [...await this.rawRootElement.$$(selector).getElements()];
|
|
306
299
|
}
|
|
307
300
|
/** Gets the root element for the document. */
|
|
@@ -319,6 +312,16 @@ var WebdriverIOHarnessEnvironment = class WebdriverIOHarnessEnvironment extends
|
|
|
319
312
|
};
|
|
320
313
|
//#endregion
|
|
321
314
|
//#region src/index.ts
|
|
315
|
+
/** Patches `ComponentHarness.prototype` to expose the host element. */
|
|
316
|
+
let _patched = false;
|
|
317
|
+
const patchComponentHarness = () => {
|
|
318
|
+
if (!_patched) {
|
|
319
|
+
_patched = true;
|
|
320
|
+
ComponentHarness.prototype.element = function() {
|
|
321
|
+
return this.locatorFactory.rootElement.element();
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
};
|
|
322
325
|
/**
|
|
323
326
|
* Searches for all instances of the component corresponding to the given harness type under the
|
|
324
327
|
* `HarnessLoader`'s root element, and returns a list of `ComponentHarness` for each instance.
|
|
@@ -348,6 +351,7 @@ const getHarness = async (query, element) => {
|
|
|
348
351
|
* @return An HarnessLoader instance for the current HTML document, rooted at the document's root element
|
|
349
352
|
*/
|
|
350
353
|
const createHarnessEnvironment = async (rootElement) => {
|
|
354
|
+
patchComponentHarness();
|
|
351
355
|
return WebdriverIOHarnessEnvironment.loader(rootElement ?? await $("//body").getElement());
|
|
352
356
|
};
|
|
353
357
|
/**
|
|
@@ -370,4 +374,4 @@ const waitForAngular = async () => {
|
|
|
370
374
|
`, []);
|
|
371
375
|
};
|
|
372
376
|
//#endregion
|
|
373
|
-
export { createHarnessEnvironment, getAllHarnesses, getHarness, waitForAngular };
|
|
377
|
+
export { createHarnessEnvironment, getAllHarnesses, getHarness, patchComponentHarness, waitForAngular };
|
package/package.json
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@badisi/wdio-harness",
|
|
3
|
-
"version": "4.4.
|
|
3
|
+
"version": "4.4.1",
|
|
4
4
|
"description": "WebdriverIO support for Angular component test harnesses.",
|
|
5
5
|
"homepage": "https://github.com/Badisi/wdio-harness",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": {
|
|
8
8
|
"name": "Badisi"
|
|
9
9
|
},
|
|
10
|
+
"sideEffects": false,
|
|
10
11
|
"type": "module",
|
|
11
12
|
"main": "./index.mjs",
|
|
12
13
|
"module": "./index.mjs",
|
|
13
14
|
"types": "./index.d.mts",
|
|
14
15
|
"exports": {
|
|
15
16
|
".": {
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
"default": "./index.mjs"
|
|
19
|
-
}
|
|
17
|
+
"types": "./index.d.mts",
|
|
18
|
+
"default": "./index.mjs"
|
|
20
19
|
},
|
|
21
20
|
"./package.json": "./package.json"
|
|
22
21
|
},
|