@elastic/synthetics 1.17.1 → 1.18.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.
Files changed (90) hide show
  1. package/dist/cli.js.map +1 -1
  2. package/dist/common_types.d.ts.map +1 -1
  3. package/dist/core/globals.d.ts +1 -0
  4. package/dist/core/globals.d.ts.map +1 -1
  5. package/dist/core/globals.js +12 -1
  6. package/dist/core/globals.js.map +1 -1
  7. package/dist/core/index.d.ts +1 -0
  8. package/dist/core/index.d.ts.map +1 -1
  9. package/dist/core/index.js +13 -12
  10. package/dist/core/index.js.map +1 -1
  11. package/dist/core/logger.d.ts.map +1 -1
  12. package/dist/core/logger.js +2 -7
  13. package/dist/core/logger.js.map +1 -1
  14. package/dist/core/mfa.d.ts.map +1 -1
  15. package/dist/core/mfa.js +1 -1
  16. package/dist/core/runner.d.ts +40 -0
  17. package/dist/core/runner.d.ts.map +1 -1
  18. package/dist/core/runner.js +71 -6
  19. package/dist/core/runner.js.map +1 -1
  20. package/dist/dsl/journey.d.ts +35 -0
  21. package/dist/dsl/journey.d.ts.map +1 -1
  22. package/dist/dsl/journey.js +49 -0
  23. package/dist/dsl/journey.js.map +1 -1
  24. package/dist/dsl/monitor.d.ts +4 -0
  25. package/dist/dsl/monitor.d.ts.map +1 -1
  26. package/dist/dsl/monitor.js +6 -0
  27. package/dist/dsl/monitor.js.map +1 -1
  28. package/dist/dsl/step.d.ts +5 -0
  29. package/dist/dsl/step.d.ts.map +1 -1
  30. package/dist/dsl/step.js +7 -0
  31. package/dist/dsl/step.js.map +1 -1
  32. package/dist/formatter/javascript.d.ts.map +1 -1
  33. package/dist/formatter/javascript.js.map +1 -1
  34. package/dist/generator/utils.d.ts +1 -1
  35. package/dist/helpers.d.ts.map +1 -1
  36. package/dist/helpers.js.map +1 -1
  37. package/dist/plugins/tracing.js.map +1 -1
  38. package/dist/push/bundler.d.ts +2 -5
  39. package/dist/push/bundler.d.ts.map +1 -1
  40. package/dist/push/bundler.js +15 -30
  41. package/dist/push/bundler.js.map +1 -1
  42. package/dist/push/index.d.ts.map +1 -1
  43. package/dist/push/index.js +21 -6
  44. package/dist/push/index.js.map +1 -1
  45. package/dist/push/monitor.d.ts +4 -1
  46. package/dist/push/monitor.d.ts.map +1 -1
  47. package/dist/push/monitor.js +13 -1
  48. package/dist/push/monitor.js.map +1 -1
  49. package/dist/push/run-local.d.ts +27 -0
  50. package/dist/push/run-local.d.ts.map +1 -0
  51. package/dist/push/run-local.js +132 -0
  52. package/dist/push/run-local.js.map +1 -0
  53. package/dist/push/utils.d.ts +2 -0
  54. package/dist/push/utils.d.ts.map +1 -1
  55. package/dist/push/utils.js +33 -1
  56. package/dist/push/utils.js.map +1 -1
  57. package/dist/reporters/base.d.ts.map +1 -1
  58. package/dist/reporters/base.js.map +1 -1
  59. package/dist/reporters/build_kite_cli.d.ts.map +1 -1
  60. package/dist/reporters/build_kite_cli.js.map +1 -1
  61. package/dist/reporters/json.d.ts +1 -1
  62. package/dist/reporters/json.d.ts.map +1 -1
  63. package/dist/reporters/json.js +6 -2
  64. package/dist/reporters/json.js.map +1 -1
  65. package/dist/reporters/junit.d.ts.map +1 -1
  66. package/dist/reporters/junit.js.map +1 -1
  67. package/package.json +8 -5
  68. package/src/cli.ts +8 -3
  69. package/src/common_types.ts +1 -1
  70. package/src/core/globals.ts +12 -0
  71. package/src/core/index.ts +3 -1
  72. package/src/core/logger.ts +2 -8
  73. package/src/core/mfa.ts +11 -11
  74. package/src/core/runner.ts +102 -33
  75. package/src/dsl/journey.ts +63 -1
  76. package/src/dsl/monitor.ts +7 -0
  77. package/src/dsl/step.ts +8 -0
  78. package/src/formatter/javascript.ts +3 -1
  79. package/src/helpers.ts +3 -3
  80. package/src/loader.ts +1 -1
  81. package/src/plugins/tracing.ts +1 -1
  82. package/src/push/bundler.ts +16 -36
  83. package/src/push/index.ts +28 -10
  84. package/src/push/monitor.ts +16 -4
  85. package/src/push/run-local.ts +155 -0
  86. package/src/push/utils.ts +51 -5
  87. package/src/reporters/base.ts +8 -4
  88. package/src/reporters/build_kite_cli.ts +7 -6
  89. package/src/reporters/json.ts +10 -14
  90. package/src/reporters/junit.ts +4 -10
