@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
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;;;;;;AAEH,gCAAkE;AAClE,sDAA8B;AAE9B,qCAA+B;AAE/B;;;GAGG;AACH,MAAM,iBAAiB,GAAG,MAAM,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;AAC1D,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,EAAE;IAC9B,MAAM,CAAC,iBAAiB,CAAC,GAAG,IAAI,gBAAM,EAAE,CAAC;CAC1C;AAEY,QAAA,MAAM,GAAW,MAAM,CAAC,iBAAiB,CAAC,CAAC;AAEjD,MAAM,OAAO,GAAG,CACrB,OAAgC,EAChC,QAAyB,EACzB,EAAE;IACF,YAAG,CAAC,qBAAqB,OAAO,EAAE,CAAC,CAAC;IACpC,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;QAC/B,OAAO,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC;KAC1C;IACD,MAAM,CAAC,GAAG,IAAI,aAAO,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACzC,cAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IACrB,OAAO,CAAC,CAAC;AACX,CAAC,CAAC;AAXW,QAAA,OAAO,WAWlB;AAEK,MAAM,IAAI,GAAG,CAAC,IAAY,EAAE,QAAsB,EAAE,EAAE;;IAC3D,YAAG,CAAC,kBAAkB,IAAI,EAAE,CAAC,CAAC;IAC9B,OAAO,MAAA,cAAM,CAAC,cAAc,0CAAE,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AACxD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AAO,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;AACxC,CAAC,CAAC;AAFW,QAAA,SAAS,aAEpB;AAEK,MAAM,QAAQ,GAAG,CAAC,QAAuB,EAAE,EAAE;IAClD,cAAM,CAAC,OAAO,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;AACvC,CAAC,CAAC;AAFW,QAAA,QAAQ,YAEnB;AAEK,MAAM,MAAM,GAAG,CAAC,QAAuB,EAAE,EAAE;IAChD,IAAI,CAAC,cAAM,CAAC,cAAc,EAAE;QAC1B,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;KACpE;IACD,OAAO,cAAM,CAAC,cAAc,CAAC,OAAO,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAC3D,CAAC,CAAC;AALW,QAAA,MAAM,UAKjB;AAEK,MAAM,KAAK,GAAG,CAAC,QAAuB,EAAE,EAAE;IAC/C,IAAI,CAAC,cAAM,CAAC,cAAc,EAAE;QAC1B,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;KACnE;IACD,OAAO,cAAM,CAAC,cAAc,CAAC,OAAO,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;AAC1D,CAAC,CAAC;AALW,QAAA,KAAK,SAKhB"}
@@ -22,6 +22,5 @@
22
22
  * THE SOFTWARE.
23
23
  *
24
24
  */
25
- export declare const setLogger: (fd: number) => any;
26
25
  export declare function log(msg: any): void;
27
26
  //# sourceMappingURL=logger.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/core/logger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AASH,eAAO,MAAM,SAAS,OAAQ,MAAM,QAKnC,CAAC;AAEF,wBAAgB,GAAG,CAAC,GAAG,KAAA,QAStB"}
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/core/logger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAYH,wBAAgB,GAAG,CAAC,GAAG,KAAA,QAStB"}
@@ -23,32 +23,25 @@
23
23
  * THE SOFTWARE.
24
24
  *
25
25
  */
26
- var __importDefault = (this && this.__importDefault) || function (mod) {
27
- return (mod && mod.__esModule) ? mod : { "default": mod };
28
- };
29
26
  Object.defineProperty(exports, "__esModule", { value: true });
30
- exports.log = exports.setLogger = void 0;
31
- const sonic_boom_1 = __importDefault(require("sonic-boom"));
27
+ exports.log = void 0;
32
28
  const colors_1 = require("kleur/colors");
33
29
  const helpers_1 = require("../helpers");
