@elastic/synthetics 1.0.0-beta.8 → 1.0.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 (220) hide show
  1. package/README.md +5 -4
  2. package/dist/cli.js +139 -165
  3. package/dist/cli.js.map +1 -1
  4. package/dist/common_types.d.ts +158 -34
  5. package/dist/common_types.d.ts.map +1 -1
  6. package/dist/config.d.ts +1 -0
  7. package/dist/config.d.ts.map +1 -1
  8. package/dist/config.js +7 -6
  9. package/dist/config.js.map +1 -1
  10. package/dist/core/browser-service.d.ts +1 -1
  11. package/dist/core/browser-service.d.ts.map +1 -1
  12. package/dist/core/browser-service.js +7 -6
  13. package/dist/core/browser-service.js.map +1 -1
  14. package/dist/core/expect.d.ts +25 -25
  15. package/dist/core/expect.d.ts.map +1 -1
  16. package/dist/core/expect.js.map +1 -1
  17. package/dist/core/gatherer.d.ts +5 -8
  18. package/dist/core/gatherer.d.ts.map +1 -1
  19. package/dist/core/gatherer.js +75 -17
  20. package/dist/core/gatherer.js.map +1 -1
  21. package/dist/core/index.d.ts +5 -1
  22. package/dist/core/index.d.ts.map +1 -1
  23. package/dist/core/index.js +23 -11
  24. package/dist/core/index.js.map +1 -1
  25. package/dist/core/logger.d.ts +0 -1
  26. package/dist/core/logger.d.ts.map +1 -1
  27. package/dist/core/logger.js +10 -17
  28. package/dist/core/logger.js.map +1 -1
  29. package/dist/core/runner.d.ts +12 -63
  30. package/dist/core/runner.d.ts.map +1 -1
  31. package/dist/core/runner.js +159 -92
  32. package/dist/core/runner.js.map +1 -1
  33. package/dist/core/transform.d.ts +37 -0
  34. package/dist/core/transform.d.ts.map +1 -0
  35. package/dist/core/transform.js +148 -0
  36. package/dist/core/transform.js.map +1 -0
  37. package/dist/dsl/index.js +5 -1
  38. package/dist/dsl/index.js.map +1 -1
  39. package/dist/dsl/journey.d.ts +9 -7
  40. package/dist/dsl/journey.d.ts.map +1 -1
  41. package/dist/dsl/journey.js +32 -39
  42. package/dist/dsl/journey.js.map +1 -1
  43. package/dist/dsl/monitor.d.ts +93 -0
  44. package/dist/dsl/monitor.d.ts.map +1 -0
  45. package/dist/dsl/monitor.js +110 -0
  46. package/dist/dsl/monitor.js.map +1 -0
  47. package/dist/dsl/step.d.ts +3 -2
  48. package/dist/dsl/step.d.ts.map +1 -1
  49. package/dist/dsl/step.js +6 -1
  50. package/dist/dsl/step.js.map +1 -1
  51. package/dist/formatter/javascript.d.ts +115 -0
  52. package/dist/formatter/javascript.d.ts.map +1 -0
  53. package/dist/formatter/javascript.js +331 -0
  54. package/dist/formatter/javascript.js.map +1 -0
  55. package/dist/generator/index.d.ts +24 -0
  56. package/dist/generator/index.d.ts.map +1 -0
  57. package/dist/generator/index.js +241 -0
  58. package/dist/generator/index.js.map +1 -0
  59. package/dist/{reporters/reporter.js → generator/utils.d.ts} +5 -3
  60. package/dist/generator/utils.d.ts.map +1 -0
  61. package/dist/generator/utils.js +84 -0
  62. package/dist/generator/utils.js.map +1 -0
  63. package/dist/helpers.d.ts +36 -9
  64. package/dist/helpers.d.ts.map +1 -1
  65. package/dist/helpers.js +170 -24
  66. package/dist/helpers.js.map +1 -1
  67. package/dist/index.d.ts +5 -7
  68. package/dist/index.d.ts.map +1 -1
  69. package/dist/index.js +5 -26
  70. package/dist/index.js.map +1 -1
  71. package/dist/loader.d.ts +34 -0
  72. package/dist/loader.d.ts.map +1 -0
  73. package/dist/loader.js +153 -0
  74. package/dist/loader.js.map +1 -0
  75. package/dist/locations/index.d.ts +45 -0
  76. package/dist/locations/index.d.ts.map +1 -0
  77. package/dist/locations/index.js +83 -0
  78. package/dist/locations/index.js.map +1 -0
  79. package/dist/{reporters/reporter.d.ts → locations/public-locations.d.ts} +12 -8
  80. package/dist/locations/public-locations.d.ts.map +1 -0
  81. package/dist/locations/public-locations.js +41 -0
  82. package/dist/locations/public-locations.js.map +1 -0
  83. package/dist/options.d.ts +42 -0
  84. package/dist/options.d.ts.map +1 -0
  85. package/dist/options.js +146 -0
  86. package/dist/options.js.map +1 -0
  87. package/dist/plugins/browser-console.d.ts +5 -4
  88. package/dist/plugins/browser-console.d.ts.map +1 -1
  89. package/dist/plugins/browser-console.js +47 -24
  90. package/dist/plugins/browser-console.js.map +1 -1
  91. package/dist/plugins/index.js +5 -1
  92. package/dist/plugins/index.js.map +1 -1
  93. package/dist/plugins/network.d.ts +24 -31
  94. package/dist/plugins/network.d.ts.map +1 -1
  95. package/dist/plugins/network.js +226 -229
  96. package/dist/plugins/network.js.map +1 -1
  97. package/dist/plugins/performance.d.ts +4 -19
  98. package/dist/plugins/performance.d.ts.map +1 -1
  99. package/dist/plugins/performance.js +6 -5
  100. package/dist/plugins/performance.js.map +1 -1
  101. package/dist/plugins/plugin-manager.d.ts +9 -5
  102. package/dist/plugins/plugin-manager.d.ts.map +1 -1
  103. package/dist/plugins/plugin-manager.js +46 -30
  104. package/dist/plugins/plugin-manager.js.map +1 -1
  105. package/dist/plugins/tracing.d.ts +6 -6
  106. package/dist/plugins/tracing.d.ts.map +1 -1
  107. package/dist/plugins/tracing.js +13 -7
  108. package/dist/plugins/tracing.js.map +1 -1
  109. package/dist/push/bundler.d.ts +35 -0
  110. package/dist/push/bundler.d.ts.map +1 -0
  111. package/dist/push/bundler.js +131 -0
  112. package/dist/push/bundler.js.map +1 -0
  113. package/dist/push/index.d.ts +10 -0
  114. package/dist/push/index.d.ts.map +1 -0
  115. package/dist/push/index.js +235 -0
  116. package/dist/push/index.js.map +1 -0
  117. package/dist/push/kibana_api.d.ts +56 -0
  118. package/dist/push/kibana_api.d.ts.map +1 -0
  119. package/dist/push/kibana_api.js +135 -0
  120. package/dist/push/kibana_api.js.map +1 -0
  121. package/dist/push/monitor.d.ts +55 -0
  122. package/dist/push/monitor.d.ts.map +1 -0
  123. package/dist/push/monitor.js +268 -0
  124. package/dist/push/monitor.js.map +1 -0
  125. package/dist/{parse_args.d.ts → push/plugin.d.ts} +9 -6
  126. package/dist/push/plugin.d.ts.map +1 -0
  127. package/dist/push/plugin.js +66 -0
  128. package/dist/push/plugin.js.map +1 -0
  129. package/dist/push/request.d.ts +45 -0
  130. package/dist/push/request.d.ts.map +1 -0
  131. package/dist/push/request.js +109 -0
  132. package/dist/push/request.js.map +1 -0
  133. package/dist/push/utils.d.ts +31 -0
  134. package/dist/push/utils.d.ts.map +1 -0
  135. package/dist/push/utils.js +64 -0
  136. package/dist/push/utils.js.map +1 -0
  137. package/dist/reporters/base.d.ts +14 -6
  138. package/dist/reporters/base.d.ts.map +1 -1
  139. package/dist/reporters/base.js +58 -50
  140. package/dist/reporters/base.js.map +1 -1
  141. package/dist/reporters/index.d.ts +18 -8
  142. package/dist/reporters/index.d.ts.map +1 -1
  143. package/dist/reporters/index.js.map +1 -1
  144. package/dist/reporters/json.d.ts +17 -62
  145. package/dist/reporters/json.d.ts.map +1 -1
  146. package/dist/reporters/json.js +147 -177
  147. package/dist/reporters/json.js.map +1 -1
  148. package/dist/reporters/junit.d.ts +7 -1
  149. package/dist/reporters/junit.d.ts.map +1 -1
  150. package/dist/reporters/junit.js +90 -95
  151. package/dist/reporters/junit.js.map +1 -1
  152. package/dist/sdk/lh-trace-processor.d.ts +35 -9
  153. package/dist/sdk/lh-trace-processor.d.ts.map +1 -1
  154. package/dist/sdk/lh-trace-processor.js +114 -53
  155. package/dist/sdk/lh-trace-processor.js.map +1 -1
  156. package/dist/sdk/trace-metrics.d.ts +4 -4
  157. package/dist/sdk/trace-metrics.d.ts.map +1 -1
  158. package/dist/sdk/trace-metrics.js +3 -4
  159. package/dist/sdk/trace-metrics.js.map +1 -1
  160. package/dist/sdk/trace-processor.d.ts +11 -3
  161. package/dist/sdk/trace-processor.d.ts.map +1 -1
  162. package/dist/sdk/trace-processor.js +17 -9
  163. package/dist/sdk/trace-processor.js.map +1 -1
  164. package/package.json +38 -30
  165. package/src/cli.ts +223 -158
  166. package/src/common_types.ts +191 -34
  167. package/src/config.ts +1 -1
  168. package/src/core/expect.ts +58 -24
  169. package/src/core/gatherer.ts +92 -25
  170. package/src/core/index.ts +36 -15
  171. package/src/core/logger.ts +8 -12
  172. package/src/core/runner.ts +158 -148
  173. package/src/core/transform.ts +160 -0
  174. package/src/dsl/journey.ts +41 -21
  175. package/src/dsl/monitor.ts +152 -0
  176. package/src/dsl/step.ts +9 -2
  177. package/src/formatter/javascript.ts +414 -0
  178. package/src/generator/index.ts +308 -0
  179. package/src/generator/utils.ts +84 -0
  180. package/src/helpers.ts +182 -16
  181. package/src/index.ts +21 -22
  182. package/src/loader.ts +171 -0
  183. package/src/locations/index.ts +95 -0
  184. package/src/{reporters/reporter.ts → locations/public-locations.ts} +12 -9
  185. package/src/options.ts +175 -0
  186. package/src/plugins/browser-console.ts +33 -8
  187. package/src/plugins/network.ts +266 -284
  188. package/src/plugins/performance.ts +6 -22
  189. package/src/plugins/plugin-manager.ts +49 -31
  190. package/src/plugins/tracing.ts +11 -9
  191. package/src/push/bundler.ts +112 -0
  192. package/src/push/index.ts +291 -0
  193. package/src/push/kibana_api.ts +191 -0
  194. package/src/push/monitor.ts +307 -0
  195. package/src/push/plugin.ts +66 -0
  196. package/src/push/request.ts +141 -0
  197. package/src/push/utils.ts +77 -0
  198. package/src/reporters/base.ts +63 -52
  199. package/src/reporters/index.ts +26 -3
  200. package/src/reporters/json.ts +181 -201
  201. package/src/reporters/junit.ts +98 -93
  202. package/src/sdk/lh-trace-processor.ts +132 -68
  203. package/src/sdk/trace-metrics.ts +8 -4
  204. package/src/sdk/trace-processor.ts +28 -13
  205. package/templates/.github/workflows/run-synthetics.yml +27 -0
  206. package/templates/README.md +21 -0
  207. package/templates/journeys/advanced-example-helpers.ts +54 -0
  208. package/templates/journeys/advanced-example.journey.ts +43 -0
  209. package/templates/journeys/example.journey.ts +18 -0
  210. package/templates/lightweight/heartbeat.yml +9 -0
  211. package/templates/synthetics.config.ts +35 -0
  212. package/CHANGELOG.md +0 -181
  213. package/NOTICE.txt +0 -221
  214. package/dist/parse_args.d.ts.map +0 -1
  215. package/dist/parse_args.js +0 -98
  216. package/dist/parse_args.js.map +0 -1
  217. package/dist/reporters/reporter.d.ts.map +0 -1
  218. package/dist/reporters/reporter.js.map +0 -1
  219. package/dist/tsconfig.tsbuildinfo +0 -1895
  220. package/src/parse_args.ts +0 -146