@@ -34,4 +34,16 @@ if (!global[SYNTHETICS_RUNNER]) {
34
34
  global[SYNTHETICS_RUNNER] = new Runner();
35
35
  }
36
36
 
37
+ /**
38
+ * Set debug based on DEBUG ENV and namespace - synthetics
39
+ */
40
+ if (process.env.DEBUG && process.env.DEBUG.includes('synthetics')) {
41
+ process.env['__SYNTHETICS__DEBUG__'] = '1';
42
+ }
43
+
37
44
  export const runner: Runner = global[SYNTHETICS_RUNNER];
45
+
46
+ // is Debug mode enabled
47
+ export function inDebugMode() {
48
+ return !!process.env['__SYNTHETICS__DEBUG__'];
49
+ }
package/src/core/index.ts CHANGED
@@ -30,7 +30,7 @@ import {
30
30
  JourneyWithAnnotations,
31
31
  StepWithAnnotations,
32
32
  } from '../dsl';
33
- import { runner } from "./globals"
33
+ import { runner as runnerGlobal } from './globals';
34
34
  import { VoidCallback, HooksCallback, Location } from '../common_types';
35
35
  import { wrapFnWithLocation } from '../helpers';
36
36
  import { log } from './logger';
@@ -112,3 +112,5 @@ export const after = (callback: HooksCallback) => {
112
112
  }
113
113
  return runner.currentJourney._addHook('after', callback);
114
114
  };
115
+
116
+ export const runner = runnerGlobal;
@@ -25,16 +25,10 @@
25
25
 
26
26
  import { grey, cyan, dim, italic } from 'kleur/colors';
27
27
  import { now } from '../helpers';
28
-
29
- /**
30
- * Set debug based on DEBUG ENV and namespace - synthetics
31
- */
32
- if (process.env.DEBUG && process.env.DEBUG.includes('synthetics')) {
33
- process.env['__SYNTHETICS__DEBUG__'] = '1';
34
- }
28
+ import { inDebugMode } from './globals';
35
29
 
