@elastic/synthetics 1.0.0-beta.3 → 1.0.0-beta.30

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 (189) hide show
  1. package/README.md +4 -3
  2. package/dist/cli.js +99 -162
  3. package/dist/cli.js.map +1 -1
  4. package/dist/common_types.d.ts +156 -34
  5. package/dist/common_types.d.ts.map +1 -1
  6. package/dist/config.d.ts +2 -5
  7. package/dist/config.d.ts.map +1 -1
  8. package/dist/config.js +5 -5
  9. package/dist/config.js.map +1 -1
  10. package/dist/core/browser-service.js +5 -5
  11. package/dist/core/browser-service.js.map +1 -1
  12. package/dist/core/gatherer.d.ts +4 -8
  13. package/dist/core/gatherer.d.ts.map +1 -1
  14. package/dist/core/gatherer.js +46 -14
  15. package/dist/core/gatherer.js.map +1 -1
  16. package/dist/core/index.d.ts +5 -1
  17. package/dist/core/index.d.ts.map +1 -1
  18. package/dist/core/index.js +23 -11
  19. package/dist/core/index.js.map +1 -1
  20. package/dist/core/logger.d.ts +0 -1
  21. package/dist/core/logger.d.ts.map +1 -1
  22. package/dist/core/logger.js +3 -16
  23. package/dist/core/logger.js.map +1 -1
  24. package/dist/core/runner.d.ts +21 -65
  25. package/dist/core/runner.d.ts.map +1 -1
  26. package/dist/core/runner.js +211 -93
  27. package/dist/core/runner.js.map +1 -1
  28. package/dist/dsl/journey.d.ts +7 -3
  29. package/dist/dsl/journey.d.ts.map +1 -1
  30. package/dist/dsl/journey.js +22 -6
  31. package/dist/dsl/journey.js.map +1 -1
  32. package/{src/reporters/reporter.ts → dist/dsl/locations.d.ts} +12 -10
  33. package/dist/dsl/locations.d.ts.map +1 -0
  34. package/dist/dsl/locations.js +41 -0
  35. package/dist/dsl/locations.js.map +1 -0
  36. package/dist/dsl/monitor.d.ts +65 -0
  37. package/dist/dsl/monitor.d.ts.map +1 -0
  38. package/dist/dsl/monitor.js +63 -0
  39. package/dist/dsl/monitor.js.map +1 -0
  40. package/dist/dsl/step.d.ts +3 -2
  41. package/dist/dsl/step.d.ts.map +1 -1
  42. package/dist/dsl/step.js +2 -1
  43. package/dist/dsl/step.js.map +1 -1
  44. package/dist/formatter/javascript.d.ts +98 -0
  45. package/dist/formatter/javascript.d.ts.map +1 -0
  46. package/dist/formatter/javascript.js +295 -0
  47. package/dist/formatter/javascript.js.map +1 -0
  48. package/dist/generator/index.d.ts +21 -0
  49. package/dist/generator/index.d.ts.map +1 -0
  50. package/dist/generator/index.js +169 -0
  51. package/dist/generator/index.js.map +1 -0
  52. package/dist/{reporters/reporter.d.ts → generator/utils.d.ts} +4 -9
  53. package/dist/generator/utils.d.ts.map +1 -0
  54. package/dist/generator/utils.js +57 -0
  55. package/dist/generator/utils.js.map +1 -0
  56. package/dist/helpers.d.ts +20 -1
  57. package/dist/helpers.d.ts.map +1 -1
  58. package/dist/helpers.js +98 -18
  59. package/dist/helpers.js.map +1 -1
  60. package/dist/index.d.ts +5 -6
  61. package/dist/index.d.ts.map +1 -1
  62. package/dist/index.js +5 -26
  63. package/dist/index.js.map +1 -1
  64. package/dist/{parse_args.d.ts → loader.d.ts} +2 -5
  65. package/dist/loader.d.ts.map +1 -0
  66. package/dist/loader.js +144 -0
  67. package/dist/loader.js.map +1 -0
  68. package/dist/options.d.ts +34 -0
  69. package/dist/options.d.ts.map +1 -0
  70. package/dist/options.js +162 -0
  71. package/dist/options.js.map +1 -0
  72. package/dist/plugins/browser-console.d.ts +5 -4
  73. package/dist/plugins/browser-console.d.ts.map +1 -1
  74. package/dist/plugins/browser-console.js +27 -8
  75. package/dist/plugins/browser-console.js.map +1 -1
  76. package/dist/plugins/network.d.ts +20 -33
  77. package/dist/plugins/network.d.ts.map +1 -1
  78. package/dist/plugins/network.js +173 -214
  79. package/dist/plugins/network.js.map +1 -1
  80. package/dist/plugins/performance.d.ts +4 -19
  81. package/dist/plugins/performance.d.ts.map +1 -1
  82. package/dist/plugins/performance.js +5 -5
  83. package/dist/plugins/performance.js.map +1 -1
  84. package/dist/plugins/plugin-manager.d.ts +9 -5
  85. package/dist/plugins/plugin-manager.d.ts.map +1 -1
  86. package/dist/plugins/plugin-manager.js +44 -29
  87. package/dist/plugins/plugin-manager.js.map +1 -1
  88. package/dist/plugins/tracing.d.ts +6 -6
  89. package/dist/plugins/tracing.d.ts.map +1 -1
  90. package/dist/plugins/tracing.js +8 -7
  91. package/dist/plugins/tracing.js.map +1 -1
  92. package/dist/push/bundler.d.ts +34 -0
  93. package/dist/push/bundler.d.ts.map +1 -0
  94. package/dist/push/bundler.js +114 -0
  95. package/dist/push/bundler.js.map +1 -0
  96. package/dist/{reporters/reporter.js → push/index.d.ts} +4 -3
  97. package/dist/push/index.d.ts.map +1 -0
  98. package/dist/push/index.js +55 -0
  99. package/dist/push/index.js.map +1 -0
  100. package/dist/push/monitor.d.ts +32 -0
  101. package/dist/push/monitor.d.ts.map +1 -0
  102. package/dist/push/monitor.js +62 -0
  103. package/dist/push/monitor.js.map +1 -0
  104. package/dist/push/plugin.d.ts +33 -0
  105. package/dist/push/plugin.d.ts.map +1 -0
  106. package/dist/push/plugin.js +124 -0
  107. package/dist/push/plugin.js.map +1 -0
  108. package/dist/push/request.d.ts +42 -0
  109. package/dist/push/request.d.ts.map +1 -0
  110. package/dist/push/request.js +84 -0
  111. package/dist/push/request.js.map +1 -0
  112. package/dist/reporters/base.d.ts +14 -6
  113. package/dist/reporters/base.d.ts.map +1 -1
  114. package/dist/reporters/base.js +54 -48
  115. package/dist/reporters/base.js.map +1 -1
  116. package/dist/reporters/index.d.ts +18 -8
  117. package/dist/reporters/index.d.ts.map +1 -1
  118. package/dist/reporters/index.js.map +1 -1
  119. package/dist/reporters/json.d.ts +18 -67
  120. package/dist/reporters/json.d.ts.map +1 -1
  121. package/dist/reporters/json.js +153 -175
  122. package/dist/reporters/json.js.map +1 -1
  123. package/dist/reporters/junit.d.ts +7 -1
  124. package/dist/reporters/junit.d.ts.map +1 -1
  125. package/dist/reporters/junit.js +94 -89
  126. package/dist/reporters/junit.js.map +1 -1
  127. package/dist/sdk/lh-trace-processor.d.ts +35 -9
  128. package/dist/sdk/lh-trace-processor.d.ts.map +1 -1
  129. package/dist/sdk/lh-trace-processor.js +114 -53
  130. package/dist/sdk/lh-trace-processor.js.map +1 -1
  131. package/dist/sdk/trace-metrics.d.ts +4 -4
  132. package/dist/sdk/trace-metrics.d.ts.map +1 -1
  133. package/dist/sdk/trace-metrics.js +5 -6
  134. package/dist/sdk/trace-metrics.js.map +1 -1
  135. package/dist/sdk/trace-processor.d.ts +11 -3
  136. package/dist/sdk/trace-processor.d.ts.map +1 -1
  137. package/dist/sdk/trace-processor.js +17 -9
  138. package/dist/sdk/trace-processor.js.map +1 -1
  139. package/dist/tsconfig.tsbuildinfo +1 -1888
  140. package/package.json +31 -19
  141. package/src/cli.ts +187 -154
  142. package/src/common_types.ts +188 -34
  143. package/src/config.ts +2 -5
  144. package/src/core/gatherer.ts +55 -27
  145. package/src/core/index.ts +36 -15
  146. package/src/core/logger.ts +1 -12
  147. package/src/core/runner.ts +216 -152
  148. package/src/dsl/journey.ts +29 -5
  149. package/src/dsl/locations.ts +38 -0
  150. package/src/dsl/monitor.ts +87 -0
  151. package/src/dsl/step.ts +9 -2
  152. package/src/formatter/javascript.ts +367 -0
  153. package/src/generator/index.ts +212 -0
  154. package/src/generator/utils.ts +54 -0
  155. package/src/helpers.ts +106 -10
  156. package/src/index.ts +21 -22
  157. package/src/loader.ts +162 -0
  158. package/src/options.ts +173 -0
  159. package/src/plugins/browser-console.ts +30 -8
  160. package/src/plugins/network.ts +208 -267
  161. package/src/plugins/performance.ts +6 -22
  162. package/src/plugins/plugin-manager.ts +49 -31
  163. package/src/plugins/tracing.ts +8 -9
  164. package/src/push/bundler.ts +95 -0
  165. package/src/push/index.ts +59 -0
  166. package/src/push/monitor.ts +68 -0
  167. package/src/push/plugin.ts +114 -0
  168. package/src/push/request.ts +111 -0
  169. package/src/reporters/base.ts +63 -52
  170. package/src/reporters/index.ts +26 -3
  171. package/src/reporters/json.ts +203 -206
  172. package/src/reporters/junit.ts +98 -93
  173. package/src/sdk/lh-trace-processor.ts +132 -68
  174. package/src/sdk/trace-metrics.ts +10 -6
  175. package/src/sdk/trace-processor.ts +28 -13
  176. package/templates/.github/workflows/run-synthetics.yml +26 -0
  177. package/templates/README.md +21 -0
  178. package/templates/journeys/advanced-example-helpers.ts +54 -0
  179. package/templates/journeys/advanced-example.journey.ts +43 -0
  180. package/templates/journeys/example.journey.ts +18 -0
  181. package/templates/synthetics.config.ts +26 -0
  182. package/CHANGELOG.md +0 -102
  183. package/NOTICE.txt +0 -221
  184. package/dist/parse_args.d.ts.map +0 -1
  185. package/dist/parse_args.js +0 -89
  186. package/dist/parse_args.js.map +0 -1
  187. package/dist/reporters/reporter.d.ts.map +0 -1
  188. package/dist/reporters/reporter.js.map +0 -1
  189. package/src/parse_args.ts +0 -127