@@ -0,0 +1,77 @@
1
+ /**
2
+ * MIT License
3
+ *
4
+ * Copyright (c) 2020-present, Elastic NV
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ * THE SOFTWARE.
23
+ *
24
+ */
25
+
26
+ import { progress, removeTrailingSlash } from '../helpers';
27
+ import { green, red, grey, yellow } from 'kleur/colors';
28
+ import { PushOptions } from '../common_types';
29
+
30
+ export function logDiff<T extends Set<string>>(
31
+ newIDs: T,
32
+ changedIDs: T,
33
+ removedIDs: T,
34
+ unchangedIDs: T
35
+ ) {
36
+ progress(
37
+ 'Monitor Diff: ' +
38
+ green(`Added(${newIDs.size}) `) +
39
+ yellow(`Updated(${changedIDs.size}) `) +
40
+ red(`Removed(${removedIDs.size}) `) +
41
+ grey(`Unchanged(${unchangedIDs.size})`)
42
+ );
43
+ }
44
+
45
+ export function getChunks(arr: any[], size: number) {
46
+ const chunks = [];
47
+ for (let i = 0; i < arr.length; i += size) {
48
+ chunks.push(arr.slice(i, i + size));
49
+ }
50
+ return chunks;
51
+ }
52
+
53
+ type Operation =
54
+ | 'status'
55
+ | 'bulk_get'
56
+ | 'bulk_update'
57
+ | 'bulk_delete'
58
+ | 'legacy'
59
+ | 'location';
60
+
61
+ export function generateURL(options: PushOptions, operation: Operation) {
62
+ const url = removeTrailingSlash(options.url);
63
+ switch (operation) {
64
+ case 'status':
65
+ return `${url}/s/${options.space}/api/status`;
66
+ case 'bulk_get':
67
+ case 'bulk_update':
68
+ case 'bulk_delete':
69
+ return `${url}/s/${options.space}/api/synthetics/project/${options.id}/monitors`;
70
+ case 'legacy':
71
+ return `${url}/s/${options.space}/api/synthetics/service/project/monitors`;
72
+ case 'location':
73
+ return `${url}/internal/uptime/service/locations`;
74
+ default:
75
+ throw new Error('Invalid operation');
76
+ }
77
+ }
@@ -25,7 +25,6 @@
25
25
 