36
30
  export function log(msg) {
37
- if (!process.env['__SYNTHETICS__DEBUG__'] || !msg) {
31
+ if (!inDebugMode() || !msg) {
38
32
  return;
39
33
  }
40
34
  if (typeof msg === 'object') {
package/src/core/mfa.ts CHANGED
@@ -23,48 +23,48 @@
23
23
  *
24
24
  */
25
25
 
26
- import { TOTP } from "otpauth";
26
+ import { TOTP } from 'otpauth';
27
27
 
28
28
  type TOTPOptions = {
29
29
  /**
30
30
  * Provider or Service the secret is associated with
31
31
  */
32
- issuer?: string
32
+ issuer?: string;
33
33
  /**
34
34
  * Account Identifier.
35
35
  * @default 'SyntheticsTOTP'
36
36
  */
37
- label?: string
37
+ label?: string;
38
38
  /**
39
39
  * Include issuer prefix in label.
40
40
  */
41
- issuerInLabel?: boolean
41
+ issuerInLabel?: boolean;
42
42
  /**
43
43
  * The encoded secret key used to generate the TOTP.
44
44
  */
45
- secret?: string
45
+ secret?: string;
46
46
  /**
47
47
  * The algorithm used to generate the TOTP.
48
48
  * @default 'SHA1'
49
49
  */
50
- algorithm?: string
50
+ algorithm?: string;
51
51
  /**
52
52
  * Number of digits in the generated token.
53
53
  * @default 6
54
54
  */
55
- digits?: number
55
+ digits?: number;
56
56
  /**
57
57
  * Validity period in seconds for the token.
58
58
  * @default 30
59
59
  */
60
- period?: number
60
+ period?: number;
61
61
  };
62
62
 
63
63
  export type TOTPCmdOptions = {
64
- issuer?: string
65
- label?: string
64
+ issuer?: string;
65
+ label?: string;
66
66
  };
67
67
 
68
68
  export function totp(secret?: string, options: TOTPOptions = {}) {
69
- return new TOTP({ label: "SyntheticsTOTP", secret, ...options }).generate();
69
+ return new TOTP({ label: 'SyntheticsTOTP', secret, ...options }).generate();
70
70
  }
@@ -45,10 +45,7 @@ import {
45
45
  StepResult,
46
46
  PushOptions,
47
47
  } from '../common_types';
48
- import {
49
- PerformanceManager,
50
- filterBrowserMessages,
51
- } from '../plugins';
48
+ import { PerformanceManager, filterBrowserMessages } from '../plugins';
52
49
  import { Gatherer } from './gatherer';
53
50
  import { log } from './logger';
54
51
  import { Monitor, MonitorConfig } from '../dsl/monitor';
@@ -104,7 +101,7 @@ export default class Runner implements RunnerInfo {
104
101
  type: 'jpeg',
105
102
  quality: 80,
106
103
  timeout: 5000,
107
- })
104
+ });
108
105
  /**
109
106
  * Write the screenshot image buffer with additional details (step
110
107
  * information) which could be extracted at the end of
@@ -131,8 +128,20 @@ export default class Runner implements RunnerInfo {
131
128
  this.#hooks[type].push(callback);
132
129
  }
133
130
 
131
+ /**
132
+ * @deprecated Since version Please do not rely on the internal methods.
133
+ * Alias _addHook for backwards compatibility
134
+ */
135
+ addHook(type: HookType, callback: HooksCallback) {
136
+ this._addHook(type, callback);
137
+ }
138
+
134
139
  private buildHookArgs() {
135
- return { env: this.config.environment, params: this.config.params, info: this as RunnerInfo };
140
+ return {
141
+ env: this.config.environment,
142
+ params: this.config.params,
143
+ info: this as RunnerInfo,
144
+ };
136
145
  }
137
146
 