@@ -23,25 +23,52 @@
23
23
  *
24
24
  */
25
25
 
26
- import { Protocol } from 'playwright-chromium/types/protocol';
26
+ import {
27
+ BrowserContextOptions,
28
+ LaunchOptions,
29
+ CDPSession,
30
+ ChromiumBrowser,
31
+ ChromiumBrowserContext,
32
+ Page,
33
+ } from 'playwright-chromium';
27
34
  import { Step } from './dsl';
28
- import { reporters } from './reporters';
35
+ import { BuiltInReporterName, ReporterInstance } from './reporters';
36
+ import { MonitorConfig } from './dsl/monitor';
29
37
 
30
38
  export type VoidCallback = () => void;
31
- export type Params = Record<string, unknown>;
39
+ export type Location = {
40
+ file: string;
41
+ line: number;
42
+ column: number;
43
+ };
44
+
45
+ export type Params = Record<string, any>;
32
46
  export type HooksArgs = {
33
47
  env: string;
34
48
  params: Params;
35
49
  };
36
50
  export type HooksCallback = (args: HooksArgs) => void;
37
51
  export type StatusValue = 'succeeded' | 'failed' | 'skipped';
38
- export type Reporters = keyof typeof reporters;
52
+
53
+ export type NetworkConditions = {
54
+ offline: boolean;
55
+ downloadThroughput: number;
56
+ uploadThroughput: number;
57
+ latency: number;
58
+ };
59
+
60
+ export type Driver = {
61
+ browser: ChromiumBrowser;
62
+ context: ChromiumBrowserContext;
63
+ page: Page;
64
+ client: CDPSession;
65
+ };
39
66
 
