@elastic/synthetics 1.0.0-beta.23 → 1.0.0-beta.26

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 (131) hide show
  1. package/README.md +1 -1
  2. package/dist/cli.js +42 -5
  3. package/dist/cli.js.map +1 -1
  4. package/dist/common_types.d.ts +62 -14
  5. package/dist/common_types.d.ts.map +1 -1
  6. package/dist/core/gatherer.d.ts +2 -2
  7. package/dist/core/gatherer.d.ts.map +1 -1
  8. package/dist/core/gatherer.js +14 -5
  9. package/dist/core/gatherer.js.map +1 -1
  10. package/dist/core/index.d.ts +4 -0
  11. package/dist/core/index.d.ts.map +1 -1
  12. package/dist/core/index.js +15 -1
  13. package/dist/core/index.js.map +1 -1
  14. package/dist/core/runner.d.ts +10 -58
  15. package/dist/core/runner.d.ts.map +1 -1
  16. package/dist/core/runner.js +89 -50
  17. package/dist/core/runner.js.map +1 -1
  18. package/dist/dsl/journey.d.ts +3 -0
  19. package/dist/dsl/journey.d.ts.map +1 -1
  20. package/dist/dsl/journey.js +15 -0
  21. package/dist/dsl/journey.js.map +1 -1
  22. package/dist/dsl/monitor.d.ts +64 -0
  23. package/dist/dsl/monitor.d.ts.map +1 -0
  24. package/dist/dsl/monitor.js +62 -0
  25. package/dist/dsl/monitor.js.map +1 -0
  26. package/dist/formatter/javascript.d.ts +1 -1
  27. package/dist/formatter/javascript.d.ts.map +1 -1
  28. package/dist/formatter/javascript.js +1 -1
  29. package/dist/formatter/javascript.js.map +1 -1
  30. package/dist/generator/index.d.ts +13 -0
  31. package/dist/generator/index.d.ts.map +1 -0
  32. package/dist/generator/index.js +123 -0
  33. package/dist/generator/index.js.map +1 -0
  34. package/dist/{reporters/reporter.js → generator/utils.d.ts} +3 -3
  35. package/dist/generator/utils.d.ts.map +1 -0
  36. package/dist/generator/utils.js +44 -0
  37. package/dist/generator/utils.js.map +1 -0
  38. package/dist/helpers.d.ts +12 -6
  39. package/dist/helpers.d.ts.map +1 -1
  40. package/dist/helpers.js +33 -43
  41. package/dist/helpers.js.map +1 -1
  42. package/dist/index.d.ts +3 -9
  43. package/dist/index.d.ts.map +1 -1
  44. package/dist/index.js +4 -5
  45. package/dist/index.js.map +1 -1
  46. package/dist/loader.js +4 -4
  47. package/dist/loader.js.map +1 -1
  48. package/dist/options.d.ts +12 -0
  49. package/dist/options.d.ts.map +1 -1
  50. package/dist/options.js +66 -4
  51. package/dist/options.js.map +1 -1
  52. package/dist/plugins/network.d.ts +17 -30
  53. package/dist/plugins/network.d.ts.map +1 -1
  54. package/dist/plugins/network.js +179 -244
  55. package/dist/plugins/network.js.map +1 -1
  56. package/dist/plugins/performance.d.ts +1 -16
  57. package/dist/plugins/performance.d.ts.map +1 -1
  58. package/dist/plugins/performance.js.map +1 -1
  59. package/dist/plugins/plugin-manager.d.ts +2 -2
  60. package/dist/plugins/plugin-manager.d.ts.map +1 -1
  61. package/dist/plugins/plugin-manager.js +2 -2
  62. package/dist/plugins/plugin-manager.js.map +1 -1
  63. package/dist/push/bundler.d.ts +34 -0
  64. package/dist/push/bundler.d.ts.map +1 -0
  65. package/dist/push/bundler.js +119 -0
  66. package/dist/push/bundler.js.map +1 -0
  67. package/{src/reporters/reporter.ts → dist/push/index.d.ts} +4 -11
  68. package/dist/push/index.d.ts.map +1 -0
  69. package/dist/push/index.js +58 -0
  70. package/dist/push/index.js.map +1 -0
  71. package/dist/{reporters/reporter.d.ts → push/monitor.d.ts} +7 -8
  72. package/dist/push/monitor.d.ts.map +1 -0
  73. package/dist/push/monitor.js +67 -0
  74. package/dist/push/monitor.js.map +1 -0
  75. package/dist/push/plugin.d.ts +33 -0
  76. package/dist/push/plugin.d.ts.map +1 -0
  77. package/dist/push/plugin.js +123 -0
  78. package/dist/push/plugin.js.map +1 -0
  79. package/dist/push/request.d.ts +43 -0
  80. package/dist/push/request.d.ts.map +1 -0
  81. package/dist/push/request.js +95 -0
  82. package/dist/push/request.js.map +1 -0
  83. package/dist/reporters/base.d.ts +14 -6
  84. package/dist/reporters/base.d.ts.map +1 -1
  85. package/dist/reporters/base.js +45 -47
  86. package/dist/reporters/base.js.map +1 -1
  87. package/dist/reporters/index.d.ts +18 -8
  88. package/dist/reporters/index.d.ts.map +1 -1
  89. package/dist/reporters/index.js.map +1 -1
  90. package/dist/reporters/json.d.ts +7 -4
  91. package/dist/reporters/json.d.ts.map +1 -1
  92. package/dist/reporters/json.js +119 -137
  93. package/dist/reporters/json.js.map +1 -1
  94. package/dist/reporters/junit.d.ts +7 -1
  95. package/dist/reporters/junit.d.ts.map +1 -1
  96. package/dist/reporters/junit.js +91 -86
  97. package/dist/reporters/junit.js.map +1 -1
  98. package/dist/tsconfig.tsbuildinfo +1 -1
  99. package/package.json +14 -9
  100. package/src/cli.ts +65 -9
  101. package/src/common_types.ts +72 -14
  102. package/src/core/gatherer.ts +18 -10
  103. package/src/core/index.ts +15 -0
  104. package/src/core/runner.ts +87 -114
  105. package/src/dsl/journey.ts +18 -0
  106. package/src/dsl/monitor.ts +83 -0
  107. package/src/formatter/javascript.ts +1 -1
  108. package/src/generator/index.ts +159 -0
  109. package/src/generator/utils.ts +41 -0
  110. package/src/helpers.ts +36 -52
  111. package/src/index.ts +10 -2
  112. package/src/loader.ts +4 -4
  113. package/src/options.ts +71 -8
  114. package/src/plugins/network.ts +218 -293
  115. package/src/plugins/performance.ts +1 -17
  116. package/src/plugins/plugin-manager.ts +2 -2
  117. package/src/push/bundler.ts +99 -0
  118. package/src/push/index.ts +63 -0
  119. package/src/push/monitor.ts +77 -0
  120. package/src/push/plugin.ts +113 -0
  121. package/src/push/request.ts +123 -0
  122. package/src/reporters/base.ts +57 -56
  123. package/src/reporters/index.ts +26 -3
  124. package/src/reporters/json.ts +154 -162
  125. package/src/reporters/junit.ts +98 -93
  126. package/templates/journeys/example.journey.ts +18 -0
  127. package/templates/synthetics.config.ts +19 -0
  128. package/CHANGELOG.md +0 -339
  129. package/NOTICE.txt +0 -250
  130. package/dist/reporters/reporter.d.ts.map +0 -1
  131. package/dist/reporters/reporter.js.map +0 -1