34
- const defaultFd = process.stdout.fd;
35
- let logger = new sonic_boom_1.default({ fd: defaultFd, sync: true });
36
- const setLogger = (fd) => {
37
- if (fd && fd !== defaultFd) {
38
- logger = new sonic_boom_1.default({ fd });
39
- }
40
- return logger;
41
- };
42
- exports.setLogger = setLogger;
30
+ /**
31
+ * Set debug based on DEBUG ENV and namespace - synthetics
32
+ */
33
+ if (process.env.DEBUG && process.env.DEBUG.includes('synthetics')) {
34
+ process.env['__SYNTHETICS__DEBUG__'] = '1';
35
+ }
43
36
  function log(msg) {
44
- if (!process.env.DEBUG || !msg) {
37
+ if (!process.env['__SYNTHETICS__DEBUG__'] || !msg) {
45
38
  return;
46
39
  }
47
40
  if (typeof msg === 'object') {
48
41
  msg = JSON.stringify(msg);
49
42
  }
50
- const time = colors_1.dim(colors_1.cyan(`at ${parseInt(String(helpers_1.now()))} ms `));
51
- logger.write(time + colors_1.italic(colors_1.grey(msg)) + '\n');
43
+ const time = (0, colors_1.dim)((0, colors_1.cyan)(`at ${parseInt(String((0, helpers_1.now)()))} ms `));
44
+ process.stderr.write(time + (0, colors_1.italic)((0, colors_1.grey)(msg)) + '\n');
52
45
  }
53
46
  exports.log = log;
54
47
  //# sourceMappingURL=logger.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/core/logger.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;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AE;IACjE,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,GAAG,GAAG,CAAC;CAC5C;AAED,SAAgB,GAAG,CAAC,GAAG;IACrB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,IAAI,CAAC,GAAG,EAAE;QACjD,OAAO;KACR;IACD,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;QAC3B,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;KAC3B;IACD,MAAM,IAAI,GAAG,IAAA,YAAG,EAAC,IAAA,aAAI,EAAC,MAAM,QAAQ,CAAC,MAAM,CAAC,IAAA,aAAG,GAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;IAC5D,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,GAAG,IAAA,eAAM,EAAC,IAAA,aAAI,EAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;AACxD,CAAC;AATD,kBASC"}
@@ -22,86 +22,34 @@
22
22
  * THE SOFTWARE.
23
23
  *
24
24
  */
25
- /// <reference types="node" />
26
- import { EventEmitter } from 'events';
27
25
  import { Journey } from '../dsl/journey';
28
26
  import { Step } from '../dsl/step';
29
- import { Reporter } from '../reporters';
30
- import { StatusValue, HooksCallback, Params, PluginOutput, CliArgs, HooksArgs, PlaywrightOptions } from '../common_types';
27
+ import { HooksCallback, Params, HooksArgs, Driver, RunOptions, JourneyResult, StepResult } from '../common_types';
31
28
  import { PluginManager } from '../plugins';
32
- import { Metrics } from '../plugins';
33
- import { Driver } from './gatherer';
34
- export declare type RunOptions = Omit<CliArgs, 'debug' | 'json' | 'pattern' | 'inline' | 'require' | 'suiteParams' | 'reporter' | 'richEvents' | 'capability' | 'sandbox' | 'headless'> & {
35
- environment?: string;
36
- playwrightOptions?: PlaywrightOptions;
37
- reporter?: CliArgs['reporter'] | Reporter;
38
- };
39
- declare type BaseContext = {
29
+ import { Monitor, MonitorConfig } from '../dsl/monitor';
30
+ declare type HookType = 'beforeAll' | 'afterAll';
31
+ export declare type SuiteHooks = Record<HookType, Array<HooksCallback>>;
32
+ declare type JourneyContext = {
40
33
  params?: Params;
41
34
  start: number;
42
- end?: number;
43
- };
44
- declare type JourneyContext = BaseContext & {
45
35
  driver: Driver;
46
36
  pluginManager: PluginManager;
47
37
  };
48
- declare type StepResult = {
49
- status: StatusValue;
50
- url?: string;
51
- metrics?: Metrics;
52
- error?: Error;
53
- };
54
- declare type JourneyResult = {
55
- status: StatusValue;
56
- error?: Error;
57
- };
58
38
  declare type RunResult = Record<string, JourneyResult>;
59
- declare type HookType = 'beforeAll' | 'afterAll';
60
- export declare type SuiteHooks = Record<HookType, Array<HooksCallback>>;
61
- interface Events {
62
- start: {
63
- numJourneys: number;
64
- };
65
- 'journey:register': {
66
- journey: Journey;
67
- };
68
- 'journey:start': {
69
- journey: Journey;
70
- timestamp: number;
71
- params: Params;
72
- };
73
- 'journey:end': BaseContext & JourneyResult & PluginOutput & {
74
- journey: Journey;
75
- options: RunOptions;
76
- };
77
- 'journey:end:reported': unknown;
78
- 'step:start': {
79
- journey: Journey;
80
- step: Step;
81
- };
82
- 'step:end': StepResult & {
83
- start: number;
84
- end: number;
85
- journey: Journey;
86
- step: Step;
87
- };
88
- end: unknown;
89
- }
90
- export default interface Runner {
91
- on<K extends keyof Events>(name: K, listener: (v: Events[K]) => void): this;
92
- emit<K extends keyof Events>(event: K, args: Events[K]): boolean;
93
- }
94
- export default class Runner extends EventEmitter {
95
- active: boolean;
96
- currentJourney?: Journey;
39
+ export default class Runner {
40
+ #private;
97
41
  journeys: Journey[];
98
42
  hooks: SuiteHooks;
99
43
  hookError: Error | undefined;
44
+ monitor?: Monitor;
100
45
  static screenshotPath: string;
101
46
  static createContext(options: RunOptions): Promise<JourneyContext>;
102
47
  captureScreenshot(page: Driver['page'], step: Step): Promise<void>;
48
+ get currentJourney(): Journey;
103
49
  addHook(type: HookType, callback: HooksCallback): void;
50
+ updateMonitor(config: MonitorConfig): void;
104
51
  addJourney(journey: Journey): void;
52
+ setReporter(options: RunOptions): void;
105
53
  runBeforeAllHook(args: HooksArgs): Promise<void>;
106
54
  runAfterAllHook(args: HooksArgs): Promise<void>;
107
55
  runBeforeHook(journey: Journey, args: HooksArgs): Promise<void>;
@@ -116,6 +64,7 @@ export default class Runner extends EventEmitter {
116
64
  runFakeJourney(journey: Journey, options: RunOptions): Promise<JourneyResult>;
117
65
  runJourney(journey: Journey, options: RunOptions): Promise<JourneyResult>;
118
66
  init(options: RunOptions): Promise<void>;
67
+ buildMonitors(options: RunOptions): Monitor[];
119
68
  run(options: RunOptions): Promise<RunResult>;
120
69
  reset(): Promise<void>;
121
70
  }
@@ -1 +1 @@
1
- {"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../../src/core/runner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;;AAEH,OAAO,EAAQ,YAAY,EAAE,MAAM,QAAQ,CAAC;AAE5C,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EAAa,QAAQ,EAAE,MAAM,cAAc,CAAC;AAWnD,OAAO,EACL,WAAW,EACX,aAAa,EACb,MAAM,EACN,YAAY,EACZ,OAAO,EACP,SAAS,EACT,iBAAiB,EAClB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAsB,OAAO,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EAAE,MAAM,EAAY,MAAM,YAAY,CAAC;AAG9C,oBAAY,UAAU,GAAG,IAAI,CAC3B,OAAO,EACL,OAAO,GACP,MAAM,GACN,SAAS,GACT,QAAQ,GACR,SAAS,GACT,aAAa,GACb,UAAU,GACV,YAAY,GACZ,YAAY,GACZ,SAAS,GACT,UAAU,CACb,GAAG;IACF,WAAW,CAAC,EAAE,MAAM,C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UAAU;IA8BrB,eAAe,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc;IAenD,UAAU,CACd,OAAO,KAAA,EACP,MAAM,EAAE,cAAc,GAAG,aAAa,EACtC,OAAO,EAAE,UAAU;IAmBrB;;OAEG;IACG,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU;IAoBpD,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU;IAiChD,IAAI,CAAC,OAAO,EAAE,UAAU;IAY9B,aAAa,CAAC,OAAO,EAAE,UAAU;IAgC3B,GAAG,CAAC,OAAO,EAAE,UAAU;IAuCvB,KAAK;CAWZ"}
@@ -24,30 +24,35 @@
24
24
  *
25
25
  */
26
26
  Object.defineProperty(exports, "__esModule", { value: true });
27
- const events_1 = require("events");
28
27
  const path_1 = require("path");
28
+ const promises_1 = require("fs/promises");
29
29
  const reporters_1 = require("../reporters");
30
30
  const helpers_1 = require("../helpers");
31
- const plugins_1 = require("../plugins");
32
31
  const gatherer_1 = require("./gatherer");
33
32
  const logger_1 = require("./logger");
34
- class Runner extends events_1.EventEmitter {
35
- constructor() {
36
- super(...arguments);
37
- this.active = false;
38
- this.currentJourney = null;
39
- this.journeys = [];
40
- this.hooks = { beforeAll: [], afterAll: [] };
41
- }
33
+ const monitor_1 = require("../dsl/monitor");
34
+ class Runner {
35
+ #active = false;
36
+ #reporter;
37
+ #currentJourney = null;
38
+ journeys = [];
39
+ hooks = { beforeAll: [], afterAll: [] };
40
+ hookError;
41
+ monitor;
42
+ static screenshotPath = (0, path_1.join)(helpers_1.CACHE_PATH, 'screenshots');
42
43
  static async createContext(options) {
43
- const start = helpers_1.monotonicTimeInSeconds();
44
44
  const driver = await gatherer_1.Gatherer.setupDriver(options);
45
+ /**
46
+ * Do not include browser launch/context creation duration
47
+ * as part of journey duration
48
+ */
49
+ const start = (0, helpers_1.monotonicTimeInSeconds)();
45
50
  const pluginManager = await gatherer_1.Gatherer.beginRecording(driver, options);
46
51
  /**
47
52
  * For each journey we create the screenshots folder for
48
53
  * caching all screenshots and clear them at end of each journey
49
54
  */
50
- await helpers_1.mkdirAsync(this.screenshotPath, { recursive: true });
55
+ await (0, promises_1.mkdir)(this.screenshotPath, { recursive: true });
51
56
  return {
52
57
  start,
53
58
  params: options.params,
@@ -56,11 +61,11 @@ class Runner extends events_1.EventEmitter {
56
61
  };
57
62
  }
58
63
  async captureScreenshot(page, step) {
59
- await page.waitForLoadState('load');
60
64
  const buffer = await page
61
65
  .screenshot({
62
66
  type: 'jpeg',
63
67
  quality: 80,
68
+ timeout: 5000,
64
69
  })
65
70
  .catch(() => { });
66
71
  /**
@@ -69,43 +74,66 @@ class Runner extends events_1.EventEmitter {
69
74
  * each journey without impacting the step timing information
70
75
  */
71
76
  if (buffer) {
72
- const fileName = `${helpers_1.generateUniqueId()}.json`;
73
- await helpers_1.writeFileAsync(path_1.join(Runner.screenshotPath, fileName), JSON.stringify({
77
+ const fileName = `${(0, helpers_1.generateUniqueId)()}.json`;
78
+ const screenshot = {
74
79
  step,
80
+ timestamp: (0, helpers_1.getTimestamp)(),
75
81
  data: buffer.toString('base64'),
76
- }));
82
+ };
83
+ await (0, promises_1.writeFile)((0, path_1.join)(Runner.screenshotPath, fileName), JSON.stringify(screenshot));
84
+ (0, logger_1.log)(`Runner: captured screenshot for (${step.name})`);
77
85
  }
78
86
  }
87
+ get currentJourney() {
88
+ return this.#currentJourney;
89
+ }
79
90
  addHook(type, callback) {
80
91
  this.hooks[type].push(callback);
81
92
  }
93
+ updateMonitor(config) {
94
+ if (!this.monitor) {
95
+ this.monitor = new monitor_1.Monitor(config);
96
+ return;
97
+ }
98
+ this.monitor.update(config);
99
+ }
82
100
  addJourney(journey) {
83
101
  this.journeys.push(journey);
84
- this.currentJourney = journey;
102
+ this.#currentJourney = journey;
103
+ }
104
+ setReporter(options) {
105
+ /**
106
+ * Set up the corresponding reporter and fallback
107
+ * to default reporter if not provided
108
+ */
109
+ const { reporter, outfd } = options;
110
+ const Reporter = typeof reporter === 'function'
111
+ ? reporter
112
+ : reporters_1.reporters[reporter] || reporters_1.reporters['default'];
113
+ this.#reporter = new Reporter({ fd: outfd });
85
114
  }
86
115
  async runBeforeAllHook(args) {
87
- logger_1.log(`Runner: beforeAll hooks`);
88
- await helpers_1.runParallel(this.hooks.beforeAll, args);
116
+ (0, logger_1.log)(`Runner: beforeAll hooks`);
117
+ await (0, helpers_1.runParallel)(this.hooks.beforeAll, args);
89
118
  }
90
119
  async runAfterAllHook(args) {
91
- logger_1.log(`Runner: afterAll hooks`);
92
- await helpers_1.runParallel(this.hooks.afterAll, args);
120
+ (0, logger_1.log)(`Runner: afterAll hooks`);
121
+ await (0, helpers_1.runParallel)(this.hooks.afterAll, args);
93
122
  }
94
123
  async runBeforeHook(journey, args) {
95
- logger_1.log(`Runner: before hooks for (${journey.name})`);
96
- await helpers_1.runParallel(journey.hooks.before, args);
124
+ (0, logger_1.log)(`Runner: before hooks for (${journey.name})`);
125
+ await (0, helpers_1.runParallel)(journey.hooks.before, args);
97
126
  }
98
127
  async runAfterHook(journey, args) {
99
- logger_1.log(`Runner: after hooks for (${journey.name})`);
100
- await helpers_1.runParallel(journey.hooks.after, args);
128
+ (0, logger_1.log)(`Runner: after hooks for (${journey.name})`);
129
+ await (0, helpers_1.runParallel)(journey.hooks.after, args);
101
130
  }
102
131
  async runStep(step, context, options) {
103
- var _a;
104
132
  const data = {
105
133
  status: 'succeeded',
106
134
  };
107
- logger_1.log(`Runner: start step (${step.name})`);
108
- const { metrics, screenshots } = options;
135
+ (0, logger_1.log)(`Runner: start step (${step.name})`);
136
+ const { metrics, screenshots, filmstrips, trace } = options;
109
137
  const { driver, pluginManager } = context;
110
138
  /**
111
139
  * URL needs to be the first navigation request of any step
@@ -116,35 +144,59 @@ class Runner extends events_1.EventEmitter {
116
144
  if (!data.url && req.isNavigationRequest()) {
117
145
  data.url = req.url();
118
146
  }
119
- driver.page.off('request', captureUrl);
147
+ driver.context.off('request', captureUrl);
120
148
  };
121
- driver.page.on('request', captureUrl);
149
+ driver.context.on('request', captureUrl);
150
+ const traceEnabled = trace || filmstrips;
122
151
  try {
152
+ /**
153
+ * Set up plugin manager context and also register
154
+ * step level plugins
155
+ */
123
156
  pluginManager.onStep(step);
157
+ traceEnabled && (await pluginManager.start('trace'));
158
+ // call the step definition
124
159
  await step.callback();
125
- if (metrics) {
126
- data.metrics = await pluginManager.get(plugins_1.PerformanceManager).getMetrics();
127
- }
128
160
  }
129
161
  catch (error) {
130
162
  data.status = 'failed';
131
163
  data.error = error;
132
164
  }
133
165
  finally {
134
- (_a = data.url) !== null && _a !== void 0 ? _a : (data.url = driver.page.url());
135
- if (screenshots && screenshots !== 'off') {
136
- await this.captureScreenshot(driver.page, step);
166
+ /**
167
+ * Collect all step level metrics and trace events
168
+ */
169
+ if (metrics) {
170
+ data.pagemetrics = await pluginManager.get('performance').getMetrics();
171
+ }
172
+ if (traceEnabled) {
173
+ const traceOutput = await pluginManager.stop('trace');
174
+ Object.assign(data, traceOutput);
175
+ }
176
+ /**
177
+ * Capture screenshot for the newly created pages
178
+ * via popup or new windows/tabs
179
+ *
180
+ * Last open page will get us the correct screenshot
181
+ */
182
+ const pages = driver.context.pages();
183
+ const page = pages[pages.length - 1];
184
+ if (page) {
185
+ data.url ??= page.url();
186
+ if (screenshots && screenshots !== 'off') {
187
+ await this.captureScreenshot(page, step);
188
+ }
137
189
  }
138
190
  }
139
- logger_1.log(`Runner: end step (${step.name})`);
191
+ (0, logger_1.log)(`Runner: end step (${step.name})`);
140
192
  return data;
141
193
  }
142
194
  async runSteps(journey, context, options) {
143
195
  const results = [];
144
196
  let skipStep = false;
145
197
  for (const step of journey.steps) {
146
- const start = helpers_1.monotonicTimeInSeconds();
147
- this.emit('step:start', { journey, step });
198
+ const start = (0, helpers_1.monotonicTimeInSeconds)();
199
+ this.#reporter?.onStepStart?.(journey, step);
148
200
  let data = { status: 'succeeded' };
149
201
  if (skipStep) {
150
202
  data.status = 'skipped';
@@ -157,11 +209,9 @@ class Runner extends events_1.EventEmitter {
157
209
  if (data.error)
158
210
  skipStep = true;
159
211
  }
160
- this.emit('step:end', {
161
- journey,
162
- step,
212
+ this.#reporter?.onStepEnd?.(journey, step, {
163
213
  start,
164
- end: helpers_1.monotonicTimeInSeconds(),
214
+ end: (0, helpers_1.monotonicTimeInSeconds)(),
165
215
  ...data,
166
216
  });
167
217
  if (options.pauseOnError && data.error) {
@@ -172,70 +222,62 @@ class Runner extends events_1.EventEmitter {
172
222
  return results;
173
223
  }
174
224
  registerJourney(journey, context) {
175
- this.currentJourney = journey;
176
- const timestamp = helpers_1.getTimestamp();
225
+ this.#currentJourney = journey;
226
+ const timestamp = (0, helpers_1.getTimestamp)();
177
227
  const { params } = context;
178
- this.emit('journey:start', { journey, timestamp, params });
228
+ this.#reporter?.onJourneyStart?.(journey, {
229
+ timestamp,
230
+ params,
231
+ });
179
232
  /**
180
- * Load and register the steps for the current journey
233
+ * Exeucute the journey callback which would
234
+ * register the steps for the current journey
181
235
  */
182
236
  journey.callback({ ...context.driver, params });
183
237
  }
184
238
  async endJourney(journey, result, options) {
239
+ const end = (0, helpers_1.monotonicTimeInSeconds)();
185
240
  const { pluginManager, start, status, error } = result;
186
241
  const pluginOutput = await pluginManager.output();
187
- this.emit('journey:end', {
188
- journey,
242
+ await this.#reporter?.onJourneyEnd?.(journey, {
189
243
  status,
190
244
  error,
191
245
  start,
192
- end: helpers_1.monotonicTimeInSeconds(),
246
+ end,
247
+ timestamp: (0, helpers_1.getTimestamp)(),
193
248
  options,
194
249
  ...pluginOutput,
195
250
  browserconsole: status == 'failed' ? pluginOutput.browserconsole : [],
196
251
  });
197
- /**
198
- * Wait for the all the reported events to be consumed aschronously
199
- * by reporter.
200
- */
201
- if (options.reporter === 'json') {
202
- await events_1.once(this, 'journey:end:reported');
203
- }
204
252
  // clear screenshots cache after each journey
205
- await helpers_1.rmdirAsync(Runner.screenshotPath, { recursive: true });
253
+ await (0, promises_1.rm)(Runner.screenshotPath, { recursive: true, force: true });
206
254
  }
207
255
  /**
208
256
  * Simulate a journey run to capture errors in the beforeAll hook
209
257
  */
210
258
  async runFakeJourney(journey, options) {
211
- const start = helpers_1.monotonicTimeInSeconds();
212
- this.emit('journey:start', {
213
- journey,
214
- timestamp: helpers_1.getTimestamp(),
259
+ const start = (0, helpers_1.monotonicTimeInSeconds)();
260
+ this.#reporter.onJourneyStart?.(journey, {
261
+ timestamp: (0, helpers_1.getTimestamp)(),
215
262
  params: options.params,
216
263
  });
217
264
  const result = {
218
265
  status: 'failed',
219
266
  error: this.hookError,
220
267
  };
221
- this.emit('journey:end', {
222
- journey,
268
+ await this.#reporter.onJourneyEnd?.(journey, {
269
+ timestamp: (0, helpers_1.getTimestamp)(),
223
270
  start,
224
271
  options,
225
- end: helpers_1.monotonicTimeInSeconds(),
272
+ end: (0, helpers_1.monotonicTimeInSeconds)(),
226
273
  ...result,
227
274
  });
228
- if (options.reporter === 'json') {
229
- await events_1.once(this, 'journey:end:reported');
230
- }
231
275
  return result;
232
276
  }
233
277
  async runJourney(journey, options) {
234
- const result = {
235
- status: 'succeeded',
236
- };
237
- logger_1.log(`Runner: start journey (${journey.name})`);
278
+ const result = { status: 'succeeded' };
238
279
  const context = await Runner.createContext(options);
280
+ (0, logger_1.log)(`Runner: start journey (${journey.name})`);
239
281
  try {
240
282
  this.registerJourney(journey, context);
241
283
  const hookArgs = {
@@ -263,31 +305,57 @@ class Runner extends events_1.EventEmitter {
263
305
  await this.endJourney(journey, { ...context, ...result }, options);
264
306
  await gatherer_1.Gatherer.dispose(context.driver);
265
307
  }
266
- logger_1.log(`Runner: end journey (${journey.name})`);
308
+ (0, logger_1.log)(`Runner: end journey (${journey.name})`);
267
309
  return result;
268
310
  }
269
311
  async init(options) {
270
- const { reporter, outfd } = options;
312
+ this.setReporter(options);
313
+ this.#reporter.onStart?.({
314
+ numJourneys: this.journeys.length,
315
+ networkConditions: options.networkConditions,
316
+ });
271
317
  /**
272
- * Set up the corresponding reporter and fallback
318
+ * Set up the directory for caching screenshots
273
319
  */
274
- const Reporter = typeof reporter === 'function'
275
- ? reporter
276
- : reporters_1.reporters[reporter] || reporters_1.reporters['default'];
277
- new Reporter(this, { fd: outfd });
278
- this.emit('start', { numJourneys: this.journeys.length });
320
+ await (0, promises_1.mkdir)(helpers_1.CACHE_PATH, { recursive: true });
321
+ }
322
+ buildMonitors(options) {
279
323
  /**
280
- * Set up the directory for caching screenshots
324
+ * Update the global monitor configuration required for
325
+ * setting defaults
281
326
  */
282
- await helpers_1.mkdirAsync(helpers_1.CACHE_PATH, { recursive: true });
327
+ this.updateMonitor({
328
+ throttling: options.throttling,
329
+ schedule: options.schedule,
330
+ locations: options.locations,
331
+ privateLocations: options.privateLocations,
332
+ params: options.params,
333
+ playwrightOptions: options.playwrightOptions,
334
+ });
335
+ const monitors = [];
336
+ for (const journey of this.journeys) {
337
+ if (!journey.isMatch(options.match, options.tags)) {
338
+ continue;
339
+ }
340
+ this.#currentJourney = journey;
341
+ /**
342
+ * Execute dummy callback to get all monitor specific
343
+ * configurations for the current journey
344
+ */
345
+ journey.callback({ params: options.params });
346
+ journey.monitor.update(this.monitor?.config);
347
+ journey.monitor.validate();
348
+ monitors.push(journey.monitor);
349
+ }
350
+ return monitors;
283
351
  }
284
352
  async run(options) {
285
353
  const result = {};
286
- if (this.active) {
354
+ if (this.#active) {
287
355
  return result;
288
356
  }
289
- this.active = true;
290
- logger_1.log(`Runner: run ${this.journeys.length} journeys`);
357
+ this.#active = true;
358
+ (0, logger_1.log)(`Runner: run ${this.journeys.length} journeys`);
291
359
  this.init(options);
292
360
  await this.runBeforeAllHook({
293
361
  env: options.environment,
@@ -299,7 +367,7 @@ class Runner extends events_1.EventEmitter {
299
367
  * Used by heartbeat to gather all registered journeys
300
368
  */
301
369
  if (dryRun) {
302
- this.emit('journey:register', { journey });
370
+ this.#reporter.onJourneyRegister?.(journey);
303
371
  continue;
304
372
  }
305
373
  if (!journey.isMatch(match, tags)) {
@@ -319,17 +387,16 @@ class Runner extends events_1.EventEmitter {
319
387
  return result;
320
388
  }
321
389
  async reset() {
390
+ this.#currentJourney = null;
391
+ this.journeys = [];
392
+ this.#active = false;
322
393
  /**
323
394
  * Clear all cache data stored for post processing by
324
395
  * the current synthetic agent run
325
396
  */
326
- await helpers_1.rmdirAsync(helpers_1.CACHE_PATH, { recursive: true });
327
- this.currentJourney = null;
328
- this.journeys = [];
329
- this.active = false;
330
- this.emit('end', {});
397
+ await (0, promises_1.rm)(helpers_1.CACHE_PATH, { recursive: true, force: true });
398
+ await this.#reporter?.onEnd?.();
331
399
  }
332
400
  }
333
401
  exports.default = Runner;
334
- Runner.screenshotPath = path_1.join(helpers_1.CACHE_PATH, 'screenshots');
335
402
  //# sourceMappingURL=runner.js.map