40
67
  export type TraceOutput = {
41
68
  name: string;
42
69
  type: string;
43
70
  start: MetricDuration;
44
- end?: MetricDuration;
71
+ duration?: MetricDuration;
45
72
  score?: number;
46
73
  };
47
74
 
@@ -73,26 +100,69 @@ export type BrowserInfo = {
73
100
  version: string;
74
101
  };
75
102
 
103
+ export type Screenshot = {
104
+ timestamp: number;
105
+ step: Step;
106
+ data: string;
107
+ };
108
+
109
+ export type SecurityDetails = {
110
+ issuer?: string;
111
+ protocol?: string;
112
+ subjectName?: string;
113
+ validFrom?: number;
114
+ validTo?: number;
115
+ };
116
+
117
+ export type Request = {
118
+ method: string;
119
+ url: string;
120
+ headers: Record<string, string>;
121
+ // Total size in bytes of the request (body and headers)
122
+ bytes?: number;
123
+ body?: {
124
+ // Size in bytes of the request body
125
+ bytes: number;
126
+ };
127
+ referrer?: string;
128
+ };
129
+
130
+ export type Response = {
131
+ url?: string;
132
+ status: number;
133
+ statusText?: string;
134
+ mimeType?: string;
135
+ headers: Record<string, string>;
136
+ // Total size in bytes of the response (body and headers)
137
+ bytes?: number;
138
+ body?: {
139
+ // Size in bytes of the response body
140
+ bytes: number;
141
+ };
142
+ transferSize?: number;
143
+ redirectURL?: string;
144
+ securityDetails?: SecurityDetails;
145
+ remoteIPAddress?: string;
146
+ remotePort?: number;
147
+ fromServiceWorker?: boolean;
148
+ };
149
+
76
150
  export type NetworkInfo = {
77
151
  url: string;
78
152
  browser: BrowserInfo;
79
- method: string;
80
153
  type: string;
81
- request: Protocol.Network.Request;
82
- response?: Protocol.Network.Response;
154
+ request: Request;
155
+ response: Response;
83
156
  isNavigationRequest: boolean;
84
157
  requestSentTime: number;
85
158
  loadEndTime: number;
86
159
  responseReceivedTime: number;
87
- status: number;
88
160
  resourceSize: number;
89
161
  transferSize: number;
90
- timings?: {
162
+ timings: {
91
163
  blocked: number;
92
- queueing: number;
93
164
  dns: number;
94
165
  ssl: number;
95
- proxy: number;
96
166
  connect: number;
97
167
  send: number;
98
168
  wait: number;
@@ -101,9 +171,12 @@ export type NetworkInfo = {
101
171
  };
102
172
  } & DefaultPluginOutput;
103
173
 
174
+ export type PageMetrics = Record<string, number>;
175
+
104
176
  export type BrowserMessage = {
105
177
  text: string;
106
178
  type: string;
179
+ error?: Error;
107
180
  } & DefaultPluginOutput;
108
181
 
109
182
  export type PluginOutput = {
@@ -114,30 +187,111 @@ export type PluginOutput = {
114
187
  metrics?: PerfMetrics;
115
188
  };
116
189
 
117
- export type CliArgs = {
118
- capability?: Array<string>;
119
- config?: string;
120
- environment?: string;
121
- outfd?: number;
122
- headless?: boolean;
123
- screenshots?: boolean;
124
- ssblocks?: boolean;
125
- metrics?: boolean;
126
- filmstrips?: boolean;
127
- trace?: boolean;
190
+ export type ScreenshotOptions = 'on' | 'off' | 'only-on-failure';
191
+
192
+ export type ThrottlingOptions = {
193
+ download?: number;
194
+ upload?: number;
195
+ latency?: number;
196
+ };
197
+
198
+ type BaseArgs = {
199
+ params?: Params;
200
+ screenshots?: ScreenshotOptions;
128
201
  dryRun?: boolean;
129
- network?: boolean;
130
- pauseOnError?: boolean;
131
- reporter?: Reporters;
132
- wsEndpoint?: string;
133
- sandbox?: boolean;
134
- json?: boolean;
135
- pattern?: string;
136
- inline: boolean;
137
202
  match?: string;
138
203
  tags?: Array<string>;
139
- require: Array<string>;
140
- debug?: boolean;
141
- suiteParams?: string;
204
+ outfd?: number;
205
+ wsEndpoint?: string;
206
+ pauseOnError?: boolean;
207
+ ignoreHttpsErrors?: boolean;
208
+ playwrightOptions?: PlaywrightOptions;
209
+ quietExitCode?: boolean;
210
+ throttling?: ThrottlingOptions;
211
+ schedule?: MonitorConfig['schedule'];
212
+ locations?: MonitorConfig['locations'];
213
+ };
214
+
215
+ export type CliArgs = BaseArgs & {
216
+ config?: string;
217
+ reporter?: BuiltInReporterName;
218
+ pattern?: string;
219
+ inline?: boolean;
220
+ require?: Array<string>;
221
+ headless?: boolean;
222
+ sandbox?: boolean;
142
223
  richEvents?: boolean;
224
+ capability?: Array<string>;
225
+ ignoreHttpsErrors?: boolean;
226
+ throttling?: boolean | ThrottlingOptions;
227
+ };
228
+
229
+ export type RunOptions = BaseArgs & {
230
+ metrics?: boolean;
231
+ ssblocks?: boolean;
232
+ network?: boolean;
233
+ trace?: boolean;
234
+ filmstrips?: boolean;
235
+ environment?: string;
236
+ playwrightOptions?: PlaywrightOptions;
237
+ networkConditions?: NetworkConditions;
238
+ reporter?: BuiltInReporterName | ReporterInstance;
239
+ };
240
+
241
+ export type PushOptions = {
242
+ auth: string;
243
+ url: string;
244
+ project: string;
245
+ space: string;
246
+ schedule?: MonitorConfig['schedule'];
247
+ locations?: MonitorConfig['locations'];
248
+ };
249
+
250
+ export type PlaywrightOptions = LaunchOptions & BrowserContextOptions;
251
+ export type SyntheticsConfig = {
252
+ params?: Params;
253
+ playwrightOptions?: PlaywrightOptions;
254
+ monitor?: MonitorConfig;
255
+ };
256
+
257
+ /** Runner Payload types */
258
+ export type JourneyResult = {
259
+ status: StatusValue;
260
+ error?: Error;
261
+ networkinfo?: PluginOutput['networkinfo'];
262
+ browserconsole?: PluginOutput['browserconsole'];
263
+ };
264
+
265
+ export type StepResult = {
266
+ status: StatusValue;
267
+ url?: string;
268
+ error?: Error;
269
+ pagemetrics?: PageMetrics;
270
+ filmstrips?: PluginOutput['filmstrips'];
271
+ metrics?: PluginOutput['metrics'];
272
+ traces?: PluginOutput['traces'];
273
+ };
274
+
275
+ /** Reporter and Runner contract */
276
+ export type StartEvent = {
277
+ numJourneys: number;
278
+ networkConditions?: NetworkConditions;
279
+ };
280
+
281
+ export type JourneyStartResult = {
282
+ timestamp: number;
283
+ params?: Params;
284
+ };
285
+
286
+ export type JourneyEndResult = JourneyStartResult &
287
+ JourneyResult & {
288
+ start: number;
289
+ end: number;
290
+ options: RunOptions;
291
+ timestamp: number;
292
+ };
293
+
294
+ export type StepEndResult = StepResult & {
295
+ start: number;
296
+ end: number;
143
297
  };
package/src/config.ts CHANGED
@@ -24,13 +24,10 @@
24
24
  */
25
25
 
26
26
  import { isAbsolute, resolve, dirname } from 'path';
27
+ import { SyntheticsConfig } from './common_types';
27
28
  import { isFile } from './helpers';
28
29
 
29
- interface Config {
30
- params?: Record<string, unknown>;
31
- }
32
-
33
- export function readConfig(env: string, config?: string): Config {
30
+ export function readConfig(env: string, config?: string): SyntheticsConfig {
34
31
  let options = {};
35
32
  const cwd = process.cwd();
36
33
  /**
@@ -23,23 +23,10 @@
23
23
  *
24
24
  */
25
25
 
26
- import {
27
- CDPSession,
28
- chromium,
29
- ChromiumBrowser,
30
- ChromiumBrowserContext,
31
- Page,
32
- } from 'playwright-chromium';
26
+ import { chromium, ChromiumBrowser, BrowserContext } from 'playwright-chromium';
33
27
  import { PluginManager } from '../plugins';
34
- import { RunOptions } from './runner';
35
28
  import { log } from './logger';
36
-
37
- export type Driver = {
38
- browser: ChromiumBrowser;
39
- context: ChromiumBrowserContext;
40
- page: Page;
41
- client: CDPSession;
42
- };
29
+ import { Driver, NetworkConditions, RunOptions } from '../common_types';
43
30
 
44
31
  /**
45
32
  * Purpose of the Gatherer is to set up the necessary browser driver
@@ -49,38 +36,79 @@ export class Gatherer {
49
36
  static browser: ChromiumBrowser;
50
37
 
51
38
  static async setupDriver(options: RunOptions): Promise<Driver> {
39
+ log('Gatherer: setup driver');
40
+ const { wsEndpoint, playwrightOptions, networkConditions } = options;
41
+
52
42
  if (Gatherer.browser == null) {
53
- const { wsEndpoint, headless, sandbox = false } = options;
54
43
  if (wsEndpoint) {
55
44
  log(`Gatherer: connecting to WS endpoint: ${wsEndpoint}`);
56
- Gatherer.browser = await chromium.connect({ wsEndpoint });
45
+ Gatherer.browser = await chromium.connect(wsEndpoint);
57
46
  } else {
58
47
  Gatherer.browser = await chromium.launch({
59
- headless,
60
- chromiumSandbox: sandbox,
48
+ ...playwrightOptions,
49
+ args: [
50
+ ...(playwrightOptions?.headless ? ['--disable-gpu'] : []),
51
+ ...(playwrightOptions?.args ?? []),
52
+ ],
61
53
  });
62
54
  }
63
55
  }
64
- const context = await Gatherer.browser.newContext();
56
+ const context = await Gatherer.browser.newContext({
57
+ ...playwrightOptions,
58
+ userAgent: await Gatherer.getUserAgent(playwrightOptions?.userAgent),
59
+ });
60
+ Gatherer.setNetworkConditions(context, networkConditions);
61
+
65
62
  const page = await context.newPage();
66
63
  const client = await context.newCDPSession(page);
67
64
  return { browser: Gatherer.browser, context, page, client };
68
65
  }
69
66
 
67
+ static async getUserAgent(userAgent?: string) {
68
+ if (!userAgent) {
69
+ const session = await Gatherer.browser.newBrowserCDPSession();
70
+ ({ userAgent } = await session.send('Browser.getVersion'));
71
+ return userAgent + ' Elastic/Synthetics';
72
+ }
73
+ return userAgent;
74
+ }
75
+
76
+ static setNetworkConditions(
77
+ context: BrowserContext,
78
+ networkConditions: NetworkConditions
79
+ ) {
80
+ if (networkConditions) {
81
+ context.on('page', page => {
82
+ const context = page.context();
83
+ const emulatePromise = context
84
+ .newCDPSession(page)
85
+ .then(client =>
86
+ client.send('Network.emulateNetworkConditions', networkConditions)
87
+ );
88
+ /**
89
+ * Guard against pages that gets closed before the emulation kicks to capture
90
+ * unhandled rejections from accessing the CDP session of closed page
91
+ */
92
+ Promise.race([
93
+ new Promise<void>(resolve => page.on('close', () => resolve())),
94
+ emulatePromise,
95
+ ]);
96
+ });
97
+ }
98
+ }
99
+
70
100
  /**
71
101
  * Starts recording all events related to the v8 devtools protocol
72
102
  * https://chromedevtools.github.io/devtools-protocol/v8/
73
103
  */
74
104
  static async beginRecording(driver: Driver, options: RunOptions) {
75
105
  log('Gatherer: started recording');
76
- const { filmstrips, trace, network, metrics } = options;
106
+ const { network, metrics } = options;
77
107
  const pluginManager = new PluginManager(driver);
78
- const plugins = [pluginManager.start('browserconsole')];
79
- network && plugins.push(pluginManager.start('network'));
80
- metrics && plugins.push(pluginManager.start('performance'));
81
- if (filmstrips || trace) {
82
- plugins.push(pluginManager.start('trace', { filmstrips, trace }));
83
- }
108
+ pluginManager.registerAll(options);
109
+ const plugins = [await pluginManager.start('browserconsole')];
110
+ network && plugins.push(await pluginManager.start('network'));
111
+ metrics && plugins.push(await pluginManager.start('performance'));
84
112
  await Promise.all(plugins);
85
113
  return pluginManager;
86
114
  }
package/src/core/index.ts CHANGED
@@ -25,8 +25,10 @@
25
25
 
26
26
  import { Journey, JourneyCallback, JourneyOptions } from '../dsl';
27
27
  import Runner from './runner';
28
- import { VoidCallback, HooksCallback } from '../common_types';
28
+ import { VoidCallback, HooksCallback, Location } from '../common_types';
29
+ import { wrapFnWithLocation } from '../helpers';
29
30
  import { log } from './logger';
31
+ import { MonitorConfig } from '../dsl/monitor';
30
32
 
31
33
  /**
32
34
  * Use a gloabl Runner which would be accessed by the runtime and
@@ -39,22 +41,41 @@ if (!global[SYNTHETICS_RUNNER]) {
39
41
 
40
42
  export const runner: Runner = global[SYNTHETICS_RUNNER];
41
43
 
42
- export const journey = (
43
- options: JourneyOptions | string,
44
- callback: JourneyCallback
45
- ) => {
46
- log(`register journey: ${options}`);
47
- if (typeof options === 'string') {
48
- options = { name: options, id: options };
44
+ export const journey = wrapFnWithLocation(
45
+ (
46
+ location: Location,
47
+ options: JourneyOptions | string,
48
+ callback: JourneyCallback
49
+ ) => {
50
+ log(`register journey: ${JSON.stringify(options)}`);
51
+ if (typeof options === 'string') {
52
+ options = { name: options, id: options };
53
+ }
54
+ const j = new Journey(options, callback, location);
55
+ runner.addJourney(j);
56
+ return j;
49
57
  }
50
- const j = new Journey(options, callback);
51
- runner.addJourney(j);
52
- return j;
53
- };
58
+ );
59
+
60
+ export const step = wrapFnWithLocation(
61
+ (location: Location, name: string, callback: VoidCallback) => {
62
+ log(`register step: ${name}`);
63
+ return runner.currentJourney?.addStep(name, callback, location);
64
+ }
65
+ );
54
66
 
55
- export const step = (name: string, callback: VoidCallback) => {
56
- log(`register step: ${name}`);
57
- return runner.currentJourney?.addStep(name, callback);
67
+ export const monitor = {
68
+ use: wrapFnWithLocation((location: Location, config: MonitorConfig) => {
69
+ /**
70
+ * If the context is inside journey, then set it to journey context
71
+ * otherwise set to the global monitor which will be used for all journeys
72
+ */
73
+ if (runner.currentJourney) {
74
+ runner.currentJourney.updateMonitor(config);
75
+ } else {
76
+ runner.updateMonitor(config);
77
+ }
78
+ }),
58
79
  };
59
80
 
60
81
  export const beforeAll = (callback: HooksCallback) => {
@@ -23,20 +23,9 @@
23
23
  *
24
24
  */
25
25
 
26
- import SonicBoom from 'sonic-boom';
27
26
  import { grey, cyan, dim, italic } from 'kleur/colors';
28
27
  import { now } from '../helpers';
29
28
 
30
- const defaultFd = process.stdout.fd;
31
- let logger = new SonicBoom({ fd: defaultFd, sync: true });
32
-
33
- export const setLogger = (fd: number) => {
34
- if (fd && fd !== defaultFd) {
35
- logger = new SonicBoom({ fd });
36
- }
37
- return logger;
38
- };
39
-
40
29
  export function log(msg) {
41
30
  if (!process.env.DEBUG || !msg) {
42
31
  return;
@@ -45,5 +34,5 @@ export function log(msg) {
45
34
  msg = JSON.stringify(msg);
46
35
  }
47
36
  const time = dim(cyan(`at ${parseInt(String(now()))} ms `));
48
- logger.write(time + italic(grey(msg)) + '\n');
37
+ console.log(time + italic(grey(msg)) + '\n');
49
38
  }