@testim/testim-cli 3.289.0 → 3.290.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.
- package/cli.js +22390 -122
- package/cli.js.map +1 -0
- package/npm-shrinkwrap.json +1951 -203
- package/package.json +9 -5
- package/OverrideTestDataBuilder.js +0 -117
- package/agent/routers/cliJsCode/index.js +0 -13
- package/agent/routers/cliJsCode/router.js +0 -63
- package/agent/routers/cliJsCode/service.js +0 -705
- package/agent/routers/codim/router.js +0 -69
- package/agent/routers/codim/router.test.js +0 -60
- package/agent/routers/codim/service.js +0 -193
- package/agent/routers/general/index.js +0 -36
- package/agent/routers/hybrid/registerRoutes.js +0 -81
- package/agent/routers/index.js +0 -56
- package/agent/routers/playground/router.js +0 -77
- package/agent/routers/playground/service.js +0 -96
- package/agent/routers/standalone-browser/registerRoutes.js +0 -47
- package/agent/server.js +0 -150
- package/cdpTestRunner.js +0 -86
- package/chromiumInstaller.js +0 -91
- package/cli/isCiRun.js +0 -10
- package/cli/onExit.js +0 -65
- package/cli/writeStackTrace.js +0 -27
- package/cliAgentMode.js +0 -384
- package/codim/codim-cli.js +0 -91
- package/codim/codim-npm-package/index.ts +0 -427
- package/codim/codim-npm-package/package-lock.json +0 -14
- package/codim/codim-npm-package/package.json +0 -14
- package/codim/hybrid-utils.js +0 -28
- package/codim/measure-perf.js +0 -41
- package/codim/template.js/.idea/workspace.xml +0 -57
- package/codim/template.js/.vscode/launch.json +0 -53
- package/codim/template.ts/.idea/workspace.xml +0 -57
- package/codim/template.ts/.vscode/launch.json +0 -55
- package/commons/AbortError.js +0 -12
- package/commons/SeleniumPerfStats.js +0 -58
- package/commons/chrome-launcher.js +0 -15
- package/commons/chromedriverWrapper.js +0 -70
- package/commons/config.js +0 -39
- package/commons/constants.js +0 -67
- package/commons/detectDebugger.js +0 -19
- package/commons/featureAvailabilityService.js +0 -26
- package/commons/featureFlags.js +0 -132
- package/commons/getSessionPlayerRequire.js +0 -28
- package/commons/httpRequest.js +0 -261
- package/commons/httpRequestCounters.js +0 -98
- package/commons/httpRequestCounters.test.js +0 -38
- package/commons/initializeUserWithAuth.js +0 -55
- package/commons/lazyRequire.js +0 -105
- package/commons/logUtils.js +0 -15
- package/commons/logUtils.test.js +0 -21
- package/commons/logger.js +0 -178
- package/commons/mockNetworkRuleFileSchema.json +0 -140
- package/commons/npmWrapper.js +0 -174
- package/commons/npmWrapper.test.js +0 -374
- package/commons/performance-logger.js +0 -71
- package/commons/preloadTests.js +0 -29
- package/commons/prepareRunner.js +0 -85
- package/commons/prepareRunner.test.js +0 -144
- package/commons/prepareRunnerAndTestimStartUtils.js +0 -198
- package/commons/prepareRunnerAndTestimStartUtils.test.js +0 -73
- package/commons/requireWithFallback.js +0 -25
- package/commons/runnerFileCache.js +0 -204
- package/commons/socket/baseSocketServiceSocketIO.js +0 -197
- package/commons/socket/realDataService.js +0 -59
- package/commons/socket/realDataServiceSocketIO.js +0 -33
- package/commons/socket/remoteStepService.js +0 -55
- package/commons/socket/remoteStepServiceSocketIO.js +0 -61
- package/commons/socket/socketService.js +0 -175
- package/commons/socket/testResultService.js +0 -62
- package/commons/socket/testResultServiceSocketIO.js +0 -64
- package/commons/testimAnalytics.js +0 -40
- package/commons/testimCloudflare.js +0 -83
- package/commons/testimCloudflare.test.js +0 -185
- package/commons/testimCustomToken.js +0 -124
- package/commons/testimDesiredCapabilitiesBuilder.js +0 -647
- package/commons/testimNgrok.js +0 -90
- package/commons/testimNgrok.test.js +0 -140
- package/commons/testimServicesApi.js +0 -631
- package/commons/testimTunnel.js +0 -73
- package/commons/testimTunnel.test.js +0 -172
- package/commons/xhr2.js +0 -897
- package/coverage/SummaryToObjectReport.js +0 -19
- package/coverage/jsCoverage.js +0 -252
- package/credentialsManager.js +0 -142
- package/errors.js +0 -161
- package/executionQueue.js +0 -37
- package/fixLocalBuild.js +0 -24
- package/inputFileUtils.js +0 -103
- package/lib/coralogix-winston.transport.js +0 -99
- package/player/SeleniumProtocolError.js +0 -100
- package/player/WebDriverHttpRequest.js +0 -177
- package/player/WebdriverioWebDriverApi.js +0 -671
- package/player/appiumTestPlayer.js +0 -90
- package/player/chromeLauncherTestPlayer.js +0 -67
- package/player/constants.js +0 -332
- package/player/extensionTestPlayer.js +0 -32
- package/player/findElementStrategy.js +0 -154
- package/player/scripts/isElementDisplayed.js +0 -252
- package/player/seleniumTestPlayer.js +0 -140
- package/player/services/frameLocator.js +0 -170
- package/player/services/mobileFrameLocatorMock.js +0 -32
- package/player/services/playbackTimeoutCalculator.js +0 -175
- package/player/services/portSelector.js +0 -19
- package/player/services/tabService.js +0 -551
- package/player/services/tabServiceMock.js +0 -167
- package/player/services/windowCreationListener.js +0 -8
- package/player/stepActions/RefreshStepAction.js +0 -16
- package/player/stepActions/apiStepAction.js +0 -89
- package/player/stepActions/baseCliJsStepAction.js +0 -51
- package/player/stepActions/baseJsStepAction.js +0 -277
- package/player/stepActions/cliConditionStepAction.js +0 -11
- package/player/stepActions/cliJsStepAction.js +0 -11
- package/player/stepActions/dropFileStepAction.js +0 -34
- package/player/stepActions/evaluateExpressionStepAction.js +0 -52
- package/player/stepActions/extensionOnlyStepAction.js +0 -12
- package/player/stepActions/extractTextStepAction.js +0 -19
- package/player/stepActions/hoverStepAction.js +0 -55
- package/player/stepActions/inputFileStepAction.js +0 -199
- package/player/stepActions/jsCodeStepAction.js +0 -11
- package/player/stepActions/jsConditionStepAction.js +0 -11
- package/player/stepActions/locateStepAction.js +0 -159
- package/player/stepActions/mouseStepAction.js +0 -370
- package/player/stepActions/navigationStepAction.js +0 -29
- package/player/stepActions/nodePackageStepAction.js +0 -47
- package/player/stepActions/pixelValidationStepAction.js +0 -39
- package/player/stepActions/scripts/dispatchEvents.js +0 -282
- package/player/stepActions/scripts/doClick.js +0 -221
- package/player/stepActions/scripts/doDragPath.js +0 -225
- package/player/stepActions/scripts/doubleClick.js +0 -119
- package/player/stepActions/scripts/dropEvent.js +0 -63
- package/player/stepActions/scripts/focusElement.js +0 -46
- package/player/stepActions/scripts/html5dragAction.js +0 -56
- package/player/stepActions/scripts/html5dragActionV2.js +0 -312
- package/player/stepActions/scripts/runCode.js +0 -147
- package/player/stepActions/scripts/scroll.js +0 -90
- package/player/stepActions/scripts/selectOption.js +0 -51
- package/player/stepActions/scripts/setText.js +0 -415
- package/player/stepActions/scripts/wheel.js +0 -61
- package/player/stepActions/scrollStepAction.js +0 -96
- package/player/stepActions/selectOptionStepAction.js +0 -49
- package/player/stepActions/sfdcRecordedStepAction.js +0 -24
- package/player/stepActions/sfdcStepAction.js +0 -28
- package/player/stepActions/sleepStepAction.js +0 -12
- package/player/stepActions/specialKeyStepAction.js +0 -52
- package/player/stepActions/stepAction.js +0 -73
- package/player/stepActions/stepActionRegistrar.js +0 -111
- package/player/stepActions/submitStepAction.js +0 -12
- package/player/stepActions/tdkHybridStepAction.js +0 -18
- package/player/stepActions/textStepAction.js +0 -110
- package/player/stepActions/textValidationStepAction.js +0 -64
- package/player/stepActions/wheelStepAction.js +0 -41
- package/player/utils/cookieUtils.js +0 -39
- package/player/utils/eyeSdkService.js +0 -250
- package/player/utils/imageCaptureUtils.js +0 -267
- package/player/utils/screenshotUtils.js +0 -68
- package/player/utils/stepActionUtils.js +0 -90
- package/player/utils/windowUtils.js +0 -195
- package/player/webDriverUtils.js +0 -40
- package/player/webDriverUtils.test.js +0 -116
- package/player/webdriver.js +0 -976
- package/polyfills/Array.prototype.at.js +0 -13
- package/polyfills/index.js +0 -13
- package/processHandler.js +0 -79
- package/processHandler.test.js +0 -55
- package/reports/chromeReporter.js +0 -17
- package/reports/consoleReporter.js +0 -190
- package/reports/debugReporter.js +0 -82
- package/reports/jsonReporter.js +0 -55
- package/reports/junitReporter.js +0 -183
- package/reports/reporter.js +0 -166
- package/reports/reporterUtils.js +0 -54
- package/reports/teamCityReporter.js +0 -73
- package/runOptions.d.ts +0 -305
- package/runOptions.js +0 -1288
- package/runOptionsAgentFlow.js +0 -87
- package/runOptionsUtils.js +0 -60
- package/runner.js +0 -355
- package/runners/ParallelWorkerManager.js +0 -284
- package/runners/TestPlanRunner.js +0 -419
- package/runners/buildCodeTests.js +0 -159
- package/runners/runnerUtils.js +0 -81
- package/services/analyticsService.js +0 -96
- package/services/branchService.js +0 -29
- package/services/gridService.js +0 -357
- package/services/gridService.test.js +0 -357
- package/services/labFeaturesService.js +0 -64
- package/services/lambdatestService.js +0 -227
- package/services/lambdatestService.test.js +0 -353
- package/services/localRCASaver.js +0 -124
- package/stepPlayers/cliJsStepPlayback.js +0 -40
- package/stepPlayers/hybridStepPlayback.js +0 -140
- package/stepPlayers/nodePackageStepPlayback.js +0 -28
- package/stepPlayers/playwrightHybridStepPlayback.js +0 -61
- package/stepPlayers/puppeteerHybridStepPlayback.js +0 -76
- package/stepPlayers/remoteStepPlayback.js +0 -80
- package/stepPlayers/seleniumHybridStepPlayback.js +0 -84
- package/stepPlayers/tdkHybridStepPlayback.js +0 -112
- package/testRunHandler.js +0 -603
- package/testRunStatus.js +0 -567
- package/testimNpmDriver.js +0 -52
- package/utils/argsUtils.js +0 -91
- package/utils/argsUtils.test.js +0 -32
- package/utils/fsUtils.js +0 -174
- package/utils/index.js +0 -197
- package/utils/promiseUtils.js +0 -85
- package/utils/stringUtils.js +0 -98
- package/utils/stringUtils.test.js +0 -22
- package/utils/timeUtils.js +0 -25
- package/utils/utils.test.js +0 -27
- package/workers/BaseWorker.js +0 -498
- package/workers/BaseWorker.test.js +0 -186
- package/workers/WorkerAppium.js +0 -180
- package/workers/WorkerExtension.js +0 -192
- package/workers/WorkerExtensionSingleBrowser.js +0 -77
- package/workers/WorkerSelenium.js +0 -253
- package/workers/workerUtils.js +0 -20
|
@@ -1,282 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const dispatchEvents = function (eventData, done) {
|
|
4
|
-
function getParents(el) {
|
|
5
|
-
return el ? [el].concat(getParents(el.parentNode)) : [];
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
function handleReactSelectFocusQuirk(context, event) {
|
|
9
|
-
function focusReactSelect(element) {
|
|
10
|
-
function getReactSelectRoot(_element) {
|
|
11
|
-
// eslint-disable-next-line prefer-spread
|
|
12
|
-
return getParents(_element).find((el) => Array.apply(null, el.classList || []).includes('Select-control'));
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function getReactSelectInput(_element) {
|
|
16
|
-
const root = getReactSelectRoot(_element);
|
|
17
|
-
return root ? root.querySelector('INPUT') : null;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const reactSelectInput = getReactSelectInput(element);
|
|
21
|
-
if (reactSelectInput) {
|
|
22
|
-
reactSelectInput.focus();
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const isReactSelectElement = context.quirks?.isReactSelect;
|
|
27
|
-
if (event.type === 'mousedown' && isReactSelectElement) {
|
|
28
|
-
focusReactSelect(context.element);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function handleCKEditorQuirk(context, event) {
|
|
33
|
-
const isCKEditorFrame = context.quirks?.isCKEditorFrame;
|
|
34
|
-
if (event.type === 'click' && isCKEditorFrame) {
|
|
35
|
-
document.body.focus();
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function dispatchMouseOver() {
|
|
40
|
-
const event = document.createEvent('Events');
|
|
41
|
-
event.initEvent('mouseover', true, true);
|
|
42
|
-
context.element.dispatchEvent(event);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function dispatchMouseMove() {
|
|
46
|
-
const userEvent = {
|
|
47
|
-
event: 'mousemove',
|
|
48
|
-
modifiers: {},
|
|
49
|
-
button: 0,
|
|
50
|
-
};
|
|
51
|
-
const event = createMouseEvent(userEvent);
|
|
52
|
-
context.element.dispatchEvent(event);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function getEventPosition(userEvent, element) {
|
|
56
|
-
function isWithinBounds(start, end, point) {
|
|
57
|
-
return (point > start) && (point < end);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const pointerPosition = userEvent.pointerPosition || {};
|
|
61
|
-
const rect = element.getBoundingClientRect();
|
|
62
|
-
const clientX = pointerPosition.originX && isWithinBounds(rect.left, rect.left + rect.width, pointerPosition.originX) ? pointerPosition.originX : rect.left + (rect.width / 2);
|
|
63
|
-
const clientY = pointerPosition.originY && isWithinBounds(rect.top, rect.top + rect.height, pointerPosition.originY) ? pointerPosition.originY : rect.top + (rect.height / 2);
|
|
64
|
-
return { x: clientX, y: clientY };
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function createMouseEvent(userEvent) {
|
|
68
|
-
const position = getEventPosition(userEvent, context.element);
|
|
69
|
-
const modifiers = userEvent.modifiers || context.modifiers || {};
|
|
70
|
-
const button = userEvent.button || context.button || 0;
|
|
71
|
-
const eventType = userEvent.event;
|
|
72
|
-
|
|
73
|
-
const event = document.createEvent('MouseEvents');
|
|
74
|
-
event.initMouseEvent(
|
|
75
|
-
eventType,
|
|
76
|
-
true, /* bubbles */
|
|
77
|
-
true, /* cancelable */
|
|
78
|
-
document.defaultView, /* view */
|
|
79
|
-
1, /* detail */
|
|
80
|
-
0, /* screenX */
|
|
81
|
-
0, /* screenY */
|
|
82
|
-
position.x, /* clientX */
|
|
83
|
-
position.y, /* clientY */
|
|
84
|
-
Boolean(modifiers.ctrl), /* ctrl */
|
|
85
|
-
Boolean(modifiers.alt), /* alt */
|
|
86
|
-
Boolean(modifiers.shift), /* shift */
|
|
87
|
-
Boolean(modifiers.meta), /* meta */
|
|
88
|
-
button, /* button */
|
|
89
|
-
document.body ? document.body.parentNode : document.documentElement,
|
|
90
|
-
);
|
|
91
|
-
return event;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function createPointerEvent(userEvent) {
|
|
95
|
-
const position = getEventPosition(userEvent, context.element);
|
|
96
|
-
const modifiers = userEvent.modifiers || context.modifiers || {};
|
|
97
|
-
const eventType = userEvent.event;
|
|
98
|
-
|
|
99
|
-
if (!window.PointerEvent) {
|
|
100
|
-
return undefined;
|
|
101
|
-
}
|
|
102
|
-
return new window.PointerEvent(eventType, {
|
|
103
|
-
screenX: 0,
|
|
104
|
-
screenY: 0,
|
|
105
|
-
clientX: position.x,
|
|
106
|
-
clientY: position.y,
|
|
107
|
-
ctrlKey: Boolean(modifiers.ctrl),
|
|
108
|
-
altKey: Boolean(modifiers.alt),
|
|
109
|
-
shiftKey: Boolean(modifiers.shift),
|
|
110
|
-
metaKey: Boolean(modifiers.meta),
|
|
111
|
-
bubbles: true,
|
|
112
|
-
cancelable: true,
|
|
113
|
-
composed: true,
|
|
114
|
-
pointerType: 'mouse',
|
|
115
|
-
isPrimary: true,
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function createFocusEvent(userEvent) {
|
|
120
|
-
const event = document.createEvent('FocusEvent');
|
|
121
|
-
// TODO we want to use new Event, but mootools (used by zuora which is used by jfrog)
|
|
122
|
-
// overrides window.Event and throws an error
|
|
123
|
-
event.initEvent(userEvent.event, true, false);
|
|
124
|
-
return event;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function createEvent(userEvent) {
|
|
128
|
-
const eventType = userEvent.event;
|
|
129
|
-
const event = document.createEvent('HTMLEvents');
|
|
130
|
-
event.initEvent(eventType, true, false);
|
|
131
|
-
return event;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function dispatchSyncEventSequence() {
|
|
135
|
-
context.events
|
|
136
|
-
.map((userEvent) => {
|
|
137
|
-
try {
|
|
138
|
-
if (MOUSE_EVENTS.includes(userEvent.event)) {
|
|
139
|
-
return createMouseEvent(userEvent);
|
|
140
|
-
} if (POINTER_EVENTS.includes(userEvent.event)) {
|
|
141
|
-
return createPointerEvent(userEvent);
|
|
142
|
-
} if (FOCUS_EVENTS.includes(userEvent.event)) {
|
|
143
|
-
return createFocusEvent(userEvent);
|
|
144
|
-
}
|
|
145
|
-
return createEvent(userEvent);
|
|
146
|
-
} catch (e) {
|
|
147
|
-
// pointer events not supported :shrug:
|
|
148
|
-
return undefined;
|
|
149
|
-
}
|
|
150
|
-
})
|
|
151
|
-
.filter(Boolean)
|
|
152
|
-
.forEach((event) => {
|
|
153
|
-
// eslint-disable-next-line no-console
|
|
154
|
-
console.log(`dispatching: ${event.type}`);
|
|
155
|
-
// eslint-disable-next-line no-console
|
|
156
|
-
console.log(event);
|
|
157
|
-
|
|
158
|
-
context.element.dispatchEvent(event);
|
|
159
|
-
handleReactSelectFocusQuirk(context, event);
|
|
160
|
-
handleCKEditorQuirk(context, event);
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
if (window.__unloadNavigator) {
|
|
164
|
-
window.removeEventListener('unload', window.__unloadNavigator);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
function findEffectiveActiveElement() {
|
|
169
|
-
let activeElement = document.activeElement;
|
|
170
|
-
while (activeElement.shadowRoot?.activeElement) {
|
|
171
|
-
activeElement = activeElement.shadowRoot.activeElement;
|
|
172
|
-
}
|
|
173
|
-
return activeElement;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function handleFocus() {
|
|
177
|
-
const oldActiveElement = findEffectiveActiveElement();
|
|
178
|
-
const quirks = context.quirks;
|
|
179
|
-
const isReactSelectElement = quirks?.isReactSelect;
|
|
180
|
-
const isCKEditorFrame = quirks?.isCKEditorFrame;
|
|
181
|
-
if (!isReactSelectElement && !isCKEditorFrame) {
|
|
182
|
-
// eslint-disable-next-line no-undef
|
|
183
|
-
dispatchFocus(eventData.elementToFocusLocatedElement, oldActiveElement);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
function handleSelect() {
|
|
188
|
-
if (context.element.tagName !== OPTION_TAG_NAME) {
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
let selectEl;
|
|
193
|
-
if (context.element.parentElement.tagName === SELECT_TAG_NAME) {
|
|
194
|
-
selectEl = context.element.parentElement;
|
|
195
|
-
} else if (context.element.parentElement.parentElement.tagName === SELECT_TAG_NAME) {
|
|
196
|
-
selectEl = context.element.parentElement.parentElement;
|
|
197
|
-
}
|
|
198
|
-
selectEl.blur();
|
|
199
|
-
selectEl.selectedIndex = 0;
|
|
200
|
-
context.element.selected = true;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
function fulfill(success, status, result) {
|
|
204
|
-
result = result || {};
|
|
205
|
-
status = {
|
|
206
|
-
success,
|
|
207
|
-
status,
|
|
208
|
-
result,
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
if (isDoneFnSupplied) {
|
|
212
|
-
return done(status);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
return status;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
function resolve(result) {
|
|
219
|
-
return fulfill(true, 'done', result);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
function reject(result) {
|
|
223
|
-
return fulfill(false, 'failed', result);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
const OPTION_TAG_NAME = 'OPTION';
|
|
227
|
-
const SELECT_TAG_NAME = 'SELECT';
|
|
228
|
-
|
|
229
|
-
const MOUSE_EVENTS = [
|
|
230
|
-
'auxclick',
|
|
231
|
-
'click',
|
|
232
|
-
'contextmenu',
|
|
233
|
-
'dblclick',
|
|
234
|
-
'mousedown',
|
|
235
|
-
'mouseenter',
|
|
236
|
-
'mouseleave',
|
|
237
|
-
'mousemove',
|
|
238
|
-
'mouseover',
|
|
239
|
-
'mouseout',
|
|
240
|
-
'mouseup',
|
|
241
|
-
'pointerlockchange',
|
|
242
|
-
'pointerlockerror',
|
|
243
|
-
'select',
|
|
244
|
-
'wheel',
|
|
245
|
-
];
|
|
246
|
-
const POINTER_EVENTS = ['pointerover', 'pointerenter', 'pointerdown', 'pointermove', 'pointerup', 'pointercancel', 'pointerout', 'pointerleave', 'gotpointercapture', 'lostpointercapture'];
|
|
247
|
-
const FOCUS_EVENTS = ['focus', 'blur', 'focusin', 'focusout'];
|
|
248
|
-
|
|
249
|
-
const isDoneFnSupplied = typeof done !== 'undefined';
|
|
250
|
-
|
|
251
|
-
window.__unloadNavigator = resolve;
|
|
252
|
-
window.addEventListener('unload', window.__unloadNavigator);
|
|
253
|
-
|
|
254
|
-
// eslint-disable-next-line no-undef
|
|
255
|
-
const element = eventData.isRoot ? document.documentElement : getLocatedElement(eventData.locatedElement);
|
|
256
|
-
if (!element) {
|
|
257
|
-
return reject('element not found');
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
const context = {
|
|
261
|
-
element,
|
|
262
|
-
events: eventData.events,
|
|
263
|
-
quirks: eventData.quirks,
|
|
264
|
-
modifiers: eventData.modifiers,
|
|
265
|
-
};
|
|
266
|
-
|
|
267
|
-
try {
|
|
268
|
-
const doMousePreparation = eventData.withMousePreparation ? eventData.withMousePreparation : true;
|
|
269
|
-
if (doMousePreparation) {
|
|
270
|
-
dispatchMouseOver();
|
|
271
|
-
dispatchMouseMove();
|
|
272
|
-
}
|
|
273
|
-
handleSelect();
|
|
274
|
-
dispatchSyncEventSequence();
|
|
275
|
-
handleFocus();
|
|
276
|
-
return resolve();
|
|
277
|
-
} catch (e) {
|
|
278
|
-
return reject(e.toString());
|
|
279
|
-
}
|
|
280
|
-
};
|
|
281
|
-
|
|
282
|
-
module.exports = dispatchEvents;
|
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
/* globals getLocatedElement, dispatchFocus */
|
|
2
|
-
|
|
3
|
-
'use strict';
|
|
4
|
-
|
|
5
|
-
const doClick = (eventData, done) => {
|
|
6
|
-
const eventConstructorSupported = typeof Event === 'function';
|
|
7
|
-
|
|
8
|
-
window.__unloadNavigator = resolve;
|
|
9
|
-
|
|
10
|
-
window.addEventListener('unload', window.__unloadNavigator);
|
|
11
|
-
|
|
12
|
-
function handleReactSelectFocusQuirk(context, event) {
|
|
13
|
-
function focusReactSelect(element) {
|
|
14
|
-
function getReactSelectRoot(_element) {
|
|
15
|
-
// eslint-disable-next-line prefer-spread
|
|
16
|
-
return getParents(_element).find((el) => Array.apply(null, el.classList || []).includes('Select-control'));
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function getReactSelectInput(_element) {
|
|
20
|
-
const root = getReactSelectRoot(_element);
|
|
21
|
-
return root ? root.querySelector('INPUT') : null;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const reactSelectInput = getReactSelectInput(element);
|
|
25
|
-
if (reactSelectInput) {
|
|
26
|
-
reactSelectInput.focus();
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const isReactSelectElement = context.quirks?.isReactSelect;
|
|
31
|
-
if (event.type === 'mousedown' && isReactSelectElement) {
|
|
32
|
-
focusReactSelect(context.element);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function handleCKEditorQuirk(context, event) {
|
|
37
|
-
const isCKEditorFrame = context.quirks?.isCKEditorFrame;
|
|
38
|
-
if (event.type === 'click' && isCKEditorFrame) {
|
|
39
|
-
document.body.focus();
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function getParents(el) {
|
|
44
|
-
return el ? [el].concat(getParents(el.parentNode)) : [];
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function resolve(result) {
|
|
48
|
-
const status = {
|
|
49
|
-
status: 'done',
|
|
50
|
-
result,
|
|
51
|
-
success: true,
|
|
52
|
-
};
|
|
53
|
-
if (context.isNonTextableElemnet) {
|
|
54
|
-
status.reason = 'Set text on non input element';
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
done(status);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function reject(result) {
|
|
61
|
-
result = result || {};
|
|
62
|
-
const status = {
|
|
63
|
-
status: 'failed',
|
|
64
|
-
result,
|
|
65
|
-
success: false,
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
done(status);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function dispatchMouseOver(element) {
|
|
72
|
-
const event = eventConstructorSupported ? new Event('mouseover', { composed: true }) : document.createEvent('Events');
|
|
73
|
-
event.initEvent('mouseover', true, true);
|
|
74
|
-
element.dispatchEvent(event);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function dispatchMouseMove(element) {
|
|
78
|
-
const modifiers = {};
|
|
79
|
-
const rect = element.getBoundingClientRect();
|
|
80
|
-
const clientX = rect.left + (rect.width / 2);
|
|
81
|
-
const clientY = rect.top + (rect.height / 2);
|
|
82
|
-
const button = 0;
|
|
83
|
-
const eventType = 'mousemove';
|
|
84
|
-
const event = createMouseEvent(eventType, modifiers, clientX, clientY, button);
|
|
85
|
-
element.dispatchEvent(event);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function getEventPosition(userEvent, element) {
|
|
89
|
-
function isWithinBounds(start, end, point) {
|
|
90
|
-
return (point > start) && (point < end);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const pointerPosition = userEvent.pointerPosition || {};
|
|
94
|
-
const rect = element.getBoundingClientRect();
|
|
95
|
-
const clientX = pointerPosition.originX && isWithinBounds(rect.left, rect.left + rect.width, pointerPosition.originX) ? pointerPosition.originX : rect.left + (rect.width / 2);
|
|
96
|
-
const clientY = pointerPosition.originY && isWithinBounds(rect.top, rect.top + rect.height, pointerPosition.originY) ? pointerPosition.originY : rect.top + (rect.height / 2);
|
|
97
|
-
return { x: clientX, y: clientY };
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function getEventDictionary(modifiers, clientX, clientY) {
|
|
101
|
-
return {
|
|
102
|
-
screenX: 0,
|
|
103
|
-
screenY: 0,
|
|
104
|
-
clientX,
|
|
105
|
-
clientY,
|
|
106
|
-
ctrlKey: Boolean(modifiers.ctrl),
|
|
107
|
-
altKey: Boolean(modifiers.alt),
|
|
108
|
-
shiftKey: Boolean(modifiers.shift),
|
|
109
|
-
metaKey: Boolean(modifiers.meta),
|
|
110
|
-
bubbles: true,
|
|
111
|
-
cancelable: true,
|
|
112
|
-
composed: true,
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function createPointerEvent(eventType, modifiers, clientX, clientY) {
|
|
117
|
-
if (!window.PointerEvent) {
|
|
118
|
-
return undefined;
|
|
119
|
-
}
|
|
120
|
-
const eventProperties = getEventDictionary(modifiers, clientX, clientY);
|
|
121
|
-
eventProperties.pointerType = 'mouse';
|
|
122
|
-
eventProperties.isPrimary = true;
|
|
123
|
-
return new window.PointerEvent(eventType, eventProperties);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
function createMouseEvent(eventType, modifiers, clientX, clientY, button) {
|
|
127
|
-
const event = eventConstructorSupported ? new MouseEvent('click', { composed: true }) : document.createEvent('MouseEvents');
|
|
128
|
-
event.initMouseEvent(
|
|
129
|
-
eventType,
|
|
130
|
-
true,
|
|
131
|
-
true,
|
|
132
|
-
document.defaultView,
|
|
133
|
-
1,
|
|
134
|
-
0,
|
|
135
|
-
0,
|
|
136
|
-
clientX,
|
|
137
|
-
clientY,
|
|
138
|
-
Boolean(modifiers.ctrl),
|
|
139
|
-
Boolean(modifiers.alt),
|
|
140
|
-
Boolean(modifiers.shift),
|
|
141
|
-
Boolean(modifiers.meta),
|
|
142
|
-
button,
|
|
143
|
-
document.body ? document.body.parentNode : document.documentElement);
|
|
144
|
-
return event;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
function getMouseEvent(userEvent, context) {
|
|
148
|
-
const pointerEvents = ['pointerup', 'pointerdown', 'pointermove'];
|
|
149
|
-
const modifiers = context.modifiers || {};
|
|
150
|
-
const pos = getEventPosition(userEvent, context.element);
|
|
151
|
-
const button = context.button || 0;
|
|
152
|
-
const eventType = userEvent.event;
|
|
153
|
-
if (pointerEvents.includes(eventType)) {
|
|
154
|
-
return createPointerEvent(eventType, modifiers, pos.x, pos.y);
|
|
155
|
-
}
|
|
156
|
-
return createMouseEvent(eventType, modifiers, pos.x, pos.y, button);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
function findEffectiveActiveElement() {
|
|
160
|
-
let activeElement = document.activeElement;
|
|
161
|
-
while (activeElement.shadowRoot?.activeElement) {
|
|
162
|
-
activeElement = activeElement.shadowRoot.activeElement;
|
|
163
|
-
}
|
|
164
|
-
return activeElement;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
function executeSynchronousEventSequence(context) {
|
|
168
|
-
context.events
|
|
169
|
-
.map((userEvent) => {
|
|
170
|
-
try {
|
|
171
|
-
return getMouseEvent(userEvent, context);
|
|
172
|
-
} catch (e) {
|
|
173
|
-
// pointer events not supported :shrug:
|
|
174
|
-
return undefined;
|
|
175
|
-
}
|
|
176
|
-
})
|
|
177
|
-
.filter(Boolean)
|
|
178
|
-
.forEach((event) => {
|
|
179
|
-
context.element.dispatchEvent(event);
|
|
180
|
-
handleReactSelectFocusQuirk(context, event);
|
|
181
|
-
handleCKEditorQuirk(context, event);
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
if (window.__unloadNavigator) {
|
|
185
|
-
window.removeEventListener('unload', window.__unloadNavigator);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
const element = eventData.isRoot ? document.documentElement : getLocatedElement(eventData.locatedElement);
|
|
190
|
-
// eslint-disable-next-line no-var
|
|
191
|
-
var context = {
|
|
192
|
-
element,
|
|
193
|
-
events: eventData.events,
|
|
194
|
-
quirks: eventData.quirks,
|
|
195
|
-
modifiers: eventData.modifiers,
|
|
196
|
-
button: eventData.button,
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
if (!context.element) {
|
|
200
|
-
reject('element not found');
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
dispatchMouseOver(context.element);
|
|
205
|
-
dispatchMouseMove(context.element);
|
|
206
|
-
try {
|
|
207
|
-
executeSynchronousEventSequence(context);
|
|
208
|
-
const oldActiveElement = findEffectiveActiveElement();
|
|
209
|
-
const quirks = context.quirks;
|
|
210
|
-
const isReactSelectElement = quirks?.isReactSelect;
|
|
211
|
-
const isCKEditorFrame = quirks?.isCKEditorFrame;
|
|
212
|
-
if (!isReactSelectElement && !isCKEditorFrame) {
|
|
213
|
-
dispatchFocus(eventData.elementToFocusLocatedElement, oldActiveElement);
|
|
214
|
-
}
|
|
215
|
-
resolve();
|
|
216
|
-
} catch (e) {
|
|
217
|
-
reject(e.toString());
|
|
218
|
-
}
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
module.exports = doClick;
|