@elastic/synthetics 1.5.3 → 1.7.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 (62) hide show
  1. package/dist/bundles/lib/index.js +186 -192
  2. package/dist/common_types.d.ts +1 -0
  3. package/dist/common_types.d.ts.map +1 -1
  4. package/dist/core/index.d.ts +4 -4
  5. package/dist/core/index.d.ts.map +1 -1
  6. package/dist/core/index.js +17 -3
  7. package/dist/core/index.js.map +1 -1
  8. package/dist/core/runner.d.ts.map +1 -1
  9. package/dist/core/runner.js +23 -3
  10. package/dist/core/runner.js.map +1 -1
  11. package/dist/core/transform.d.ts +2 -18
  12. package/dist/core/transform.d.ts.map +1 -1
  13. package/dist/core/transform.js +0 -3
  14. package/dist/core/transform.js.map +1 -1
  15. package/dist/dsl/journey.d.ts +13 -0
  16. package/dist/dsl/journey.d.ts.map +1 -1
  17. package/dist/dsl/journey.js +2 -0
  18. package/dist/dsl/journey.js.map +1 -1
  19. package/dist/dsl/step.d.ts +19 -0
  20. package/dist/dsl/step.d.ts.map +1 -1
  21. package/dist/dsl/step.js +3 -0
  22. package/dist/dsl/step.js.map +1 -1
  23. package/dist/formatter/javascript.d.ts.map +1 -1
  24. package/dist/formatter/javascript.js +2 -11
  25. package/dist/formatter/javascript.js.map +1 -1
  26. package/dist/helpers.js +1 -1
  27. package/dist/helpers.js.map +1 -1
  28. package/dist/index.d.ts +2 -1
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/push/bundler.d.ts.map +1 -1
  31. package/dist/push/bundler.js +4 -2
  32. package/dist/push/bundler.js.map +1 -1
  33. package/dist/push/request.d.ts.map +1 -1
  34. package/dist/push/request.js +1 -0
  35. package/dist/push/request.js.map +1 -1
  36. package/dist/reporters/base.d.ts +1 -0
  37. package/dist/reporters/base.d.ts.map +1 -1
  38. package/dist/reporters/base.js +2 -0
  39. package/dist/reporters/base.js.map +1 -1
  40. package/dist/reporters/build_kite_cli.d.ts +39 -0
  41. package/dist/reporters/build_kite_cli.d.ts.map +1 -0
  42. package/dist/reporters/build_kite_cli.js +111 -0
  43. package/dist/reporters/build_kite_cli.js.map +1 -0
  44. package/dist/reporters/index.d.ts +1 -1
  45. package/dist/reporters/index.d.ts.map +1 -1
  46. package/dist/reporters/index.js +2 -0
  47. package/dist/reporters/index.js.map +1 -1
  48. package/package.json +8 -5
  49. package/src/common_types.ts +1 -0
  50. package/src/core/index.ts +47 -21
  51. package/src/core/runner.ts +28 -3
  52. package/src/core/transform.ts +0 -3
  53. package/src/dsl/journey.ts +18 -0
  54. package/src/dsl/step.ts +20 -0
  55. package/src/formatter/javascript.ts +2 -11
  56. package/src/helpers.ts +1 -1
  57. package/src/index.ts +17 -1
  58. package/src/push/bundler.ts +4 -2
  59. package/src/push/request.ts +1 -0
  60. package/src/reporters/base.ts +1 -1
  61. package/src/reporters/build_kite_cli.ts +111 -0
  62. package/src/reporters/index.ts +7 -1
@@ -101,23 +101,15 @@ function toAssertCall(pageAlias: string, action: Action) {
101
101
  }
102
102
 