138
147
  _updateMonitor(config: MonitorConfig) {
@@ -143,11 +152,27 @@ export default class Runner implements RunnerInfo {
143
152
  this.#monitor.update(config);
144
153
  }
145
154
 
155
+ /**
156
+ * @deprecated Since version Please do not rely on the internal methods.
157
+ * Alias _addJourney for backwards compatibility
158
+ */
159
+ updateMonitor(config: MonitorConfig) {
160
+ this._updateMonitor(config);
161
+ }
162
+
146
163
  _addJourney(journey: Journey) {
147
164
  this.#journeys.push(journey);
148
165
  this.#currentJourney = journey;
149
166
  }
150
167
 
168
+ /**
169
+ * @deprecated Since version 1.17.0. Please do not rely on the internal methods.
170
+ * Alias _addJourney for backwards compatibility
171
+ */
172
+ addJourney(journey: Journey) {
173
+ this._addJourney(journey);
174
+ }
175
+
151
176
  private setReporter(options: RunOptions) {
152
177
  /**
153
178
  * Set up the corresponding reporter and fallback
@@ -181,10 +206,7 @@ export default class Runner implements RunnerInfo {
181
206
  await runParallel(journey._getHook('after'), args);
182
207
  }
183
208
 
184
- async #runStep(
185
- step: Step,
186
- options: RunOptions
187
- ): Promise<StepResult> {
209
+ async #runStep(step: Step, options: RunOptions): Promise<StepResult> {
188
210
  log(`Runner: start step (${step.name})`);
189
211
  const { metrics, screenshots, filmstrips, trace } = options;
190
212
  /**
@@ -212,7 +234,7 @@ export default class Runner implements RunnerInfo {
212
234
  // invoke the step callback by extracting to a variable to get better stack trace
213
235
  const cb = step.cb;
214
236
  await cb();
215
- step.status = "succeeded"
237
+ step.status = 'succeeded';
216
238
  } catch (error) {
217
239
  step.status = 'failed';
218
240
  step.error = error;
@@ -245,13 +267,10 @@ export default class Runner implements RunnerInfo {
245
267
  }
246
268
  }
247
269
  log(`Runner: end step (${step.name})`);
248
- return data
270
+ return data;
249
271
  }
250
272
 
251
- async #runSteps(
252
- journey: Journey,
253
- options: RunOptions
254
- ) {
273
+ async #runSteps(journey: Journey, options: RunOptions) {
255
274
  const results: Array<StepResult> = [];
256
275
  const isOnlyExists = journey.steps.filter(s => s.only).length > 0;
257
276
  let skipStep = false;
@@ -297,7 +316,7 @@ export default class Runner implements RunnerInfo {
297
316
  * caching all screenshots and clear them at end of each journey
298
317
  */
299
318
  await mkdir(this.#screenshotPath, { recursive: true });
300
- const params = options.params
319
+ const params = options.params;
301
320
  this.#reporter?.onJourneyStart?.(journey, {
302
321
  timestamp: getTimestamp(),
303
322
  params,
@@ -315,7 +334,10 @@ export default class Runner implements RunnerInfo {
315
334
  ) {
316
335
  // Enhance the journey results
317
336
  const pOutput = await Gatherer.pluginManager.output();
318
- const bConsole = filterBrowserMessages(pOutput.browserconsole, journey.status);
337
+ const bConsole = filterBrowserMessages(
338
+ pOutput.browserconsole,
339
+ journey.status
340
+ );
319
341
  await this.#reporter?.onJourneyEnd?.(journey, {
320
342
  browserDelay: this.#browserDelay,
321
343
  timestamp: getTimestamp(),
@@ -324,7 +346,7 @@ export default class Runner implements RunnerInfo {
324
346
  browserconsole: bConsole,
325
347
  });
326
348
  await Gatherer.endRecording();
327
- await Gatherer.dispose(this.#driver)
349
+ await Gatherer.dispose(this.#driver);
328
350
  // clear screenshots cache after each journey
329
351
  await rm(this.#screenshotPath, { recursive: true, force: true });
330
352
  return Object.assign(result, {
@@ -361,12 +383,16 @@ export default class Runner implements RunnerInfo {
361
383
  this.#currentJourney = journey;
362
384
  log(`Runner: start journey (${journey.name})`);
363
385
  let result: JourneyResult = {};
364
- const hookArgs = { env: options.environment, params: options.params, info: this };
386
+ const hookArgs = {
387
+ env: options.environment,
388
+ params: options.params,
389
+ info: this,
390
+ };
365
391
  try {
366
392
  await this.#startJourney(journey, options);
367
393
  await this.#runBeforeHook(journey, hookArgs);
368
394
  const stepResults = await this.#runSteps(journey, options);
369
- journey.status = "succeeded";
395
+ journey.status = 'succeeded';
370
396
  // Mark journey as failed if any one of the step fails
371
397
  for (const step of journey.steps) {
372
398
  if (step.status === 'failed') {
@@ -385,13 +411,21 @@ export default class Runner implements RunnerInfo {
385
411
  await this.#runAfterHook(journey, hookArgs).catch(e => {
386
412
  journey.status = 'failed';
387
413
  journey.error = e;
388
- })
414
+ });
389
415
  result = await this.#endJourney(journey, result, options);
390
416
  }
391
417
  log(`Runner: end journey (${journey.name})`);
392
418
  return result;
393
419
  }
394
420
 
421
+ /**
422
+ * @deprecated Since version 1.17.0. Please do not rely on the internal methods.
423
+ * Alias _runJourney for backwards compatibility
424
+ */
425
+ runJourney(journey: Journey, options: RunOptions) {
426
+ this._runJourney(journey, options);
427
+ }
428
+
395
429
  _buildMonitors(options: PushOptions) {
396
430
  /**
397
431
  * Update the global monitor configuration required for setting defaults
@@ -426,15 +460,12 @@ export default class Runner implements RunnerInfo {
426
460
  * - filter out monitors based on matched tags and name after applying both
427
461
  * global and local monitor configurations
428
462
  */
429
- journey.cb({ params: options.params } as any);
430
- const monitor = journey._getMonitor();
463
+
464
+ // TODO: Fix backwards compatibility with 1.14 and prior
465
+ (journey.cb ?? journey.callback)({ params: options.params } as any);
466
+ const monitor = journey.monitor ?? journey?._getMonitor();
431
467
  monitor.update(this.#monitor?.config);
432
- if (
433
- !monitor.isMatch(
434
- options.grepOpts?.match,
435
- options.grepOpts?.tags
436
- )
437
- ) {
468
+ if (!monitor.isMatch(options.grepOpts?.match, options.grepOpts?.tags)) {
438
469
  continue;
439
470
  }
440
471
  monitor.validate();
@@ -443,6 +474,14 @@ export default class Runner implements RunnerInfo {
443
474
  return monitors;
444
475
  }
445
476
 
477
+ /**
478
+ * @deprecated Since version 1.17.0. Please do not rely on the internal methods.
479
+ * Alias _buildMonitors for backwards compatibility
480
+ */
481
+ buildMonitors(options: PushOptions) {
482
+ this._buildMonitors(options);
483
+ }
484
+
446
485
  async #init(options: RunOptions) {
447
486
  this.setReporter(options);
448
487
  this.#reporter.onStart?.({
@@ -474,20 +513,34 @@ export default class Runner implements RunnerInfo {
474
513
  this.#journeys = onlyJournerys;
475
514
  } else {
476
515
  // filter journeys based on tags and skip annotations
477
- this.#journeys = this.#journeys.filter(j => j._isMatch(grepOpts?.match, grepOpts?.tags) && !j.skip);
516
+ this.#journeys = this.#journeys.filter(
517
+ j => j._isMatch(grepOpts?.match, grepOpts?.tags) && !j.skip
518
+ );
478
519
  }
479
520
 
480
521
  // Used by heartbeat to gather all registered journeys
481
522
  if (dryRun) {
482
- this.#journeys.forEach(journey => this.#reporter.onJourneyRegister?.(journey))
523
+ this.#journeys.forEach(journey =>
524
+ this.#reporter.onJourneyRegister?.(journey)
525
+ );
483
526
  } else if (this.#journeys.length > 0) {
484
527
  result = await this._runJourneys(options);
485
528
  }
486
- await this.#runAfterAllHook(hookArgs).catch(async () => await this._reset());
529
+ await this.#runAfterAllHook(hookArgs).catch(
530
+ async () => await this._reset()
531
+ );
487
532
  await this._reset();
488
533
  return result;
489
534
  }
490
535
 
536
+ /**
537
+ * @deprecated Since version 1.17.0. Please do not rely on the internal methods.
538
+ * Alias _run for backwards compatibility
539
+ */
540
+ run(options: RunOptions): Promise<RunResult> {
541
+ return this._run(options);
542
+ }
543
+
491
544
  async _runJourneys(options: RunOptions) {
492
545
  const result: RunResult = {};
493
546
  const browserStart = monotonicTimeInSeconds();
@@ -504,6 +557,14 @@ export default class Runner implements RunnerInfo {
504
557
  return result;
505
558
  }
506
559
 
560
+ /**
561
+ * @deprecated Since version 1.17.0. Please do not rely on the internal methods.
562
+ * Alias _runJourneys for backwards compatibility
563
+ */
564
+ runJourneys(options: RunOptions): Promise<RunResult> {
565
+ return this._runJourneys(options);
566
+ }
567
+
507
568
  async _reset() {
508
569
  this.#currentJourney = null;
509
570
  this.#journeys = [];
@@ -515,4 +576,12 @@ export default class Runner implements RunnerInfo {
515
576
  await rm(CACHE_PATH, { recursive: true, force: true });
516
577
  await this.#reporter?.onEnd?.();
517
578
  }
579
+
580
+ /**
581
+ * @deprecated Since version 1.17.0. Please do not rely on the internal methods.
582
+ * Alias _reset for backwards compatibility
583
+ */
584
+ reset() {
585
+ return this._reset();
586
+ }
518
587
  }
@@ -31,7 +31,13 @@ import {
31
31
  APIRequestContext,
32
32
  } from 'playwright-core';
33
33
  import { Step } from './step';
34
- import { VoidCallback, HooksCallback, Params, Location, StatusValue } from '../common_types';
34
+ import {
35
+ VoidCallback,
36
+ HooksCallback,
37
+ Params,
38
+ Location,
39
+ StatusValue,
40
+ } from '../common_types';
35
41
  import { Monitor, MonitorConfig } from './monitor';
36
42
  import { isMatch } from '../helpers';
37
43
  import { RunnerInfo } from '../core/runner';
@@ -90,18 +96,50 @@ export class Journey {
90
96
  return step;
91
97
  }
92
98
 
99
+ /**
100
+ * @deprecated Since version 1.17.0. Please do not rely on the internal methods.
101
+ * Alias _addStep for backwards compatibility
102
+ */
103
+ addStep(name: string, cb: VoidCallback, location?: Location) {
104
+ this._addStep(name, cb, location);
105
+ }
106
+
93
107
  _addHook(type: HookType, cb: HooksCallback) {
94
108
  this.#hooks[type].push(cb);
95
109
  }
96
110
 
111
+ /**
112
+ * @deprecated Since version 1.17.0. Please do not rely on the internal methods.
113
+ * Alias _addHook for backwards compatibility
114
+ */
115
+ addHook(type: HookType, cb: HooksCallback) {
116
+ this._addHook(type, cb);
117
+ }
118
+
97
119
  _getHook(type: HookType) {
98
120
  return this.#hooks[type];
99
121
  }
100
122
 
123
+ /**
124
+ * @deprecated Since version 1.17.0. Please do not rely on the internal methods.
125
+ * Alias _getHook for backwards compatibility
126
+ */
127
+ getHook(type: HookType) {
128
+ this._getHook(type);
129
+ }
130
+
101
131
  _getMonitor() {
102
132
  return this.#monitor;
103
133
  }
104
134
 
135
+ /**
136
+ * @deprecated Since version 1.17.0. Please do not rely on the internal methods.
137
+ * Alias _getHook for backwards compatibility
138
+ */
139
+ get monitor() {
140
+ return this._getMonitor();
141
+ }
142
+
105
143
  _updateMonitor(config: MonitorConfig) {
106
144
  /**
107
145
  * Use defaults values from journey for monitor object (id, name and tags)
@@ -117,16 +155,40 @@ export class Journey {
117
155
  this.#monitor.setFilter({ match: this.name });
118
156
  }
119
157
 
158
+ /**
159
+ * @deprecated Since version 1.17.0. Please do not rely on the internal methods.
160
+ * Alias _updateMonitor for backwards compatibility
161
+ */
162
+ updateMonitor(config: MonitorConfig) {
163
+ this._updateMonitor(config);
164
+ }
165
+
120
166
  get cb() {
121
167
  return this.#cb;
122
168
  }
123
169
 
170
+ /**
171
+ * @deprecated Since version 1.17.0. Please do not rely on the internal methods.
172
+ * Alias cb for backwards compatibility
173
+ */
174
+ get callback() {
175
+ return this.#cb;
176
+ }
177
+
124
178
  /**
125
179
  * Matches journeys based on the provided args. Proitize tags over match
126
180
  */
127
181
  _isMatch(matchPattern: string, tagsPattern: Array<string>) {
128
182
  return isMatch(this.tags, this.name, tagsPattern, matchPattern);
129
183
  }
184
+
185
+ /**
186
+ * @deprecated Since version 1.17.0. Please do not rely on the internal methods.
187
+ * Alias _isMatch for backwards compatibility
188
+ */
189
+ isMatch(matchPattern: string, tagsPattern: Array<string>) {
190
+ return this._isMatch(matchPattern, tagsPattern);
191
+ }
130
192
  }
131
193
 
132
194
  type JourneyType = (
@@ -158,6 +158,13 @@ export class Monitor {
158
158
  .digest('base64');
159
159
  }
160
160
 
161
+ /**
162
+ * Returns the size of the monitor in bytes which is sent as payload to Kibana
163
+ */
164
+ size() {
165
+ return JSON.stringify(this).length;
166
+ }
167
+
161
168
  validate() {
162
169
  const schedule = this.config.schedule;
163
170
  if (ALLOWED_SCHEDULES.includes(schedule)) {
package/src/dsl/step.ts CHANGED
@@ -54,6 +54,14 @@ export class Step {
54
54
  get cb() {
55
55
  return this.#cb;
56
56
  }
57
+
58
+ /**
59
+ * @deprecated Since version 1.17.0. Please do not rely on the internal methods.
60
+ * Alias cb for backwards compatibility
61
+ */
62
+ get callback() {
63
+ return this.#cb;
64
+ }
57
65
  }
58
66
 
59
67
  type StepType = (name: string, callback: VoidCallback) => Step;
@@ -199,7 +199,9 @@ export class SyntheticsGenerator extends JavaScriptLanguageGenerator {
199
199
  const offset = this.isProject ? 2 + stepIndent : 0 + stepIndent;
200
200
  const formatter = new JavaScriptFormatter(offset);
201
201
 
202
- const locators = actionInContext.frame.framePath.map(selector => `.${super._asLocator(selector)}.contentFrame()`);
202
+ const locators = actionInContext.frame.framePath.map(
203
+ selector => `.${super._asLocator(selector)}.contentFrame()`
204
+ );
203
205
  const subject = `${pageAlias}${locators.join('')}`;
204
206
  const signals = toSignalMap(action);
205
207
 
package/src/helpers.ts CHANGED
@@ -41,7 +41,7 @@ import micromatch from 'micromatch';
41
41
 
42
42
  const SEPARATOR = '\n';
43
43
 
44
- export function noop() { }
44
+ export function noop() {}
45
45
 
46
46
  export function indent(lines: string, tab = ' ') {
47
47
  return lines.replace(/^/gm, tab);
@@ -152,8 +152,8 @@ export function findPkgJsonByTraversing(resolvePath, cwd) {
152
152
  if (resolvePath === parentDirectory) {
153
153
  throw red(
154
154
  `Could not find package.json file in: "${cwd}"\n` +
155
- `It is recommended to run the agent in an NPM project.\n` +
156
- `You can create one by running "npm init -y" in the project folder.`
155
+ `It is recommended to run the agent in an NPM project.\n` +
156
+ `You can create one by running "npm init -y" in the project folder.`
157
157
  );
158
158
  }
159
159
  return findPkgJsonByTraversing(parentDirectory, cwd);
package/src/loader.ts CHANGED
@@ -29,7 +29,7 @@ import { CliArgs } from './common_types';
29
29
  import { step, journey } from './core';
30
30
  import { log } from './core/logger';
31
31
  import { expect } from './core/expect';
32
- import * as mfa from "./core/mfa";
32
+ import * as mfa from './core/mfa';
33
33
  import {
34
34
  isDepInstalled,
35
35
  isDirectory,
@@ -38,7 +38,7 @@ export type TraceOptions = {
38
38
  * https://chromedevtools.github.io/devtools-protocol/tot/Tracing/
39
39
  */
40
40
  export class Tracing {
41
- constructor(private driver: Driver, private options: TraceOptions) { }
41
+ constructor(private driver: Driver, private options: TraceOptions) {}
42
42
 
43
43
  async start() {
44
44
  log(`Plugins: started collecting trace events`);
@@ -24,25 +24,19 @@
24
24
  */
25
25
 
26
26
  import path from 'path';
27
- import { stat, unlink, readFile } from 'fs/promises';
27
+ import { unlink, readFile } from 'fs/promises';
28
28
  import { createWriteStream } from 'fs';
29
29
  import * as esbuild from 'esbuild';
30
30
  import archiver from 'archiver';
31
31
  import { commonOptions } from '../core/transform';
32
32
  import { SyntheticsBundlePlugin } from './plugin';
33
33
 
34
- // 1500KB Max Gzipped limit for bundled code to be pushed as Kibana project monitors.
35
- const SIZE_LIMIT_KB = 1500;
36
-
37
34
  function relativeToCwd(entry: string) {
38
35
  return path.relative(process.cwd(), entry);
39
36
  }
40
37
 
41
38
  export class Bundler {
42
- moduleMap = new Map<string, string>();
43
- constructor() {}
44
-
45
- async prepare(absPath: string) {
39
+ async bundle(absPath: string) {
46
40
  const options: esbuild.BuildOptions = {
47
41
  ...commonOptions(),
48
42
  ...{
@@ -59,56 +53,42 @@ export class Bundler {
59
53
  if (result.errors.length > 0) {
60
54
  throw result.errors;
61
55
  }
62
- this.moduleMap.set(absPath, result.outputFiles[0].text);
56
+ return result.outputFiles[0].text;
63
57
  }
64
58
 
65
- async zip(outputPath: string) {
59
+ async zip(source: string, code: string, dest: string) {
66
60
  return new Promise((fulfill, reject) => {
67
- const output = createWriteStream(outputPath);
61
+ const output = createWriteStream(dest);
68
62
  const archive = archiver('zip', {
69
63
  zlib: { level: 9 },
70
64
  });
71
65
  archive.on('error', reject);
72
66
  output.on('close', fulfill);
73
67
  archive.pipe(output);
74
- for (const [path, content] of this.moduleMap.entries()) {
75
- const relativePath = relativeToCwd(path);
76
- // Date is fixed to Unix epoch so the file metadata is
77
- // not modified everytime when files are bundled
78
- archive.append(content, {
79
- name: relativePath,
80
- date: new Date('1970-01-01'),
81
- });
82
- }
68
+ const relativePath = relativeToCwd(source);
69
+ // Date is fixed to Unix epoch so the file metadata is
70
+ // not modified everytime when files are bundled
71
+ archive.append(code, {
72
+ name: relativePath,
73
+ date: new Date('1970-01-01'),
74
+ });
83
75
  archive.finalize();
84
76
  });
85
77
  }
86
78
 
87
79
  async build(entry: string, output: string) {
88
- await this.prepare(entry);
89
- await this.zip(output);
90
- const data = await this.encode(output);
91
- await this.checkSize(output);
80
+ const code = await this.bundle(entry);
81
+ await this.zip(entry, code, output);
82
+ const content = await this.encode(output);
92
83
  await this.cleanup(output);
93
- return data;
84
+ return content;
94
85
  }
95
86
 
96
87
  async encode(outputPath: string) {
97
88
  return await readFile(outputPath, 'base64');
98
89
  }
99
90
 
100
- async checkSize(outputPath: string) {
101
- const { size } = await stat(outputPath);
102
- const sizeKb = size / 1024;
103
- if (sizeKb > SIZE_LIMIT_KB) {
104
- throw new Error(
105
- `Bundled monitor code exceeds the recommended ${SIZE_LIMIT_KB}KB limit. Please check your dependencies and try again.`
106
- );
107
- }
108
- }
109
-
110
91
  async cleanup(outputPath: string) {
111
- this.moduleMap = new Map<string, string>();
112
92
  await unlink(outputPath);
113
93
  }
114
94
  }