@cydran/testsupport 0.5.1 → 0.6.0

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,9 +1,9 @@
1
1
  /*
2
- 0.5.1
2
+ 0.6.0
3
3
  ---
4
- Cydran <http://cydran.io/>
5
- Copyright (c) 2018 The Cydran Team and other contributors <http://cydran.io/>
6
- Released under MIT license <http://cydran.io/license>
4
+ Cydran <https://cydran.io/>
5
+ Copyright (c) 2018-2026 The Cydran Team <https://cydran.io/>
6
+ SPDX-License-Identifier: MIT
7
7
  ---
8
8
  Derivative work based on Lodash 4.17.15 <https://lodash.com/license>
9
9
  Copyright (c) 2019 OpenJS Foundation and other contributors <https://openjsf.org/>
@@ -21,35 +21,75 @@ Derivative work based on UMD <https://github.com/umdjs/umd/blob/master/LICENSE.m
21
21
  Copyright (c) 2014 the UMD contributors <https://github.com/umdjs/umd/>
22
22
 
23
23
  */
24
+ (function (root, factory) {
25
+ var ids = ["@cydran/cydran","@jest/globals","@testing-library/dom","jsdom"];
26
+ var globals = {"@cydran/cydran":"cydran"};
27
+ if (typeof define === "function" && define.amd) {
28
+ define(["exports"].concat(ids), function (exports) {
29
+ var values = Array.prototype.slice.call(arguments, 1);
30
+ factory(exports, function (id) {
31
+ return values[ids.indexOf(id)];
32
+ });
33
+ });
34
+ } else if (typeof exports === "object" && typeof exports.nodeName !== "string") {
35
+ factory(exports, typeof require === "function" ? require : function (id) {
36
+ throw new Error("testsupport: dependency " + id + " cannot be loaded: require is not available");
37
+ });
38
+ } else {
39
+ var target = {};
40
+ factory(target, function (id) {
41
+ var value = Object.prototype.hasOwnProperty.call(globals, id) ? root[globals[id]] : undefined;
42
+ if (value === undefined) {
43
+ throw new Error("testsupport: dependency " + id + " is not available as a global");
44
+ }
45
+ return value;
46
+ });
47
+ root["testsupport"] = target;
48
+ }
49
+ })(typeof self !== "undefined" ? self : this, function (exports, require) {
24
50
  "use strict";
25
- var testsupport = (() => {
26
- var __getOwnPropNames = Object.getOwnPropertyNames;
27
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
28
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
29
- }) : x)(function(x) {
30
- if (typeof require !== "undefined") return require.apply(this, arguments);
31
- throw Error('Dynamic require of "' + x + '" is not supported');
32
- });
33
- var __commonJS = (cb, mod) => function __require2() {
34
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
35
- };
51
+ var module = { exports: {} };
52
+ var __defProp = Object.defineProperty;
53
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
54
+ var __getOwnPropNames = Object.getOwnPropertyNames;
55
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
56
+ var __export = (target, all) => {
57
+ for (var name in all)
58
+ __defProp(target, name, { get: all[name], enumerable: true });
59
+ };
60
+ var __copyProps = (to, from, except, desc) => {
61
+ if (from && typeof from === "object" || typeof from === "function") {
62
+ for (let key of __getOwnPropNames(from))
63
+ if (!__hasOwnProp.call(to, key) && key !== except)
64
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
65
+ }
66
+ return to;
67
+ };
68
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
36
69
 
37
- // dist/src/harness/Harness.js
38
- var require_Harness = __commonJS({
39
- "dist/src/harness/Harness.js"(exports) {
40
- "use strict";
41
- Object.defineProperty(exports, "__esModule", { value: true });
42
- var jsdom_1 = __require("jsdom");
43
- var cydran_1 = __require("@cydran/cydran");
44
- var dom_1 = __require("@testing-library/dom");
45
- var globals_1 = __require("@jest/globals");
46
- var TestComponent = class extends cydran_1.Component {
47
- constructor() {
48
- super("<div></div>");
49
- }
50
- };
51
- var DEFAULT_COMPONENT_SUPPLIER = () => new TestComponent();
52
- var HTML = `<!doctype html>
70
+ // target/js/index.js
71
+ var js_exports = {};
72
+ __export(js_exports, {
73
+ Harness: () => Harness_default,
74
+ isDefined: () => isDefined2,
75
+ merge: () => merge2,
76
+ overlay: () => overlay,
77
+ requireNotNull: () => requireNotNull2
78
+ });
79
+ module.exports = __toCommonJS(js_exports);
80
+
81
+ // target/js/harness/Harness.js
82
+ var import_jsdom = require("jsdom");
83
+ var import_cydran = require("@cydran/cydran");
84
+ var import_dom = require("@testing-library/dom");
85
+ var import_globals = require("@jest/globals");
86
+ var TestComponent = class extends import_cydran.Component {
87
+ constructor() {
88
+ super("<div></div>");
89
+ }
90
+ };
91
+ var DEFAULT_COMPONENT_SUPPLIER = () => new TestComponent();
92
+ var HTML = `<!doctype html>
53
93
  <html lang="en">
54
94
  <head>
55
95
  <title>Cydran Test Harness</title>
@@ -58,250 +98,227 @@ var testsupport = (() => {
58
98
  <!-- Stage Content -->
59
99
  </body>
60
100
  </html>`;
61
- var ExpectionActionsImpl = class {
62
- constructor(element) {
63
- this.element = (0, cydran_1.requireNotNull)(element, "element");
64
- }
65
- selectedValues() {
66
- const selected = [];
67
- for (let i = 0; i < this.element["selectedOptions"].length; i++) {
68
- const option = this.element["selectedOptions"][i];
69
- selected.push(option.value);
70
- }
71
- return (0, globals_1.expect)(selected);
72
- }
73
- trimmedTextContent() {
74
- return (0, globals_1.expect)(this.element.textContent.trim());
75
- }
76
- textContent() {
77
- return (0, globals_1.expect)(this.element.textContent);
78
- }
79
- };
80
- var OperationsImpl = class {
81
- constructor(element, value, type) {
82
- this.element = (0, cydran_1.requireNotNull)(element, "element");
83
- this.value = (0, cydran_1.requireNotNull)(value, "value");
84
- this.type = (0, cydran_1.requireNotNull)(type, "type");
85
- }
86
- get(options) {
87
- return this.execute("get", options);
88
- }
89
- query(options) {
90
- return this.execute("query", options);
91
- }
92
- find(options) {
93
- return this.execute("find", options);
94
- }
95
- getAll(options) {
96
- return this.execute("getAll", options);
97
- }
98
- queryAll(options) {
99
- return this.execute("queryAll", options);
100
- }
101
- findAll(options) {
102
- return this.execute("findAll", options);
103
- }
104
- expect(options) {
105
- const element = this.get(options);
106
- return new ExpectionActionsImpl(element);
107
- }
108
- appendText(text, options) {
109
- const element = this.get(options);
110
- element.value = element.value + text;
111
- dom_1.fireEvent.input(element);
112
- }
113
- replaceText(text, options) {
114
- const element = this.get(options);
115
- element.value = text;
116
- dom_1.fireEvent.input(element);
117
- }
118
- selectIndex(index, options) {
119
- const element = this.get(options);
120
- element.selectedIndex = index;
121
- dom_1.fireEvent.change(element);
122
- }
123
- selectIndexes(indexes, options) {
124
- const element = this.get(options);
125
- for (let i = 0; i < element.options.length; i++) {
126
- const option = element.options[i];
127
- option.selected = false;
128
- }
129
- for (let i = 0; i < indexes.length; i++) {
130
- const index = indexes[i];
131
- const option = element.options[index];
132
- option.selected = true;
133
- }
134
- dom_1.fireEvent.change(element);
135
- }
136
- setCheckedState(value, options) {
137
- const element = this.get(options);
138
- element.checked = value;
139
- dom_1.fireEvent.input(element);
140
- }
141
- execute(name, options) {
142
- const methodName = name + "By" + this.type;
143
- return dom_1.queries[methodName](this.element, this.value, options);
144
- }
145
- };
146
- var Harness = class {
147
- constructor(rootSupplier = DEFAULT_COMPONENT_SUPPLIER, properties) {
148
- this.rootSupplier = (0, cydran_1.requireNotNull)(rootSupplier, "rootSupplier");
149
- this.actualProperties = (0, cydran_1.isDefined)(properties) ? properties : {};
150
- this.reset();
151
- }
152
- reset() {
153
- this.stop();
154
- this.window = new jsdom_1.JSDOM(HTML).window;
155
- this.document = this.window.document;
156
- const defaultProperties = {
157
- [cydran_1.PropertyKeys.CYDRAN_STARTUP_SYNCHRONOUS]: true,
158
- [cydran_1.PropertyKeys.CYDRAN_LOG_LEVEL]: "WARN",
159
- [cydran_1.PropertyKeys.CYDRAN_OVERRIDE_WINDOW]: this.window
160
- };
161
- this.initialProperties = (0, cydran_1.merge)([defaultProperties, this.actualProperties]);
162
- this.stage = (0, cydran_1.create)("body", this.initialProperties);
163
- this.stage.addInitializer({}, (stage) => {
164
- this.root = this.rootSupplier();
165
- stage.setComponent(this.root);
166
- });
167
- }
168
- start() {
169
- this.stage.start();
170
- return this;
171
- }
172
- stop() {
173
- if ((0, cydran_1.isDefined)(this.stage) && this.stage.isStarted()) {
174
- this.stage.$release();
175
- }
176
- return this;
177
- }
178
- getComponent() {
179
- return this.root;
180
- }
181
- getWindow() {
182
- return this.window;
183
- }
184
- getDocument() {
185
- return this.document;
186
- }
187
- getContext() {
188
- return this.stage.getContext();
189
- }
190
- getStage() {
191
- return this.stage;
192
- }
193
- registerConstant(id, instance) {
194
- this.stage.getContext().registerConstant(id, instance);
195
- }
196
- registerPrototype(id, classInstance, resolvers) {
197
- this.stage.getContext().registerPrototype(id, classInstance, resolvers);
198
- }
199
- registerSingleton(id, classInstance, resolvers) {
200
- this.stage.getContext().registerSingleton(id, classInstance, resolvers);
201
- }
202
- registerConstantGlobally(id, instance) {
203
- this.stage.getContext()["obscuredParent"].registerConstant(id, instance);
204
- }
205
- registerPrototypeGlobally(id, classInstance, resolvers) {
206
- this.stage.getContext()["obscuredParent"].registerPrototype(id, classInstance, resolvers);
207
- }
208
- registerSingletonGlobally(id, classInstance, resolvers) {
209
- this.stage.getContext()["obscuredParent"].registerSingleton(id, classInstance, resolvers);
210
- }
211
- forRole(value) {
212
- return new OperationsImpl(this.document.documentElement, value, "Role");
213
- }
214
- forLabelText(value) {
215
- return new OperationsImpl(this.document.documentElement, value, "LabelText");
216
- }
217
- forPlaceholderText(value) {
218
- return new OperationsImpl(this.document.documentElement, value, "PlaceholderText");
219
- }
220
- forText(value) {
221
- return new OperationsImpl(this.document.documentElement, value, "Text");
222
- }
223
- forDisplayValue(value) {
224
- return new OperationsImpl(this.document.documentElement, value, "DisplayValue");
225
- }
226
- forAltText(value) {
227
- return new OperationsImpl(this.document.documentElement, value, "AltText");
228
- }
229
- forTitle(value) {
230
- return new OperationsImpl(this.document.documentElement, value, "Title");
231
- }
232
- forTestId(value) {
233
- return new OperationsImpl(this.document.documentElement, value, "TestId");
234
- }
235
- expectBody() {
236
- return (0, globals_1.expect)(this.document.body.innerHTML);
237
- }
238
- };
239
- exports.default = Harness;
101
+ var ExpectionActionsImpl = class {
102
+ constructor(element) {
103
+ this.element = (0, import_cydran.requireNotNull)(element, "element");
104
+ }
105
+ selectedValues() {
106
+ const selected = [];
107
+ for (let i = 0; i < this.element["selectedOptions"].length; i++) {
108
+ const option = this.element["selectedOptions"][i];
109
+ selected.push(option.value);
110
+ }
111
+ return (0, import_globals.expect)(selected);
112
+ }
113
+ trimmedTextContent() {
114
+ return (0, import_globals.expect)(this.element.textContent.trim());
115
+ }
116
+ textContent() {
117
+ return (0, import_globals.expect)(this.element.textContent);
118
+ }
119
+ };
120
+ var OperationsImpl = class {
121
+ constructor(element, value, type) {
122
+ this.element = (0, import_cydran.requireNotNull)(element, "element");
123
+ this.value = (0, import_cydran.requireNotNull)(value, "value");
124
+ this.type = (0, import_cydran.requireNotNull)(type, "type");
125
+ }
126
+ get(options) {
127
+ return this.execute("get", options);
128
+ }
129
+ query(options) {
130
+ return this.execute("query", options);
131
+ }
132
+ find(options) {
133
+ return this.execute("find", options);
134
+ }
135
+ getAll(options) {
136
+ return this.execute("getAll", options);
137
+ }
138
+ queryAll(options) {
139
+ return this.execute("queryAll", options);
140
+ }
141
+ findAll(options) {
142
+ return this.execute("findAll", options);
143
+ }
144
+ expect(options) {
145
+ const element = this.get(options);
146
+ return new ExpectionActionsImpl(element);
147
+ }
148
+ appendText(text, options) {
149
+ const element = this.get(options);
150
+ element.value = element.value + text;
151
+ import_dom.fireEvent.input(element);
152
+ }
153
+ replaceText(text, options) {
154
+ const element = this.get(options);
155
+ element.value = text;
156
+ import_dom.fireEvent.input(element);
157
+ }
158
+ selectIndex(index, options) {
159
+ const element = this.get(options);
160
+ element.selectedIndex = index;
161
+ import_dom.fireEvent.change(element);
162
+ }
163
+ selectIndexes(indexes, options) {
164
+ const element = this.get(options);
165
+ for (let i = 0; i < element.options.length; i++) {
166
+ const option = element.options[i];
167
+ option.selected = false;
168
+ }
169
+ for (let i = 0; i < indexes.length; i++) {
170
+ const index = indexes[i];
171
+ const option = element.options[index];
172
+ option.selected = true;
173
+ }
174
+ import_dom.fireEvent.change(element);
175
+ }
176
+ setCheckedState(value, options) {
177
+ const element = this.get(options);
178
+ element.checked = value;
179
+ import_dom.fireEvent.input(element);
180
+ }
181
+ execute(name, options) {
182
+ const methodName = name + "By" + this.type;
183
+ return import_dom.queries[methodName](this.element, this.value, options);
184
+ }
185
+ };
186
+ var Harness = class {
187
+ constructor(rootSupplier = DEFAULT_COMPONENT_SUPPLIER, properties) {
188
+ this.rootSupplier = (0, import_cydran.requireNotNull)(rootSupplier, "rootSupplier");
189
+ this.actualProperties = (0, import_cydran.isDefined)(properties) ? properties : {};
190
+ this.reset();
191
+ }
192
+ reset() {
193
+ this.stop();
194
+ this.window = new import_jsdom.JSDOM(HTML).window;
195
+ this.document = this.window.document;
196
+ const defaultProperties = {
197
+ [import_cydran.PropertyKeys.CYDRAN_STARTUP_SYNCHRONOUS]: true,
198
+ [import_cydran.PropertyKeys.CYDRAN_LOG_LEVEL]: "WARN",
199
+ [import_cydran.PropertyKeys.CYDRAN_OVERRIDE_WINDOW]: this.window
200
+ };
201
+ this.initialProperties = (0, import_cydran.merge)([defaultProperties, this.actualProperties]);
202
+ this.stage = (0, import_cydran.create)("body", this.initialProperties);
203
+ this.stage.addInitializer({}, (stage) => {
204
+ this.root = this.rootSupplier();
205
+ stage.setComponent(this.root);
206
+ });
207
+ }
208
+ start() {
209
+ this.stage.start();
210
+ return this;
211
+ }
212
+ stop() {
213
+ if ((0, import_cydran.isDefined)(this.stage) && this.stage.isStarted()) {
214
+ this.stage.$release();
240
215
  }
241
- });
216
+ return this;
217
+ }
218
+ getComponent() {
219
+ return this.root;
220
+ }
221
+ getWindow() {
222
+ return this.window;
223
+ }
224
+ getDocument() {
225
+ return this.document;
226
+ }
227
+ getContext() {
228
+ return this.stage.getContext();
229
+ }
230
+ getStage() {
231
+ return this.stage;
232
+ }
233
+ registerConstant(id, instance) {
234
+ this.stage.getContext().registerConstant(id, instance);
235
+ }
236
+ registerPrototype(id, classInstance, resolvers) {
237
+ this.stage.getContext().registerPrototype(id, classInstance, resolvers);
238
+ }
239
+ registerSingleton(id, classInstance, resolvers) {
240
+ this.stage.getContext().registerSingleton(id, classInstance, resolvers);
241
+ }
242
+ registerConstantGlobally(id, instance) {
243
+ this.stage.getContext()["obscuredParent"].registerConstant(id, instance);
244
+ }
245
+ registerPrototypeGlobally(id, classInstance, resolvers) {
246
+ this.stage.getContext()["obscuredParent"].registerPrototype(id, classInstance, resolvers);
247
+ }
248
+ registerSingletonGlobally(id, classInstance, resolvers) {
249
+ this.stage.getContext()["obscuredParent"].registerSingleton(id, classInstance, resolvers);
250
+ }
251
+ forRole(value) {
252
+ return new OperationsImpl(this.document.documentElement, value, "Role");
253
+ }
254
+ forLabelText(value) {
255
+ return new OperationsImpl(this.document.documentElement, value, "LabelText");
256
+ }
257
+ forPlaceholderText(value) {
258
+ return new OperationsImpl(this.document.documentElement, value, "PlaceholderText");
259
+ }
260
+ forText(value) {
261
+ return new OperationsImpl(this.document.documentElement, value, "Text");
262
+ }
263
+ forDisplayValue(value) {
264
+ return new OperationsImpl(this.document.documentElement, value, "DisplayValue");
265
+ }
266
+ forAltText(value) {
267
+ return new OperationsImpl(this.document.documentElement, value, "AltText");
268
+ }
269
+ forTitle(value) {
270
+ return new OperationsImpl(this.document.documentElement, value, "Title");
271
+ }
272
+ forTestId(value) {
273
+ return new OperationsImpl(this.document.documentElement, value, "TestId");
274
+ }
275
+ expectBody() {
276
+ return (0, import_globals.expect)(this.document.body.innerHTML);
277
+ }
278
+ };
279
+ var Harness_default = Harness;
242
280
 
243
- // dist/src/index.js
244
- var require_src = __commonJS({
245
- "dist/src/index.js"(exports) {
246
- var __importDefault = exports && exports.__importDefault || function(mod) {
247
- return mod && mod.__esModule ? mod : { "default": mod };
248
- };
249
- Object.defineProperty(exports, "__esModule", { value: true });
250
- exports.Harness = void 0;
251
- exports.overlay = overlay;
252
- exports.merge = merge;
253
- exports.requireNotNull = requireNotNull;
254
- exports.isDefined = isDefined;
255
- var Harness_1 = __importDefault(require_Harness());
256
- exports.Harness = Harness_1.default;
257
- function isDefined(value) {
258
- return value !== null && value !== void 0;
259
- }
260
- function requireNotNull(value, name) {
261
- if (value === null || value === void 0) {
262
- throw new Error(`${name} shall not be null`);
263
- }
264
- return value;
265
- }
266
- function merge(sources) {
267
- requireNotNull(sources, "sources");
268
- return overlay({}, sources);
269
- }
270
- function overlay(destination, sources) {
271
- requireNotNull(destination, "destination");
272
- requireNotNull(sources, "sources");
273
- for (const source of sources) {
274
- if (!isDefined(source)) {
275
- continue;
276
- }
277
- for (const name of Object.keys(source)) {
278
- if (!isDefined(source[name])) {
279
- continue;
280
- }
281
- destination[name] = source[name];
282
- }
283
- }
284
- return destination;
281
+ // target/js/index.js
282
+ function isDefined2(value) {
283
+ return value !== null && value !== void 0;
284
+ }
285
+ function requireNotNull2(value, name) {
286
+ if (value === null || value === void 0) {
287
+ throw new Error(`${name} shall not be null`);
288
+ }
289
+ return value;
290
+ }
291
+ function merge2(sources) {
292
+ requireNotNull2(sources, "sources");
293
+ return overlay({}, sources);
294
+ }
295
+ function overlay(destination, sources) {
296
+ requireNotNull2(destination, "destination");
297
+ requireNotNull2(sources, "sources");
298
+ for (const source of sources) {
299
+ if (!isDefined2(source)) {
300
+ continue;
301
+ }
302
+ for (const name of Object.keys(source)) {
303
+ if (!isDefined2(source[name])) {
304
+ continue;
285
305
  }
306
+ destination[name] = source[name];
286
307
  }
287
- });
288
- return require_src();
289
- })();
290
- ((root, factory, cydranObject) => {
291
- if (typeof define === 'function' && define.amd) {
292
- // AMD. Register as an anonymous module.
293
- define(['exports'], function(exports) {
294
- factory((root.commonJsStrictGlobal = exports), cydranObject);
295
- });
296
- } else if (typeof exports === 'object' && typeof exports.nodeName !== 'string') {
297
- // CommonJS
298
- factory(exports, cydranObject);
299
- } else {
300
- // Browser globals
301
- factory((root.commonJsStrictGlobal = {}), cydranObject);
302
- }
303
- })(typeof self !== 'undefined' ? self : this, function(exports, c) {
304
- c.overlay(exports, [c]);
305
- }, testsupport);
306
-
308
+ }
309
+ return destination;
310
+ }
311
+ // Annotate the CommonJS export names for ESM import in node:
312
+ 0 && (module.exports = {
313
+ Harness,
314
+ isDefined,
315
+ merge,
316
+ overlay,
317
+ requireNotNull
318
+ });
319
+ var source = module.exports;
320
+ Object.getOwnPropertyNames(source).forEach(function (key) {
321
+ Object.defineProperty(exports, key, Object.getOwnPropertyDescriptor(source, key));
322
+ });
323
+ });
307
324
  //# sourceMappingURL=testsupport.js.map