103
103
  function toSignalMap(action: Action) {
104
- let waitForNavigation: Signal | undefined;
105
- let assertNavigation: Signal | undefined;
106
104
  let popup: Signal | undefined;
107
105
  let download: Signal | undefined;
108
106
  let dialog: Signal | undefined;
109
107
  for (const signal of action.signals) {
110
- if (signal.name === 'navigation' && signal.isAsync)
111
- waitForNavigation = signal;
112
- else if (signal.name === 'navigation' && !signal.isAsync)
113
- assertNavigation = signal;
114
- else if (signal.name === 'popup') popup = signal;
108
+ if (signal.name === 'popup') popup = signal;
115
109
  else if (signal.name === 'download') download = signal;
116
110
  else if (signal.name === 'dialog') dialog = signal;
117
111
  }
118
112
  return {
119
- waitForNavigation,
120
- assertNavigation,
121
113
  popup,
122
114
  download,
123
115
  dialog,
@@ -280,8 +272,7 @@ export class SyntheticsGenerator extends JavaScriptLanguageGenerator {
280
272
  if (isAssert && action.command) {
281
273
  formatter.add(toAssertCall(pageAlias, action));
282
274
  } else {
283
- const actionCall = super._generateActionCall(action);
284
- formatter.add(`await ${subject}.${actionCall};`);
275
+ formatter.add(super._generateActionCall(subject, action));
285
276
  }
286
277
 
287
278
  if (signals.popup)
package/src/helpers.ts CHANGED
@@ -312,7 +312,7 @@ export function wrapFnWithLocation<A extends unknown[], R>(
312
312
  };
313
313
  }
314
314
 
315
- // Safely parse ND JSON (Newline delimitted JSON) chunks
315
+ // Safely parse ND JSON (Newline delimited JSON) chunks
316
316
  export function safeNDJSONParse(data: string | string[]) {
317
317
  // data may not be at proper newline boundaries, so we make sure everything is split
318
318
  // on proper newlines
package/src/index.ts CHANGED
@@ -63,7 +63,23 @@ export type {
63
63
  export type { default as Runner } from './core/runner';
64
64
  export type { Reporter, ReporterOptions } from './reporters';
65
65
 
66
- export type { SyntheticsConfig } from './common_types';
66
+ export type {
67
+ SyntheticsConfig,
68
+ StepEndResult,
69
+ JourneyEndResult,
70
+ JourneyStartResult,
71
+ JourneyResult,
72
+ StepResult,
73
+ StartEvent,
74
+ } from './common_types';
75
+
76
+ export type {
77
+ Journey,
78
+ JourneyCallback,
79
+ JourneyWithAnnotations,
80
+ JourneyOptions,
81
+ StepWithAnnotations,
82
+ } from './dsl';
67
83
 
68
84
  export type {
69
85
  Action,
@@ -31,7 +31,8 @@ import archiver from 'archiver';
31
31
  import { commonOptions } from '../core/transform';
32
32
  import { SyntheticsBundlePlugin } from './plugin';
33
33
 
34
- const SIZE_LIMIT_KB = 800;
34
+ // 1500KB Max Gzipped limit for bundled code to be pushed as Kibana project monitors.
35
+ const SIZE_LIMIT_KB = 1500;
35
36
 
36
37
  function relativeToCwd(entry: string) {
37
38
  return path.relative(process.cwd(), entry);
@@ -48,6 +49,7 @@ export class Bundler {
48
49
  entryPoints: [absPath],
49
50
  bundle: true,
50
51
  write: false,
52
+ minifyWhitespace: true,
51
53
  sourcemap: 'inline',
52
54
  external: ['@elastic/synthetics'],
53
55
  plugins: [SyntheticsBundlePlugin()],
@@ -100,7 +102,7 @@ export class Bundler {
100
102
  const sizeKb = size / 1024;
101
103
  if (sizeKb > SIZE_LIMIT_KB) {
102
104
  throw new Error(
103
- `You have monitors whose size exceeds the ${SIZE_LIMIT_KB}KB limit.`
105
+ `Bundled monitor code exceeds the recommended ${SIZE_LIMIT_KB}KB limit. Please check your dependencies and try again.`
104
106
  );
105
107
  }
106
108
  }
@@ -47,6 +47,7 @@ export async function sendRequest(options: APIRequestOptions) {
47
47
  'content-type': 'application/json',
48
48
  'user-agent': `Elastic/Synthetics ${version}`,
49
49
  'kbn-xsrf': 'true',
50
+ 'x-elastic-internal-origin': 'elastic-synthetics',
50
51
  },
51
52
  // align with the default timeout of the kibana route
52
53
  headersTimeout: 2 * 60 * 1000,
@@ -35,7 +35,7 @@ import {
35
35
  } from '../common_types';
36
36
  import { Journey, Step } from '../dsl';
37
37
 
38
- function renderDuration(durationMs) {
38
+ export function renderDuration(durationMs) {
39
39
  return parseInt(durationMs);
40
40
  }
41
41
 
@@ -0,0 +1,111 @@
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 { red, green, cyan } from 'kleur/colors';
27
+ import { ReporterOptions } from '.';
28
+
29
+ import BaseReporter, { renderDuration } from './base';
30
+ import { indent, now, symbols } from '../helpers';
31
+ import {
32
+ JourneyEndResult,
33
+ JourneyStartResult,
34
+ StepEndResult,
35
+ } from '../common_types';
36
+ import { Journey, Step } from '../dsl';
37
+ import { renderError, serializeError } from './reporter-util';
38
+
39
+ export default class BuildKiteCLIReporter extends BaseReporter {
40
+ journeys: Map<string, Array<StepEndResult & { name: string }>> = new Map();
41
+
42
+ constructor(options: ReporterOptions = {}) {
43
+ super(options);
44
+ }
45
+
46
+ override onJourneyStart(journey: Journey, {}: JourneyStartResult) {
47
+ this.write(`\n--- Journey: ${journey.name}`);
48
+ }
49
+
50
+ override onStepEnd(journey: Journey, step: Step, result: StepEndResult) {
51
+ super.onStepEnd(journey, step, result);
52
+ if (!this.journeys.has(journey.name)) {
53
+ this.journeys.set(journey.name, []);
54
+ }
55
+ this.journeys.get(journey.name)?.push({ name: step.name, ...result });
56
+ }
57
+
58
+ override async onJourneyEnd(journey: Journey, endResult: JourneyEndResult) {
59
+ const { start, end, status } = endResult;
60
+ super.onJourneyEnd(journey, endResult);
61
+ const message = `${symbols[status]} Took (${renderDuration(
62
+ end - start
63
+ )} seconds)`;
64
+ this.write(message);
65
+ }
66
+
67
+ override onEnd() {
68
+ const { failed, succeeded, skipped } = this.metrics;
69
+ const total = failed + succeeded + skipped;
70
+
71
+ if (total > 0) {
72
+ const failedJourneys = Array.from(this.journeys.entries()).filter(
73
+ ([, steps]) => steps.some(step => step.status === 'failed')
74
+ );
75
+
76
+ // if more than 5 journeys, we also report failed journeys at the end
77
+ if (failedJourneys.length > 0 && this.journeys.size > 5) {
78
+ failedJourneys.forEach(([journeyName, steps]) => {
79
+ const name = red(`Journey: ${journeyName} :slightly_frowning_face:`);
80
+ this.write(`\n+++ ${name}`);
81
+ steps.forEach(stepResult => {
82
+ const { status, end, start, error, name: stepName } = stepResult;
83
+ const message = `${
84
+ symbols[status]
85
+ } Step: '${stepName}' ${status} (${renderDuration(
86
+ (end - start) * 1000
87
+ )} ms)`;
88
+ this.write(indent(message));
89
+ if (error) {
90
+ this.write(renderError(serializeError(error)));
91
+ }
92
+ });
93
+ });
94
+ }
95
+ }
96
+
97
+ let message = '\n';
98
+ if (total === 0) {
99
+ message = 'No tests found!';
100
+ message += ` (${renderDuration(now())} ms) \n`;
101
+ this.write(message);
102
+ return;
103
+ }
104
+
105
+ message += succeeded > 0 ? green(` ${succeeded} passed`) : '';
106
+ message += failed > 0 ? red(` ${failed} failed`) : '';
107
+ message += skipped > 0 ? cyan(` ${skipped} skipped`) : '';
108
+ message += ` (${renderDuration(now() / 1000)} seconds) \n`;
109
+ this.write(message);
110
+ }
111
+ }
@@ -33,13 +33,18 @@ import {
33
33
  JourneyStartResult,
34
34
  StepEndResult,
35
35
  } from '../common_types';
36
+ import BuildKiteCLIReporter from './build_kite_cli';
36
37
 
37
38
  export type ReporterOptions = {
38
39
  fd?: number;
39
40
  colors?: boolean;
40
41
  dryRun?: boolean;
41
42
  };
42
- export type BuiltInReporterName = 'default' | 'json' | 'junit';
43
+ export type BuiltInReporterName =
44
+ | 'default'
45
+ | 'json'
46
+ | 'junit'
47
+ | 'buildkite-cli';
43
48
  export type ReporterInstance = new (opts: ReporterOptions) => Reporter;
44
49
  export const reporters: {
45
50
  [key in BuiltInReporterName]: ReporterInstance;
@@ -47,6 +52,7 @@ export const reporters: {
47
52
  default: BaseReporter,
48
53
  json: JSONReporter,
49
54
  junit: JUnitReporter,
55
+ 'buildkite-cli': BuildKiteCLIReporter,
50
56
  };
51
57
 
52
58
  export interface Reporter {