@mablhq/mabl-cli 1.54.3 → 1.55.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.
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EmbeddedPdfDetectionEvents = void 0;
3
+ exports.WEB_PERFORMANCE_METRIC_DETECTED_MESSAGE_TYPE = exports.EmbeddedPdfDetectionEvents = void 0;
4
4
  var EmbeddedPdfDetectionEvents;
5
5
  (function (EmbeddedPdfDetectionEvents) {
6
6
  EmbeddedPdfDetectionEvents["EmbeddedPdfDetected"] = "EMBEDDED_PDF_DETECTED";
7
7
  EmbeddedPdfDetectionEvents["EmbeddedPdfMarked"] = "EMBEDDED_PDF_MARKED";
8
8
  })(EmbeddedPdfDetectionEvents = exports.EmbeddedPdfDetectionEvents || (exports.EmbeddedPdfDetectionEvents = {}));
9
+ exports.WEB_PERFORMANCE_METRIC_DETECTED_MESSAGE_TYPE = 'WEB_PERFORMANCE_METRIC_DETECTED';
@@ -78,8 +78,8 @@ async function editTest(trainingSessionOptions) {
78
78
  if (test.default) {
79
79
  throw new Error('Editing of the mabl default supplied tests is not supported');
80
80
  }
81
- if (!((_g = test.flows) === null || _g === void 0 ? void 0 : _g.length)) {
82
- throw new Error(util_2.TEST_INFO_NOT_FOUND);
81
+ if (!((_g = test.flows) === null || _g === void 0 ? void 0 : _g.length) && test.test_type !== mablApi_1.TestTypeEnum.Performance) {
82
+ throw new Error(util_2.TEST_WITHOUT_FLOWS_MESSAGE);
83
83
  }
84
84
  const workspaceId = test.organization_id;
85
85
  if (branchName !== 'master') {
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.attachListeners = exports.listenersAreAttached = void 0;
4
+ const web_vitals_1 = require("web-vitals");
5
+ const POLLING_MAX_ATTEMPTS = 10;
6
+ const POLLING_INTERVAL_MILLIS = 100;
7
+ exports.listenersAreAttached = false;
8
+ function attachListeners() {
9
+ (0, web_vitals_1.onCLS)(sendMetric);
10
+ (0, web_vitals_1.onFCP)(sendMetric);
11
+ (0, web_vitals_1.onLCP)(sendMetric);
12
+ (0, web_vitals_1.onTTFB)(sendMetric);
13
+ onNavigationEvent(sendMetric);
14
+ exports.listenersAreAttached = true;
15
+ }
16
+ exports.attachListeners = attachListeners;
17
+ function handleNavigationEvent(eventName, callback) {
18
+ var _a;
19
+ const performanceEntries = performance.getEntriesByType('navigation');
20
+ const navigationTiming = performanceEntries === null || performanceEntries === void 0 ? void 0 : performanceEntries[0];
21
+ const eventTimestamp = navigationTiming === null || navigationTiming === void 0 ? void 0 : navigationTiming[eventName];
22
+ callback({
23
+ name: eventName,
24
+ value: eventTimestamp,
25
+ delta: eventTimestamp,
26
+ rating: 'none',
27
+ id: `NAV:${eventName}:${eventTimestamp}:${Date.now()}`,
28
+ entries: performanceEntries === null || performanceEntries === void 0 ? void 0 : performanceEntries.map((entry) => entry === null || entry === void 0 ? void 0 : entry.toJSON()),
29
+ navigationType: (_a = navigationTiming === null || navigationTiming === void 0 ? void 0 : navigationTiming.type) !== null && _a !== void 0 ? _a : 'navigate',
30
+ });
31
+ }
32
+ function pollForEventTimestamp(eventName, callback, navigationTiming) {
33
+ var _a;
34
+ navigationTiming =
35
+ navigationTiming !== null && navigationTiming !== void 0 ? navigationTiming : (_a = performance.getEntriesByType('navigation')) === null || _a === void 0 ? void 0 : _a[0];
36
+ if (navigationTiming === null || navigationTiming === void 0 ? void 0 : navigationTiming[eventName]) {
37
+ handleNavigationEvent(eventName, callback);
38
+ return;
39
+ }
40
+ let attempts = 0;
41
+ const interval = window.setInterval(() => {
42
+ var _a;
43
+ attempts++;
44
+ const navigationTiming = (_a = performance.getEntriesByType('navigation')) === null || _a === void 0 ? void 0 : _a[0];
45
+ if ((navigationTiming === null || navigationTiming === void 0 ? void 0 : navigationTiming[eventName]) || attempts >= POLLING_MAX_ATTEMPTS) {
46
+ handleNavigationEvent(eventName, callback);
47
+ window.clearInterval(interval);
48
+ }
49
+ }, POLLING_INTERVAL_MILLIS);
50
+ }
51
+ function onNavigationEvent(callback) {
52
+ var _a;
53
+ const navigationTiming = (_a = performance.getEntriesByType('navigation')) === null || _a === void 0 ? void 0 : _a[0];
54
+ if (navigationTiming !== undefined) {
55
+ handleNavigationEvent('startTime', callback);
56
+ }
57
+ if (navigationTiming === null || navigationTiming === void 0 ? void 0 : navigationTiming.domContentLoadedEventEnd) {
58
+ handleNavigationEvent('domContentLoadedEventEnd', callback);
59
+ }
60
+ else {
61
+ document.addEventListener('DOMContentLoaded', function () {
62
+ pollForEventTimestamp('domContentLoadedEventEnd', callback);
63
+ });
64
+ }
65
+ if (document.readyState === 'complete' || (navigationTiming === null || navigationTiming === void 0 ? void 0 : navigationTiming.loadEventEnd)) {
66
+ pollForEventTimestamp('loadEventEnd', callback, navigationTiming);
67
+ }
68
+ else {
69
+ window.addEventListener('load', function () {
70
+ pollForEventTimestamp('loadEventEnd', callback);
71
+ });
72
+ }
73
+ }
74
+ const sendMetric = (metric) => {
75
+ var _a, _b, _c;
76
+ const navigationTiming = (_a = performance.getEntriesByType('navigation')) === null || _a === void 0 ? void 0 : _a[0];
77
+ (_c = (_b = window).dispatchMablEvent) === null || _c === void 0 ? void 0 : _c.call(_b, {
78
+ createdTime: Date.now(),
79
+ timeOrigin: performance.timeOrigin,
80
+ type: 'WEB_PERFORMANCE_METRIC_DETECTED',
81
+ currentUrl: window.document.URL,
82
+ navigationUrl: navigationTiming === null || navigationTiming === void 0 ? void 0 : navigationTiming.name,
83
+ metric,
84
+ });
85
+ };