@badisi/wdio-harness 4.4.0 → 4.4.2
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 -20
- package/index.mjs +28 -28
- 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,4 @@
|
|
|
1
1
|
import { ComponentHarness, ComponentHarnessConstructor, ElementDimensions, EventData, HarnessEnvironment, HarnessQuery, ModifierKeys, TestElement, TestKey, TextOptions } from "@angular/cdk/testing";
|
|
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
2
|
/**
|
|
13
3
|
* A `TestElement` implementation for WebdriverIO.
|
|
14
4
|
*/
|
|
@@ -95,8 +85,6 @@ declare class WebdriverIOTestElement implements TestElement {
|
|
|
95
85
|
/** Writes info to the console outputs. */
|
|
96
86
|
private logAction;
|
|
97
87
|
}
|
|
98
|
-
//#endregion
|
|
99
|
-
//#region src/WebdriverIOHarnessEnvironment.d.ts
|
|
100
88
|
/**
|
|
101
89
|
* A `HarnessEnvironment` implementation for WebdriverIO.
|
|
102
90
|
*/
|
|
@@ -129,15 +117,23 @@ declare class WebdriverIOHarnessEnvironment extends HarnessEnvironment<Webdriver
|
|
|
129
117
|
/** Creates a `HarnessLoader` rooted at the given raw element. */
|
|
130
118
|
protected createEnvironment(element: WebdriverIO.Element): HarnessEnvironment<WebdriverIO.Element>;
|
|
131
119
|
}
|
|
132
|
-
|
|
133
|
-
|
|
120
|
+
/** Module augmentation to expose the host element as a public api */
|
|
121
|
+
declare module "@angular/cdk/testing" {
|
|
122
|
+
interface ComponentHarness {
|
|
123
|
+
element(): WebdriverIO.Element;
|
|
124
|
+
}
|
|
125
|
+
interface TestElement {
|
|
126
|
+
element(): WebdriverIO.Element;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
export declare const patchComponentHarness: () => void;
|
|
134
130
|
/**
|
|
135
131
|
* Searches for all instances of the component corresponding to the given harness type under the
|
|
136
132
|
* `HarnessLoader`'s root element, and returns a list of `ComponentHarness` for each instance.
|
|
137
133
|
* @param query A query for a harness to create
|
|
138
134
|
* @return A list of instances of the given harness type
|
|
139
135
|
*/
|
|
140
|
-
declare const getAllHarnesses: <T extends ComponentHarness>(query: HarnessQuery<T>) => Promise<T[]>;
|
|
136
|
+
export declare const getAllHarnesses: <T extends ComponentHarness>(query: HarnessQuery<T>) => Promise<T[]>;
|
|
141
137
|
/**
|
|
142
138
|
* Searches for an instance of the component corresponding to the given harness type or host element
|
|
143
139
|
* under the `HarnessLoader`'s root element, and returns a `ComponentHarness` for that instance. If
|
|
@@ -148,17 +144,16 @@ declare const getAllHarnesses: <T extends ComponentHarness>(query: HarnessQuery<
|
|
|
148
144
|
* @return An instance of the given harness type
|
|
149
145
|
* @throws If a matching component instance can't be found
|
|
150
146
|
*/
|
|
151
|
-
declare const getHarness: <T extends ComponentHarness>(query: HarnessQuery<T>, element?: WebdriverIO.Element) => Promise<T>;
|
|
147
|
+
export declare const getHarness: <T extends ComponentHarness>(query: HarnessQuery<T>, element?: WebdriverIO.Element) => Promise<T>;
|
|
152
148
|
/**
|
|
153
149
|
* Returns a base harness environment instance.
|
|
154
150
|
* @return An HarnessLoader instance for the current HTML document, rooted at the document's root element
|
|
155
151
|
*/
|
|
156
|
-
declare const createHarnessEnvironment: (rootElement?: WebdriverIO.Element) => Promise<WebdriverIOHarnessEnvironment>;
|
|
152
|
+
export declare const createHarnessEnvironment: (rootElement?: WebdriverIO.Element) => Promise<WebdriverIOHarnessEnvironment>;
|
|
157
153
|
/**
|
|
158
154
|
* Returns a promise that resolves when the application is "stable".
|
|
159
155
|
* The promise might be rejected due to timeouts, or async tasks in the client
|
|
160
156
|
* app that never finish (timers, etc).
|
|
161
157
|
*/
|
|
162
|
-
declare const waitForAngular: () => Promise<void>;
|
|
163
|
-
|
|
164
|
-
export { createHarnessEnvironment, getAllHarnesses, getHarness, waitForAngular };
|
|
158
|
+
export declare const waitForAngular: () => Promise<void>;
|
|
159
|
+
export {};
|
package/index.mjs
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
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
|
+
// src/utils.ts
|
|
5
5
|
const colorize = (msg, color) => process.stdout.isTTY ? `${color}${msg}\x1b[0m` : msg;
|
|
6
6
|
const magenta = (msg) => colorize(msg, "\x1B[35m");
|
|
7
7
|
const green = (msg) => colorize(msg, "\x1B[32m");
|
|
8
|
-
|
|
9
|
-
//#region src/WebdriverIOTestElement.ts
|
|
10
|
-
/** Registers the element logger. */
|
|
11
|
-
const log$1 = logger("wdio-harness");
|
|
8
|
+
// src/WebdriverIOTestElement.ts
|
|
12
9
|
/** Maps the `TestKey` constants to WebdriverIO's `Key` constants. */
|
|
13
|
-
const
|
|
10
|
+
const getKey = (key) => ({
|
|
14
11
|
[TestKey.BACKSPACE]: "Backspace",
|
|
15
12
|
[TestKey.TAB]: "Tab",
|
|
16
13
|
[TestKey.ENTER]: "Enter",
|
|
@@ -42,17 +39,14 @@ const keyMap = {
|
|
|
42
39
|
[TestKey.F12]: "F12",
|
|
43
40
|
[TestKey.META]: "Meta",
|
|
44
41
|
[TestKey.COMMA]: ","
|
|
45
|
-
};
|
|
46
|
-
ComponentHarness.prototype.element = function() {
|
|
47
|
-
return this.locatorFactory.rootElement.element();
|
|
48
|
-
};
|
|
42
|
+
})[key];
|
|
49
43
|
/** Converts a `ModifierKeys` object to a list of WebdriverIO `Key`s. */
|
|
50
44
|
const toWebdriverIOModifierKeys = (modifiers) => {
|
|
51
45
|
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(
|
|
46
|
+
if (modifiers.control) result.push(getKey(TestKey.CONTROL));
|
|
47
|
+
if (modifiers.alt) result.push(getKey(TestKey.ALT));
|
|
48
|
+
if (modifiers.shift) result.push(getKey(TestKey.SHIFT));
|
|
49
|
+
if (modifiers.meta) result.push(getKey(TestKey.META));
|
|
56
50
|
return result;
|
|
57
51
|
};
|
|
58
52
|
/**
|
|
@@ -120,7 +114,7 @@ var WebdriverIOTestElement = class {
|
|
|
120
114
|
}
|
|
121
115
|
const KeyNULL = String.fromCharCode(57344);
|
|
122
116
|
const modifierKeys = toWebdriverIOModifierKeys(modifiers);
|
|
123
|
-
const keys = rest.map((k) => typeof k === "string" ? k.split("") : [
|
|
117
|
+
const keys = rest.map((k) => typeof k === "string" ? k.split("") : [getKey(k)]).reduce((arr, k) => arr.concat(k), []).reduce((arr, k) => {
|
|
124
118
|
if (modifierKeys.length > 0) return arr.concat(...modifierKeys, k, KeyNULL);
|
|
125
119
|
return arr.concat(k);
|
|
126
120
|
}, []);
|
|
@@ -205,9 +199,9 @@ var WebdriverIOTestElement = class {
|
|
|
205
199
|
if (options.length && indexes.size) {
|
|
206
200
|
await this.setInputValue("");
|
|
207
201
|
for (let i = 0; i < options.length; i++) if (indexes.has(i)) {
|
|
208
|
-
await this.keyDown(
|
|
202
|
+
await this.keyDown(getKey(TestKey.CONTROL));
|
|
209
203
|
await options[i].click();
|
|
210
|
-
await this.keyUp(
|
|
204
|
+
await this.keyUp(getKey(TestKey.CONTROL));
|
|
211
205
|
}
|
|
212
206
|
}
|
|
213
207
|
}
|
|
@@ -267,13 +261,10 @@ var WebdriverIOTestElement = class {
|
|
|
267
261
|
}
|
|
268
262
|
/** Writes info to the console outputs. */
|
|
269
263
|
logAction(action, args) {
|
|
270
|
-
|
|
264
|
+
logger("wdio-harness").info(`${magenta(action)} ${green(this.hostElement.selector.toString())} ${args ? args : ""}`);
|
|
271
265
|
}
|
|
272
266
|
};
|
|
273
|
-
|
|
274
|
-
//#region src/WebdriverIOHarnessEnvironment.ts
|
|
275
|
-
/** Registers the environment logger. */
|
|
276
|
-
const log = logger("wdio-harness");
|
|
267
|
+
// src/WebdriverIOHarnessEnvironment.ts
|
|
277
268
|
/**
|
|
278
269
|
* A `HarnessEnvironment` implementation for WebdriverIO.
|
|
279
270
|
*/
|
|
@@ -301,7 +292,7 @@ var WebdriverIOHarnessEnvironment = class WebdriverIOHarnessEnvironment extends
|
|
|
301
292
|
}
|
|
302
293
|
/** Gets a list of all elements matching the given selector under this environment's root element. */
|
|
303
294
|
async getAllRawElements(selector) {
|
|
304
|
-
|
|
295
|
+
logger("wdio-harness").info(`${magenta("GET_ALL_RAW_ELEMENTS")} ${green(selector.toString())}`);
|
|
305
296
|
return [...await this.rawRootElement.$$(selector).getElements()];
|
|
306
297
|
}
|
|
307
298
|
/** Gets the root element for the document. */
|
|
@@ -317,8 +308,17 @@ var WebdriverIOHarnessEnvironment = class WebdriverIOHarnessEnvironment extends
|
|
|
317
308
|
return new WebdriverIOHarnessEnvironment(element, { documentRoot: this.documentRoot });
|
|
318
309
|
}
|
|
319
310
|
};
|
|
320
|
-
|
|
321
|
-
|
|
311
|
+
// src/index.ts
|
|
312
|
+
/** Patches `ComponentHarness.prototype` to expose the host element. */
|
|
313
|
+
let _patched = false;
|
|
314
|
+
const patchComponentHarness = () => {
|
|
315
|
+
if (!_patched) {
|
|
316
|
+
_patched = true;
|
|
317
|
+
ComponentHarness.prototype.element = function() {
|
|
318
|
+
return this.locatorFactory.rootElement.element();
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
322
|
/**
|
|
323
323
|
* Searches for all instances of the component corresponding to the given harness type under the
|
|
324
324
|
* `HarnessLoader`'s root element, and returns a list of `ComponentHarness` for each instance.
|
|
@@ -348,6 +348,7 @@ const getHarness = async (query, element) => {
|
|
|
348
348
|
* @return An HarnessLoader instance for the current HTML document, rooted at the document's root element
|
|
349
349
|
*/
|
|
350
350
|
const createHarnessEnvironment = async (rootElement) => {
|
|
351
|
+
patchComponentHarness();
|
|
351
352
|
return WebdriverIOHarnessEnvironment.loader(rootElement ?? await $("//body").getElement());
|
|
352
353
|
};
|
|
353
354
|
/**
|
|
@@ -369,5 +370,4 @@ const waitForAngular = async () => {
|
|
|
369
370
|
Promise.all(promises).then(done);
|
|
370
371
|
`, []);
|
|
371
372
|
};
|
|
372
|
-
|
|
373
|
-
export { createHarnessEnvironment, getAllHarnesses, getHarness, waitForAngular };
|
|
373
|
+
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.2",
|
|
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
|
},
|