@helvetia-design/playwright 0.0.0-stage → 0.0.3
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 +210 -0
- package/dist/src/index.js +8 -0
- package/dist/src/lib/components/accordion.po.js +74 -0
- package/dist/src/lib/components/app-footer.po.js +132 -0
- package/dist/src/lib/components/app-navbar.po.js +106 -0
- package/dist/src/lib/components/badge.po.js +32 -0
- package/dist/src/lib/components/brand-icon.po.js +13 -0
- package/dist/src/lib/components/button.po.js +86 -0
- package/dist/src/lib/components/card.po.js +148 -0
- package/dist/src/lib/components/carousel.po.js +92 -0
- package/dist/src/lib/components/checkbox.po.js +107 -0
- package/dist/src/lib/components/close.po.js +31 -0
- package/dist/src/lib/components/content.po.js +32 -0
- package/dist/src/lib/components/counter.po.js +121 -0
- package/dist/src/lib/components/data-item.po.js +235 -0
- package/dist/src/lib/components/data.po.js +110 -0
- package/dist/src/lib/components/datepicker.po.js +260 -0
- package/dist/src/lib/components/divider.po.js +10 -0
- package/dist/src/lib/components/drawer.po.js +55 -0
- package/dist/src/lib/components/file-upload.po.js +200 -0
- package/dist/src/lib/components/heading.po.js +32 -0
- package/dist/src/lib/components/hint.po.js +71 -0
- package/dist/src/lib/components/icon.po.js +13 -0
- package/dist/src/lib/components/index.js +49 -0
- package/dist/src/lib/components/input.po.js +107 -0
- package/dist/src/lib/components/label.po.js +32 -0
- package/dist/src/lib/components/list.po.js +68 -0
- package/dist/src/lib/components/logo.po.js +13 -0
- package/dist/src/lib/components/modal.po.js +97 -0
- package/dist/src/lib/components/notification.po.js +56 -0
- package/dist/src/lib/components/number-input.po.js +107 -0
- package/dist/src/lib/components/page-object.js +47 -0
- package/dist/src/lib/components/pagination.po.js +146 -0
- package/dist/src/lib/components/phone-input.po.js +302 -0
- package/dist/src/lib/components/popup.po.js +55 -0
- package/dist/src/lib/components/radio.po.js +89 -0
- package/dist/src/lib/components/root.po.js +32 -0
- package/dist/src/lib/components/segment.po.js +135 -0
- package/dist/src/lib/components/select.po.js +257 -0
- package/dist/src/lib/components/shape.po.js +10 -0
- package/dist/src/lib/components/sheet.po.js +88 -0
- package/dist/src/lib/components/slider.po.js +101 -0
- package/dist/src/lib/components/snackbar.po.js +115 -0
- package/dist/src/lib/components/spinner.po.js +13 -0
- package/dist/src/lib/components/stack.po.js +32 -0
- package/dist/src/lib/components/steps.po.js +112 -0
- package/dist/src/lib/components/tabs.po.js +110 -0
- package/dist/src/lib/components/tag.po.js +53 -0
- package/dist/src/lib/components/text.po.js +32 -0
- package/dist/src/lib/components/textarea.po.js +89 -0
- package/dist/src/lib/components/toast.po.js +92 -0
- package/dist/src/lib/components/toggle.po.js +107 -0
- package/dist/src/lib/components/tooltip.po.js +32 -0
- package/dist/src/lib/devices.js +6 -0
- package/dist/src/lib/extend.js +375 -0
- package/dist/src/lib/functions/a11y.js +31 -0
- package/dist/src/lib/matchers/index.js +12 -0
- package/dist/src/lib/matchers/to-have-first-received-event-detail.js +44 -0
- package/dist/src/lib/matchers/to-have-nth-received-event-detail.js +53 -0
- package/dist/src/lib/matchers/to-have-received-event-detail.js +44 -0
- package/dist/src/lib/matchers/to-have-received-event-times.js +33 -0
- package/dist/src/lib/matchers/to-have-received-event.js +33 -0
- package/dist/src/lib/page/event-spy.js +198 -0
- package/dist/src/lib/page/utils/goto.js +71 -0
- package/dist/src/lib/page/utils/index.js +6 -0
- package/dist/src/lib/page/utils/locator.js +38 -0
- package/dist/src/lib/page/utils/mount-ssr.js +118 -0
- package/dist/src/lib/page/utils/mount.js +70 -0
- package/dist/src/lib/page/utils/spy-on-event.js +34 -0
- package/dist/src/lib/page/utils/wait-for-changes.js +99 -0
- package/dist/src/lib/screenshot.js +13 -0
- package/dist/src/lib/test-expect.js +1 -0
- package/dist/src/lib/types.js +54 -0
- package/package.json +31 -3
- package/sbom.cdx.json +80470 -0
- package/README.md +0 -3
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { expect } from '@playwright/test';
|
|
2
|
+
import deepEqual from 'fast-deep-equal';
|
|
3
|
+
export function toHaveFirstReceivedEventDetail(eventSpy, eventDetail) {
|
|
4
|
+
if (eventSpy === null || eventSpy === undefined) {
|
|
5
|
+
return {
|
|
6
|
+
message: function message() {
|
|
7
|
+
return "expected spy to have received event, but it was not defined";
|
|
8
|
+
},
|
|
9
|
+
pass: false
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
if (typeof eventSpy.then === 'function') {
|
|
13
|
+
return {
|
|
14
|
+
message: function message() {
|
|
15
|
+
return "expected spy to have received event, but it was not resolved (did you forget an await operator?).";
|
|
16
|
+
},
|
|
17
|
+
pass: false
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
if (eventSpy.eventName === null || eventSpy.eventName === undefined) {
|
|
21
|
+
return {
|
|
22
|
+
message: function message() {
|
|
23
|
+
return "toHaveReceivedEventDetail did not receive an event spy";
|
|
24
|
+
},
|
|
25
|
+
pass: false
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
if (eventSpy.firstEvent === null || eventSpy.firstEvent === undefined) {
|
|
29
|
+
return {
|
|
30
|
+
message: function message() {
|
|
31
|
+
return 'event "' + eventSpy.eventName + '" was not received';
|
|
32
|
+
},
|
|
33
|
+
pass: false
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
var pass = deepEqual(eventSpy.firstEvent.detail, eventDetail);
|
|
37
|
+
expect(eventSpy.lastEvent.detail).toEqual(eventDetail);
|
|
38
|
+
return {
|
|
39
|
+
message: function message() {
|
|
40
|
+
return 'expected event "' + eventSpy.eventName + '" detail to ' + (pass ? 'not ' : '') + "equal";
|
|
41
|
+
},
|
|
42
|
+
pass: pass
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { expect } from '@playwright/test';
|
|
2
|
+
import deepEqual from 'fast-deep-equal';
|
|
3
|
+
export function toHaveNthReceivedEventDetail(eventSpy, index, eventDetail) {
|
|
4
|
+
if (eventSpy === null || eventSpy === undefined) {
|
|
5
|
+
return {
|
|
6
|
+
message: function message() {
|
|
7
|
+
return "expected spy to have received event, but it was not defined";
|
|
8
|
+
},
|
|
9
|
+
pass: false
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
if (typeof eventSpy.then === 'function') {
|
|
13
|
+
return {
|
|
14
|
+
message: function message() {
|
|
15
|
+
return "expected spy to have received event, but it was not resolved (did you forget an await operator?).";
|
|
16
|
+
},
|
|
17
|
+
pass: false
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
if (eventSpy.eventName === null || eventSpy.eventName === undefined) {
|
|
21
|
+
return {
|
|
22
|
+
message: function message() {
|
|
23
|
+
return "toHaveReceivedEventDetail did not receive an event spy";
|
|
24
|
+
},
|
|
25
|
+
pass: false
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
if (eventSpy.firstEvent === null || eventSpy.firstEvent === undefined) {
|
|
29
|
+
return {
|
|
30
|
+
message: function message() {
|
|
31
|
+
return 'event "' + eventSpy.eventName + '" was not received';
|
|
32
|
+
},
|
|
33
|
+
pass: false
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
var event = eventSpy.events[index];
|
|
37
|
+
if (event === null || event === undefined) {
|
|
38
|
+
return {
|
|
39
|
+
message: function message() {
|
|
40
|
+
return "event at index " + index + " was not received";
|
|
41
|
+
},
|
|
42
|
+
pass: false
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
var pass = deepEqual(event.detail, eventDetail);
|
|
46
|
+
expect(event.detail).toEqual(eventDetail);
|
|
47
|
+
return {
|
|
48
|
+
message: function message() {
|
|
49
|
+
return 'expected event "' + eventSpy.eventName + '" detail to ' + (pass ? 'not ' : '') + "equal";
|
|
50
|
+
},
|
|
51
|
+
pass: pass
|
|
52
|
+
};
|
|
53
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { expect } from '@playwright/test';
|
|
2
|
+
import deepEqual from 'fast-deep-equal';
|
|
3
|
+
export function toHaveReceivedEventDetail(eventSpy, eventDetail) {
|
|
4
|
+
if (eventSpy === null || eventSpy === undefined) {
|
|
5
|
+
return {
|
|
6
|
+
message: function message() {
|
|
7
|
+
return "toHaveReceivedEventDetail event spy is null";
|
|
8
|
+
},
|
|
9
|
+
pass: false
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
if (typeof eventSpy.then === 'function') {
|
|
13
|
+
return {
|
|
14
|
+
message: function message() {
|
|
15
|
+
return "expected spy to have received event, but it was not resolved (did you forget an await operator?).";
|
|
16
|
+
},
|
|
17
|
+
pass: false
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
if (!eventSpy.eventName) {
|
|
21
|
+
return {
|
|
22
|
+
message: function message() {
|
|
23
|
+
return "toHaveReceivedEventDetail did not receive an event spy";
|
|
24
|
+
},
|
|
25
|
+
pass: false
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
if (eventSpy.lastEvent === null || eventSpy.lastEvent === undefined) {
|
|
29
|
+
return {
|
|
30
|
+
message: function message() {
|
|
31
|
+
return 'event "' + eventSpy.eventName + '" was not received';
|
|
32
|
+
},
|
|
33
|
+
pass: false
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
var pass = deepEqual(eventSpy.lastEvent.detail, eventDetail);
|
|
37
|
+
expect(eventSpy.lastEvent.detail).toEqual(eventDetail);
|
|
38
|
+
return {
|
|
39
|
+
message: function message() {
|
|
40
|
+
return 'expected event "' + eventSpy.eventName + '" detail to ' + (pass ? 'not ' : '') + "equal";
|
|
41
|
+
},
|
|
42
|
+
pass: pass
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export function toHaveReceivedEventTimes(eventSpy, count) {
|
|
2
|
+
if (!eventSpy) {
|
|
3
|
+
return {
|
|
4
|
+
message: function message() {
|
|
5
|
+
return "toHaveReceivedEventTimes event spy is null";
|
|
6
|
+
},
|
|
7
|
+
pass: false
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
if (typeof eventSpy.then === 'function') {
|
|
11
|
+
return {
|
|
12
|
+
message: function message() {
|
|
13
|
+
return "expected spy to have received event, but it was not resolved (did you forget an await operator?).";
|
|
14
|
+
},
|
|
15
|
+
pass: false
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
if (!eventSpy.eventName) {
|
|
19
|
+
return {
|
|
20
|
+
message: function message() {
|
|
21
|
+
return "toHaveReceivedEventTimes did not receive an event spy";
|
|
22
|
+
},
|
|
23
|
+
pass: false
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
var pass = eventSpy.length === count;
|
|
27
|
+
return {
|
|
28
|
+
message: function message() {
|
|
29
|
+
return 'expected event "' + eventSpy.eventName + '" to have been called ' + count + " times, but it was called " + eventSpy.events.length + " times";
|
|
30
|
+
},
|
|
31
|
+
pass: pass
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export function toHaveReceivedEvent(eventSpy) {
|
|
2
|
+
if (eventSpy === undefined || eventSpy === null) {
|
|
3
|
+
return {
|
|
4
|
+
message: function message() {
|
|
5
|
+
return "expected spy to have received event, but it was not defined";
|
|
6
|
+
},
|
|
7
|
+
pass: false
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
if (typeof eventSpy.then === 'function') {
|
|
11
|
+
return {
|
|
12
|
+
message: function message() {
|
|
13
|
+
return "expected spy to have received event, but it was not resolved (did you forget an await operator?).";
|
|
14
|
+
},
|
|
15
|
+
pass: false
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
var pass = eventSpy.events.length > 0;
|
|
19
|
+
if (pass) {
|
|
20
|
+
return {
|
|
21
|
+
message: function message() {
|
|
22
|
+
return "expected to have called " + eventSpy.eventName + " event";
|
|
23
|
+
},
|
|
24
|
+
pass: true
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
message: function message() {
|
|
29
|
+
return "expected to have not called " + eventSpy.eventName + " event";
|
|
30
|
+
},
|
|
31
|
+
pass: false
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
+
import { _ as _create_class } from "@swc/helpers/_/_create_class";
|
|
3
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
4
|
+
/**
|
|
5
|
+
* The EventSpy class allows developers to listen for a particular event emission and
|
|
6
|
+
* pass/fail the test based on whether or not the event was emitted.
|
|
7
|
+
* Based off https://github.com/ionic-team/stencil/blob/16b8ea4dabb22024872a38bc58ba1dcf1c7cc25b/src/testing/puppeteer/puppeteer-events.ts#L64
|
|
8
|
+
*/ export var EventSpy = /*#__PURE__*/ function() {
|
|
9
|
+
"use strict";
|
|
10
|
+
function EventSpy(eventName) {
|
|
11
|
+
this.eventName = eventName;
|
|
12
|
+
/**
|
|
13
|
+
* Keeping track of a cursor ensures that no two spy.next() calls point to the same event.
|
|
14
|
+
*/ this.cursor = 0;
|
|
15
|
+
this.queuedHandler = [];
|
|
16
|
+
this.events = [];
|
|
17
|
+
}
|
|
18
|
+
var _proto = EventSpy.prototype;
|
|
19
|
+
_proto.next = function next() {
|
|
20
|
+
var _this = this;
|
|
21
|
+
var cursor = this.cursor;
|
|
22
|
+
this.cursor++;
|
|
23
|
+
var next = this.events[cursor];
|
|
24
|
+
if (next !== undefined) {
|
|
25
|
+
return Promise.resolve(next);
|
|
26
|
+
} else {
|
|
27
|
+
/**
|
|
28
|
+
* If the event has not already been emitted, then add it to the queuedHandler.
|
|
29
|
+
* When the event is emitted, the push method is called which results in the Promise below being resolved.
|
|
30
|
+
*/ var resolve = function resolve() {
|
|
31
|
+
return void 0;
|
|
32
|
+
};
|
|
33
|
+
var promise = new Promise(function(r) {
|
|
34
|
+
return resolve = r;
|
|
35
|
+
});
|
|
36
|
+
this.queuedHandler.push(resolve);
|
|
37
|
+
return promise.then(function() {
|
|
38
|
+
return _this.events[cursor];
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
_proto.push = function push(ev) {
|
|
43
|
+
this.events.push(ev);
|
|
44
|
+
var next = this.queuedHandler.shift();
|
|
45
|
+
if (next) {
|
|
46
|
+
next();
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
_create_class(EventSpy, [
|
|
50
|
+
{
|
|
51
|
+
key: "length",
|
|
52
|
+
get: function get() {
|
|
53
|
+
return this.events.length;
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
key: "firstEvent",
|
|
58
|
+
get: function get() {
|
|
59
|
+
var _this_events_;
|
|
60
|
+
return (_this_events_ = this.events[0]) != null ? _this_events_ : null;
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
key: "lastEvent",
|
|
65
|
+
get: function get() {
|
|
66
|
+
var _this_events_;
|
|
67
|
+
return (_this_events_ = this.events[this.events.length - 1]) != null ? _this_events_ : null;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
]);
|
|
71
|
+
return EventSpy;
|
|
72
|
+
}();
|
|
73
|
+
/**
|
|
74
|
+
* For internal use only.
|
|
75
|
+
*
|
|
76
|
+
* Initializes information required to spy on events.
|
|
77
|
+
* The stencilOnEvent function is called in the context of the current page.
|
|
78
|
+
* This lets us respond to an event listener created within the page itself.
|
|
79
|
+
*
|
|
80
|
+
* @param page The Playwright test page object.
|
|
81
|
+
*/ export var initPageEvents = function initPageEvents(page) {
|
|
82
|
+
return _async_to_generator(function() {
|
|
83
|
+
return _ts_generator(this, function(_state) {
|
|
84
|
+
switch(_state.label){
|
|
85
|
+
case 0:
|
|
86
|
+
page._e2eEventsIds = 0;
|
|
87
|
+
page._e2eEvents = new Map();
|
|
88
|
+
return [
|
|
89
|
+
4,
|
|
90
|
+
page.exposeFunction('stencilOnEvent', function(id, ev) {
|
|
91
|
+
var context = page._e2eEvents.get(id);
|
|
92
|
+
if (context) {
|
|
93
|
+
context.callback(ev);
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
];
|
|
97
|
+
case 1:
|
|
98
|
+
_state.sent();
|
|
99
|
+
return [
|
|
100
|
+
2
|
|
101
|
+
];
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
})();
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* For internal use only.
|
|
108
|
+
*
|
|
109
|
+
* Adds a new event listener in the current page context to updates
|
|
110
|
+
* the _e2eEvents map when an event is fired.
|
|
111
|
+
*
|
|
112
|
+
* @param page The Playwright test page object.
|
|
113
|
+
* @param elmHandle A {@link JSHandle} representing the element to listen for events on.
|
|
114
|
+
* @param eventName The event name to listen for.
|
|
115
|
+
* @param callback The callback to execute when the event is fired.
|
|
116
|
+
*/ export var addE2EListener = function addE2EListener(page, elmHandle, eventName, callback) {
|
|
117
|
+
return _async_to_generator(function() {
|
|
118
|
+
var id;
|
|
119
|
+
return _ts_generator(this, function(_state) {
|
|
120
|
+
switch(_state.label){
|
|
121
|
+
case 0:
|
|
122
|
+
id = page._e2eEventsIds++;
|
|
123
|
+
page._e2eEvents.set(id, {
|
|
124
|
+
eventName: eventName,
|
|
125
|
+
callback: callback
|
|
126
|
+
});
|
|
127
|
+
return [
|
|
128
|
+
4,
|
|
129
|
+
elmHandle.evaluate(function(elm, param) {
|
|
130
|
+
var _$eventName = param[0], id = param[1];
|
|
131
|
+
;
|
|
132
|
+
window.stencilSerializeEventTarget = function(target) {
|
|
133
|
+
// BROWSER CONTEXT
|
|
134
|
+
if (!target) {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
if (target === window) {
|
|
138
|
+
return {
|
|
139
|
+
serializedWindow: true
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
if (target === document) {
|
|
143
|
+
return {
|
|
144
|
+
serializedDocument: true
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
if (target.nodeType != null) {
|
|
148
|
+
var serializedElement = {
|
|
149
|
+
serializedElement: true,
|
|
150
|
+
nodeName: target.nodeName,
|
|
151
|
+
nodeValue: target.nodeValue,
|
|
152
|
+
nodeType: target.nodeType,
|
|
153
|
+
tagName: target.tagName,
|
|
154
|
+
className: target.className,
|
|
155
|
+
id: target.id
|
|
156
|
+
};
|
|
157
|
+
return serializedElement;
|
|
158
|
+
}
|
|
159
|
+
return null;
|
|
160
|
+
};
|
|
161
|
+
window.serializeStencilEvent = function(orgEv) {
|
|
162
|
+
var serializedEvent = {
|
|
163
|
+
bubbles: orgEv.bubbles,
|
|
164
|
+
cancelBubble: orgEv.cancelBubble,
|
|
165
|
+
cancelable: orgEv.cancelable,
|
|
166
|
+
composed: orgEv.composed,
|
|
167
|
+
currentTarget: window.stencilSerializeEventTarget(orgEv.currentTarget),
|
|
168
|
+
defaultPrevented: orgEv.defaultPrevented,
|
|
169
|
+
detail: orgEv.detail,
|
|
170
|
+
eventPhase: orgEv.eventPhase,
|
|
171
|
+
isTrusted: orgEv.isTrusted,
|
|
172
|
+
returnValue: orgEv.returnValue,
|
|
173
|
+
srcElement: window.stencilSerializeEventTarget(orgEv.srcElement),
|
|
174
|
+
target: window.stencilSerializeEventTarget(orgEv.target),
|
|
175
|
+
timeStamp: orgEv.timeStamp,
|
|
176
|
+
type: orgEv.type,
|
|
177
|
+
isSerializedEvent: true
|
|
178
|
+
};
|
|
179
|
+
return serializedEvent;
|
|
180
|
+
};
|
|
181
|
+
elm.addEventListener(_$eventName, function(ev) {
|
|
182
|
+
;
|
|
183
|
+
window.stencilOnEvent(id, window.serializeStencilEvent(ev));
|
|
184
|
+
});
|
|
185
|
+
}, [
|
|
186
|
+
eventName,
|
|
187
|
+
id
|
|
188
|
+
])
|
|
189
|
+
];
|
|
190
|
+
case 1:
|
|
191
|
+
_state.sent();
|
|
192
|
+
return [
|
|
193
|
+
2
|
|
194
|
+
];
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
})();
|
|
198
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
+
import { _ as _create_for_of_iterator_helper_loose } from "@swc/helpers/_/_create_for_of_iterator_helper_loose";
|
|
3
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
4
|
+
/**
|
|
5
|
+
* This is an extended version of Playwright's `page.goto` method. In addition to performing
|
|
6
|
+
* the normal `page.goto` work, this code also automatically waits for the Stencil components
|
|
7
|
+
* to be hydrated before proceeding with the test.
|
|
8
|
+
*/ export var gotoPage = function gotoPage(page, url, originalFn, options) {
|
|
9
|
+
return _async_to_generator(function() {
|
|
10
|
+
var response;
|
|
11
|
+
return _ts_generator(this, function(_state) {
|
|
12
|
+
switch(_state.label){
|
|
13
|
+
case 0:
|
|
14
|
+
return [
|
|
15
|
+
4,
|
|
16
|
+
originalFn.call(page, url, options)
|
|
17
|
+
];
|
|
18
|
+
case 1:
|
|
19
|
+
response = _state.sent();
|
|
20
|
+
// Wait for Stencil hydration (all components)
|
|
21
|
+
return [
|
|
22
|
+
4,
|
|
23
|
+
page.evaluate(function() {
|
|
24
|
+
return _async_to_generator(function() {
|
|
25
|
+
var elements, readyPromises, _iterator, _step, el;
|
|
26
|
+
return _ts_generator(this, function(_state) {
|
|
27
|
+
switch(_state.label){
|
|
28
|
+
case 0:
|
|
29
|
+
elements = Array.from(document.querySelectorAll('*'));
|
|
30
|
+
readyPromises = [];
|
|
31
|
+
for(_iterator = _create_for_of_iterator_helper_loose(elements); !(_step = _iterator()).done;){
|
|
32
|
+
el = _step.value;
|
|
33
|
+
if (typeof el.componentOnReady === 'function') {
|
|
34
|
+
readyPromises.push(el.componentOnReady());
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return [
|
|
38
|
+
4,
|
|
39
|
+
Promise.all(readyPromises)
|
|
40
|
+
];
|
|
41
|
+
case 1:
|
|
42
|
+
_state.sent();
|
|
43
|
+
return [
|
|
44
|
+
2
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
})();
|
|
49
|
+
})
|
|
50
|
+
];
|
|
51
|
+
case 2:
|
|
52
|
+
_state.sent();
|
|
53
|
+
// Wait for global app ready flag (if used in your app)
|
|
54
|
+
// await page.waitForFunction(() => (window as any).dsAppReady === true, { timeout: 4750 })
|
|
55
|
+
// Wait for fonts
|
|
56
|
+
return [
|
|
57
|
+
4,
|
|
58
|
+
page.evaluate(function() {
|
|
59
|
+
return document.fonts.ready;
|
|
60
|
+
})
|
|
61
|
+
];
|
|
62
|
+
case 3:
|
|
63
|
+
_state.sent();
|
|
64
|
+
return [
|
|
65
|
+
2,
|
|
66
|
+
response
|
|
67
|
+
];
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
})();
|
|
71
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
|
+
import { addE2EListener, EventSpy } from '../event-spy';
|
|
4
|
+
export var locator = function locator(page, originalFn, selector, options) {
|
|
5
|
+
var locator = originalFn(selector, options);
|
|
6
|
+
locator.spyOnEvent = function(eventName) {
|
|
7
|
+
return _async_to_generator(function() {
|
|
8
|
+
var spy, handle;
|
|
9
|
+
return _ts_generator(this, function(_state) {
|
|
10
|
+
switch(_state.label){
|
|
11
|
+
case 0:
|
|
12
|
+
spy = new EventSpy(eventName);
|
|
13
|
+
return [
|
|
14
|
+
4,
|
|
15
|
+
locator.evaluateHandle(function(node) {
|
|
16
|
+
return node;
|
|
17
|
+
})
|
|
18
|
+
];
|
|
19
|
+
case 1:
|
|
20
|
+
handle = _state.sent();
|
|
21
|
+
return [
|
|
22
|
+
4,
|
|
23
|
+
addE2EListener(page, handle, eventName, function(ev) {
|
|
24
|
+
return spy.push(ev);
|
|
25
|
+
})
|
|
26
|
+
];
|
|
27
|
+
case 2:
|
|
28
|
+
_state.sent();
|
|
29
|
+
return [
|
|
30
|
+
2,
|
|
31
|
+
spy
|
|
32
|
+
];
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
})();
|
|
36
|
+
};
|
|
37
|
+
return locator;
|
|
38
|
+
};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
+
import { _ as _create_for_of_iterator_helper_loose } from "@swc/helpers/_/_create_for_of_iterator_helper_loose";
|
|
3
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
4
|
+
import { template } from './mount';
|
|
5
|
+
import { waitForChanges } from './wait-for-changes';
|
|
6
|
+
/**
|
|
7
|
+
* SSR twin of `mount()`. Renders `content` server-side via the injected `renderToString`
|
|
8
|
+
* (from `@helvetia-design/core/hydrate`), serves the resulting markup to a real page using the same
|
|
9
|
+
* route-interception trick as `mount()`, then lets the client-side bundle hydrate it — so tests can
|
|
10
|
+
* use the same page-object infrastructure as `.component.play.ts` post-hydration.
|
|
11
|
+
*/ export var mountSsr = function mountSsr(page, content, renderToString, testInfo) {
|
|
12
|
+
return _async_to_generator(function() {
|
|
13
|
+
var baseUrl, rendered, result, errors, consoleErrors, leftoverCIds;
|
|
14
|
+
return _ts_generator(this, function(_state) {
|
|
15
|
+
switch(_state.label){
|
|
16
|
+
case 0:
|
|
17
|
+
if (page.isClosed()) {
|
|
18
|
+
throw new Error('mountSsr unavailable: page is already closed');
|
|
19
|
+
}
|
|
20
|
+
baseUrl = testInfo.project.use.baseURL;
|
|
21
|
+
if (!baseUrl) {
|
|
22
|
+
throw new Error('mountSsr unavailable: no dev server base URL provided');
|
|
23
|
+
}
|
|
24
|
+
return [
|
|
25
|
+
4,
|
|
26
|
+
renderToString(template(content), {
|
|
27
|
+
fullDocument: true,
|
|
28
|
+
url: "" + baseUrl + "/",
|
|
29
|
+
serializeShadowRoot: 'declarative-shadow-dom'
|
|
30
|
+
})
|
|
31
|
+
];
|
|
32
|
+
case 1:
|
|
33
|
+
rendered = _state.sent();
|
|
34
|
+
if (!('diagnostics' in rendered)) {
|
|
35
|
+
throw new Error('mountSsr: renderToString unexpectedly returned a stream');
|
|
36
|
+
}
|
|
37
|
+
result = rendered;
|
|
38
|
+
errors = result.diagnostics.filter(function(d) {
|
|
39
|
+
return d.level === 'error';
|
|
40
|
+
});
|
|
41
|
+
if (errors.length) {
|
|
42
|
+
throw new Error("mountSsr: SSR render failed:\n" + errors.map(function(e) {
|
|
43
|
+
return e.messageText;
|
|
44
|
+
}).join('\n\n'));
|
|
45
|
+
}
|
|
46
|
+
// `shadowrootmode` alone isn't a reliable "SSR actually happened" signal — some components
|
|
47
|
+
// (e.g. ds-content, ds-stack, ds-root) render light DOM only. `hydratedCount` reflects every
|
|
48
|
+
// component Stencil actually rendered server-side, regardless of shadow DOM usage.
|
|
49
|
+
if (!result.hydratedCount) {
|
|
50
|
+
throw new Error('mountSsr: hydratedCount is 0 — no component rendered server-side');
|
|
51
|
+
}
|
|
52
|
+
consoleErrors = [];
|
|
53
|
+
page.on('console', function(m) {
|
|
54
|
+
if (m.type() === 'error') consoleErrors.push(m.text());
|
|
55
|
+
});
|
|
56
|
+
page.on('pageerror', function(e) {
|
|
57
|
+
return consoleErrors.push(e.message);
|
|
58
|
+
});
|
|
59
|
+
return [
|
|
60
|
+
4,
|
|
61
|
+
page.route(baseUrl + '**', function(route) {
|
|
62
|
+
var url = route.request().url();
|
|
63
|
+
if (url === "" + baseUrl + "/" || url === "" + baseUrl + "/#" || url === "" + baseUrl + "#" || url === baseUrl) {
|
|
64
|
+
route.fulfill({
|
|
65
|
+
status: 200,
|
|
66
|
+
contentType: 'text/html',
|
|
67
|
+
body: result.html
|
|
68
|
+
});
|
|
69
|
+
} else {
|
|
70
|
+
route.continue();
|
|
71
|
+
}
|
|
72
|
+
})
|
|
73
|
+
];
|
|
74
|
+
case 2:
|
|
75
|
+
_state.sent();
|
|
76
|
+
return [
|
|
77
|
+
4,
|
|
78
|
+
page.goto("" + baseUrl + "#", {
|
|
79
|
+
waitUntil: 'domcontentloaded'
|
|
80
|
+
})
|
|
81
|
+
];
|
|
82
|
+
case 3:
|
|
83
|
+
_state.sent();
|
|
84
|
+
return [
|
|
85
|
+
4,
|
|
86
|
+
waitForChanges(page)
|
|
87
|
+
];
|
|
88
|
+
case 4:
|
|
89
|
+
_state.sent();
|
|
90
|
+
if (consoleErrors.length) {
|
|
91
|
+
throw new Error("mountSsr: console errors during hydration:\n" + consoleErrors.join('\n'));
|
|
92
|
+
}
|
|
93
|
+
return [
|
|
94
|
+
4,
|
|
95
|
+
page.evaluate(function() {
|
|
96
|
+
var countIn = function countIn1(root) {
|
|
97
|
+
var count = root.querySelectorAll('[c-id]').length;
|
|
98
|
+
for(var _iterator = _create_for_of_iterator_helper_loose(root.querySelectorAll('*')), _step; !(_step = _iterator()).done;){
|
|
99
|
+
var el = _step.value;
|
|
100
|
+
if (el.shadowRoot) count += countIn(el.shadowRoot);
|
|
101
|
+
}
|
|
102
|
+
return count;
|
|
103
|
+
};
|
|
104
|
+
return countIn(document);
|
|
105
|
+
})
|
|
106
|
+
];
|
|
107
|
+
case 5:
|
|
108
|
+
leftoverCIds = _state.sent();
|
|
109
|
+
if (leftoverCIds > 0) {
|
|
110
|
+
throw new Error("mountSsr: " + leftoverCIds + " leftover c-id attribute(s) after hydration — the client re-rendered " + 'instead of adopting the server-rendered markup, duplicating content');
|
|
111
|
+
}
|
|
112
|
+
return [
|
|
113
|
+
2
|
|
114
|
+
];
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
})();
|
|
118
|
+
};
|