package/src/helpers.ts CHANGED
@@ -23,7 +23,7 @@
23
23
  *
24
24
  */
25
25
 
26
- import { red, green, yellow, cyan } from 'kleur/colors';
26
+ import { red, green, yellow, cyan, bold } from 'kleur/colors';
27
27
  import os from 'os';
28
28
  import { resolve, join, dirname } from 'path';
29
29
  import fs from 'fs';
@@ -35,6 +35,7 @@ import {
35
35
  HooksCallback,
36
36
  NetworkConditions,
37
37
  Location,
38
+ ThrottlingOptions,
38
39
  } from './common_types';
39
40
 
40
41
  const lstatAsync = promisify(fs.lstat);
@@ -60,6 +61,7 @@ const NO_UTF8_SUPPORT = process.platform === 'win32';
60
61
  export const symbols = {
61
62
  warning: yellow(NO_UTF8_SUPPORT ? '!' : '⚠'),
62
63
  skipped: cyan('-'),
64
+ progress: cyan('>'),
63
65
  succeeded: green(NO_UTF8_SUPPORT ? 'ok' : '✓'),
64
66
  failed: red(NO_UTF8_SUPPORT ? 'x' : '✖'),
65
67
  };
@@ -267,62 +269,27 @@ export function megabitsToBytes(megabytes: number) {
267
269
  return (megabytes * 1024 * 1024) / 8;
268
270
  }