26
26
  import SonicBoom from 'sonic-boom';
27
27
  import { green, red, cyan } from 'kleur/colors';
28
- import Runner from '../core/runner';
29
28
  import {
30
29
  symbols,
31
30
  indent,
@@ -33,7 +32,13 @@ import {
33
32
  findPWLogsIndexes,
34
33
  rewriteErrorStack,
35
34
  } from '../helpers';
36
- import { ReporterOptions } from './reporter';
35
+ import { Reporter, ReporterOptions } from '.';
36
+ import {
37
+ JourneyEndResult,
38
+ JourneyStartResult,
39
+ StepEndResult,
40
+ } from '../common_types';
41
+ import { Journey, Step } from '../dsl';
37
42
 
38
43
  function renderError(error) {
39
44
  let output = '';
@@ -58,68 +63,74 @@ function renderDuration(durationMs) {
58
63
  return parseInt(durationMs);
59
64
  }
60
65
 
61
- export default class BaseReporter {
66
+ export default class BaseReporter implements Reporter {
62
67
  stream: SonicBoom;
63
68
  fd: number;
69
+ metrics = {
70
+ succeeded: 0,
71
+ failed: 0,
72
+ skipped: 0,
73
+ };
64
74
 
65
- constructor(public runner: Runner, options: ReporterOptions = {}) {
75
+ constructor(options: ReporterOptions = {}) {
66
76
  this.fd = options.fd || process.stdout.fd;
67
- this.stream = new SonicBoom({ fd: this.fd, sync: true });
68
- this._registerListeners();
69
- this.runner.on('end', () => this.stream.flush());
77
+ /**
78
+ * minLength is set to 1 byte to make sure we flush the
79
+ * content even if its the last byte on the stream buffer
80
+ * before destroying the pipe with underlying file descriptor
81
+ */
82
+ this.stream = new SonicBoom({ fd: this.fd, sync: true, minLength: 1 });
70
83
  }
71
84
 
72
- _registerListeners() {
73
- const result = {
74
- succeeded: 0,
75
- failed: 0,
76
- skipped: 0,
77
- };
78
-
79
- this.runner.on('journey:start', ({ journey }) => {
80
- this.write(`\nJourney: ${journey.name}`);
81
- });
82
-
83
- this.runner.on('step:end', ({ step, start, end, error, status }) => {
84
- const message = `${symbols[status]} Step: '${
85
- step.name
86
- }' ${status} (${renderDuration((end - start) * 1000)} ms)`;
87
- this.write(indent(message));
88
- error && this.write(renderError(error));
89
- result[status]++;
90
- });
91
-
92
- this.runner.on('journey:end', ({ error }) => {
93
- const { failed, succeeded, skipped } = result;
94
- const total = failed + succeeded + skipped;
85
+ onJourneyStart(journey: Journey, {}: JourneyStartResult) {
86
+ this.write(`\nJourney: ${journey.name}`);
87
+ }
95
88
 
96
- /**
97
- * Render the error on the terminal only when no steps could
98
- * be executed which means the error happened in one of the hooks
99
- */
100
- if (total === 0 && error) {
101
- this.write(renderError(error));
102
- }
103
- });
89
+ onStepEnd(_: Journey, step: Step, result: StepEndResult) {
90
+ const { status, end, start, error } = result;
91
+ const message = `${symbols[status]} Step: '${
92
+ step.name
93
+ }' ${status} (${renderDuration((end - start) * 1000)} ms)`;
94
+ this.write(indent(message));
95
+ error && this.write(renderError(error));
96
+ this.metrics[status]++;
97
+ }
104
98
 
105
- this.runner.on('end', () => {
106
- const { failed, succeeded, skipped } = result;
107
- const total = failed + succeeded + skipped;
99
+ /* eslint-disable @typescript-eslint/no-unused-vars */
100
+ onJourneyEnd(_: Journey, { error }: JourneyEndResult) {
101
+ const { failed, succeeded, skipped } = this.metrics;
102
+ const total = failed + succeeded + skipped;
103
+ /**
104
+ * Render the error on the terminal only when no steps could
105
+ * be executed which means the error happened in one of the hooks
106
+ */
107
+ if (total === 0 && error) {
108
+ this.write(renderError(error));
109
+ }
110
+ }
108
111
 
109
- let message = '\n';
110
- if (total === 0) {
111
- message = 'No tests found!';
112
- message += ` (${renderDuration(now())} ms) \n`;
113
- this.write(message);
114
- return;
115
- }
112
+ onEnd() {
113
+ const { failed, succeeded, skipped } = this.metrics;
114
+ const total = failed + succeeded + skipped;
116
115
 
117
- message += succeeded > 0 ? green(` ${succeeded} passed`) : '';
118
- message += failed > 0 ? red(` ${failed} failed`) : '';
119
- message += skipped > 0 ? cyan(` ${skipped} skipped`) : '';
116
+ let message = '\n';
117
+ if (total === 0) {
118
+ message = 'No tests found!';
120
119
  message += ` (${renderDuration(now())} ms) \n`;
121
120
  this.write(message);
122
- });
121
+ return;
122
+ }
123
+
124
+ message += succeeded > 0 ? green(` ${succeeded} passed`) : '';
125
+ message += failed > 0 ? red(` ${failed} failed`) : '';
126
+ message += skipped > 0 ? cyan(` ${skipped} skipped`) : '';
127
+ message += ` (${renderDuration(now())} ms) \n`;
128
+ this.write(message);
129
+
130
+ // flushSync is used here to make sure all the data from the underlying
131
+ // SonicBoom stream buffer is completely written to the fd before closing
132
+ // the process
133
+ this.stream.flushSync();
123
134
  }
124
135
 
125
136
  write(message) {
@@ -26,11 +26,34 @@
26
26
  import BaseReporter from './base';
27
27
  import JSONReporter from './json';
28
28
  import JUnitReporter from './junit';
29
- import Reporter, { ReporterOptions } from './reporter';
29
+ import { Journey, Step } from '../dsl';
30
+ import {
31
+ StartEvent,
32
+ JourneyEndResult,
33
+ JourneyStartResult,
34
+ StepEndResult,
35
+ } from '../common_types';
30
36
 
31
- export { Reporter, ReporterOptions };
32
- export const reporters = {
37
+ export type ReporterOptions = { fd?: number; colors?: boolean };
38
+ export type BuiltInReporterName = 'default' | 'json' | 'junit';
39
+ export type ReporterInstance = new (opts: ReporterOptions) => Reporter;
40
+ export const reporters: {
41
+ [key in BuiltInReporterName]: ReporterInstance;
42
+ } = {
33
43
  default: BaseReporter,
34
44
  json: JSONReporter,
35
45
  junit: JUnitReporter,
36
46
  };
47
+
48
+ export interface Reporter {
49
+ onStart?(params: StartEvent): void;
50
+ onJourneyRegister?(journey: Journey): void;
51
+ onJourneyStart?(journey: Journey, result: JourneyStartResult): void;
52
+ onStepStart?(journey: Journey, step: Step): void;
53
+ onStepEnd?(journey: Journey, step: Step, result: StepEndResult): void;
54
+ onJourneyEnd?(
55
+ journey: Journey,
56
+ result: JourneyEndResult
57
+ ): void | Promise<void>;
58
+ onEnd?(): void | Promise<void>;
59
+ }