269
271
 
270
- export function bytesToMegabits(bytes: number) {
271
- return (bytes / 1024 / 1024) * 8;
272
- }
273
-
274
- export const DEFAULT_NETWORK_CONDITIONS: NetworkConditions = {
275
- downloadThroughput: megabitsToBytes(5), // Devtools CDP expects format to be in bytes/second
276
- uploadThroughput: megabitsToBytes(3), // Devtools CDP expects format to be in bytes/second
277
- latency: 20, // milliseconds,
278
- offline: false,
272
+ export const DEFAULT_THROTTLING_OPTIONS: ThrottlingOptions = {
273
+ download: 5,
274
+ upload: 3,
275
+ latency: 20,
279
276
  };
280
277
 
281
- // Tranforms CDP dev tools format back to cli args format
282
- export function formatNetworkConditionsArgs(
283
- networkConditions: NetworkConditions
284
- ) {
285
- const d = bytesToMegabits(networkConditions.downloadThroughput);
286
- const u = bytesToMegabits(networkConditions.uploadThroughput);
287
- const l = networkConditions.latency;
288
- return `${d}d/${u}u/${l}l`;
289
- }
290
-
291
- export const DEFAULT_NETWORK_CONDITIONS_ARG = formatNetworkConditionsArgs(
292
- DEFAULT_NETWORK_CONDITIONS
293
- );
294
-
295
- export function parseNetworkConditions(args: string): NetworkConditions {
296
- const uploadToken = 'u';
297
- const downloadToken = 'd';
298
- const latencyToken = 'l';
299
- const networkConditions = {
300
- ...DEFAULT_NETWORK_CONDITIONS,
278
+ /**
279
+ * Transforms the CLI throttling arguments in to format
280
+ * expected by Chrome devtools protocol NetworkConditions
281
+ */
282
+ export function getNetworkConditions(
283
+ throttlingOpts: ThrottlingOptions
284
+ ): NetworkConditions {
285
+ return {
286
+ downloadThroughput: megabitsToBytes(throttlingOpts.download),
287
+ uploadThroughput: megabitsToBytes(throttlingOpts.upload), // Devtools CDP expects format to be in bytes/second
288
+ latency: throttlingOpts.latency, // milliseconds,
289
+ offline: false,
301
290
  };
302
-
303
- const conditions = args.split('/');
304
-
305
- conditions.forEach(condition => {
306
- const value = condition.slice(0, condition.length - 1);
307
- const token = condition.slice(-1);
308
-
309
- switch (token) {
310
- case uploadToken:
311
- networkConditions.uploadThroughput = megabitsToBytes(Number(value));
312
- break;
313
- case downloadToken:
314
- networkConditions.downloadThroughput = megabitsToBytes(Number(value));
315
- break;
316
- case latencyToken:
317
- networkConditions.latency = Number(value);
318
- break;
319
- }
320
- });
321
-
322
- return networkConditions;
323
291
  }
324
292
 
325
- // default stack trace limit
326
293
  const dstackTraceLimit = 10;
327
294
 
328
295
  // Uses the V8 Stacktrace API to get the function location
@@ -354,3 +321,20 @@ export function wrapFnWithLocation<A extends unknown[], R>(
354
321
  return func(location, ...args);
355
322
  };
356
323
  }
324
+
325
+ // Console helpers
326
+ export function write(message: string) {
327
+ process.stderr.write(message + '\n');
328
+ }
329
+
330
+ export function progress(message: string) {
331
+ write(cyan(bold(`${symbols.progress} ${message}`)));
332
+ }
333
+
334
+ export function error(message: string) {
335
+ write(red(message));
336
+ }
337
+
338
+ export function done(message: string) {
339
+ write(bold(green(`${symbols['succeeded']} ${message}`)));
340
+ }
package/src/index.ts CHANGED
@@ -33,7 +33,15 @@ export async function run(options: RunOptions) {
33
33
  /**
34
34
  * Export all core module functions
35
35
  */
36
- export { beforeAll, afterAll, journey, step, before, after } from './core';
36
+ export {
37
+ journey,
38
+ step,
39
+ monitor,
40
+ beforeAll,
41
+ afterAll,
42
+ before,
43
+ after,
44
+ } from './core';
37
45
  export { expect } from './core/expect';
38
46
  /**
39
47
  * Export all the driver related types to be consumed
@@ -59,5 +67,5 @@ export type {
59
67
  Signal,
60
68
  Step,
61
69
  Steps,
70
+ actionTitle,
62
71
  } from './formatter/javascript';
63
- export { actionTitle } from './formatter/javascript';
package/src/loader.ts CHANGED
@@ -81,7 +81,7 @@ export async function loadTestFiles(options: CliArgs, args: string[]) {
81
81
  */
82
82
  const files =
83
83
  args.length > 0 ? args : (await readStdin()).split('\n').filter(Boolean);
84
- const suites = await prepareSuites(files, options);
84
+ const suites = await prepareSuites(files, options.pattern);
85
85
  requireSuites(suites);
86
86
  }
87
87
 
@@ -123,7 +123,7 @@ function requireSuites(suites: Iterable<string>) {
123
123
  * Handle both directory and files that are passed through TTY
124
124
  * and add them to suites
125
125
  */
126
- async function prepareSuites(inputs: string[], cliArgs: CliArgs) {
126
+ async function prepareSuites(inputs: string[], filePattern?: string) {
127
127
  const suites = new Set<string>();
128
128
  const addSuite = absPath => {
129
129
  log(`Processing file: ${absPath}`);
@@ -133,8 +133,8 @@ async function prepareSuites(inputs: string[], cliArgs: CliArgs) {
133
133
  * Match all files inside the directory with the
134
134
  * .journey.{mjs|cjs|js|ts) extensions
135
135
  */
136
- const pattern = cliArgs.pattern
137
- ? new RegExp(cliArgs.pattern, 'i')
136
+ const pattern = filePattern
137
+ ? new RegExp(filePattern, 'i')
138
138
  : /.+\.journey\.([mc]js|[jt]s?)$/;
139
139
  /**
140
140
  * Ignore node_modules by default when running suites
package/src/options.ts CHANGED
@@ -25,8 +25,9 @@
25
25
 
26
26
  import merge from 'deepmerge';
27
27
  import { readConfig } from './config';
28
- import { parseNetworkConditions } from './helpers';
29
- import type { CliArgs, RunOptions } from './common_types';
28
+ import { getNetworkConditions, DEFAULT_THROTTLING_OPTIONS } from './helpers';
29
+ import type { CliArgs, RunOptions, ThrottlingOptions } from './common_types';
30
+ import { MonitorConfig } from './dsl/monitor';
30
31
 
31
32
  /**
32
33
  * Set debug based on DEBUG ENV and -d flags
@@ -91,11 +92,14 @@ export function normalizeOptions(cliArgs: CliArgs): RunOptions {
91
92
  ? readConfig(options.environment, cliArgs.config)
92
93
  : {};
93
94
 
94
- options.params = Object.freeze(merge(config.params, cliArgs.params || {}));
95
-
96
95
  /**
97
- * Favor playwright options passed via cli to inline playwright options
96
+ * Order of preference for options that are used while running are
97
+ * 1. Local options configured via Runner API
98
+ * 2. CLI flags
99
+ * 3. Configuration file
98
100
  */
101
+ options.params = Object.freeze(merge(config.params, cliArgs.params || {}));
102
+
99
103
  options.playwrightOptions = merge.all([
100
104
  config.playwrightOptions || {},
101
105
  cliArgs.playwrightOptions || {},
@@ -106,11 +110,70 @@ export function normalizeOptions(cliArgs: CliArgs): RunOptions {
106
110
  },
107
111
  ]);
108
112
 
113
+ const defaults = getDefaultMonitorConfig();
109
114
  if (cliArgs.throttling) {
110
- options.networkConditions = parseNetworkConditions(
111
- cliArgs.throttling as string
112
- );
115
+ const throttleConfig = merge.all([
116
+ defaults.throttling,
117
+ config.monitor?.throttling || {},
118
+ cliArgs.throttling as ThrottlingOptions,
119
+ ]);
120
+ options.throttling = throttleConfig;
121
+ options.networkConditions = getNetworkConditions(throttleConfig);
122
+ } else {
123
+ /**
124
+ * Do not apply throttling when `--no-throttling` flag is passed
125
+ */
126
+ options.throttling = {};
113
127
  }
114
128
 
129
+ options.locations =
130
+ cliArgs.locations ?? config.monitor?.locations ?? defaults.locations;
131
+
132
+ options.schedule =
133
+ cliArgs.schedule ?? config.monitor?.schedule ?? defaults.schedule;
134
+
115
135
  return options;
116
136
  }
137
+
138
+ /**
139
+ * Get the default monitor configuration for all journeys
140
+ */
141
+ export function getDefaultMonitorConfig(): MonitorConfig {
142
+ return {
143
+ throttling: DEFAULT_THROTTLING_OPTIONS,
144
+ locations: ['US East'],
145
+ schedule: 10,
146
+ };
147
+ }
148
+
149
+ /**
150
+ * Parses the throttling CLI settings and also
151
+ * adapts to the format to keep the backwards compatability
152
+ * - Accepts old format `<5d/3u/20l>`
153
+ * - Processess new format otherwise `{download: 5, upload: 3, latency: 20}`
154
+ */
155
+ export function parseThrottling(value: string, prev?: string) {
156
+ const THROTTLING_REGEX = /([0-9]{1,}u)|([0-9]{1,}d)|([0-9]{1,}l)/gm;
157
+ if (THROTTLING_REGEX.test(value)) {
158
+ const throttling: ThrottlingOptions = {};
159
+ const conditions = value.split('/');
160
+
161
+ conditions.forEach(condition => {
162
+ const setting = condition.slice(0, condition.length - 1);
163
+ const token = condition.slice(-1);
164
+ switch (token) {
165
+ case 'd':
166
+ throttling.download = Number(setting);
167
+ break;
168
+ case 'u':
169
+ throttling.upload = Number(setting);
170
+ break;
171
+ case 'l':
172
+ throttling.latency = Number(setting);
173
+ break;
174
+ }
175
+ });
176
+ return throttling;
177
+ }
178
+ return JSON.parse(value || prev);
179
+ }