@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.
- package/README.md +4 -3
- package/dist/cli.js +99 -162
- package/dist/cli.js.map +1 -1
- package/dist/common_types.d.ts +156 -34
- package/dist/common_types.d.ts.map +1 -1
- package/dist/config.d.ts +2 -5
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +5 -5
- package/dist/config.js.map +1 -1
- package/dist/core/browser-service.js +5 -5
- package/dist/core/browser-service.js.map +1 -1
- package/dist/core/gatherer.d.ts +4 -8
- package/dist/core/gatherer.d.ts.map +1 -1
- package/dist/core/gatherer.js +46 -14
- package/dist/core/gatherer.js.map +1 -1
- package/dist/core/index.d.ts +5 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +23 -11
- package/dist/core/index.js.map +1 -1
- package/dist/core/logger.d.ts +0 -1
- package/dist/core/logger.d.ts.map +1 -1
- package/dist/core/logger.js +3 -16
- package/dist/core/logger.js.map +1 -1
- package/dist/core/runner.d.ts +21 -65
- package/dist/core/runner.d.ts.map +1 -1
- package/dist/core/runner.js +211 -93
- package/dist/core/runner.js.map +1 -1
- package/dist/dsl/journey.d.ts +7 -3
- package/dist/dsl/journey.d.ts.map +1 -1
- package/dist/dsl/journey.js +22 -6
- package/dist/dsl/journey.js.map +1 -1
- package/{src/reporters/reporter.ts → dist/dsl/locations.d.ts} +12 -10
- package/dist/dsl/locations.d.ts.map +1 -0
- package/dist/dsl/locations.js +41 -0
- package/dist/dsl/locations.js.map +1 -0
- package/dist/dsl/monitor.d.ts +65 -0
- package/dist/dsl/monitor.d.ts.map +1 -0
- package/dist/dsl/monitor.js +63 -0
- package/dist/dsl/monitor.js.map +1 -0
- package/dist/dsl/step.d.ts +3 -2
- package/dist/dsl/step.d.ts.map +1 -1
- package/dist/dsl/step.js +2 -1
- package/dist/dsl/step.js.map +1 -1
- package/dist/formatter/javascript.d.ts +98 -0
- package/dist/formatter/javascript.d.ts.map +1 -0
- package/dist/formatter/javascript.js +295 -0
- package/dist/formatter/javascript.js.map +1 -0
- package/dist/generator/index.d.ts +21 -0
- package/dist/generator/index.d.ts.map +1 -0
- package/dist/generator/index.js +169 -0
- package/dist/generator/index.js.map +1 -0
- package/dist/{reporters/reporter.d.ts → generator/utils.d.ts} +4 -9
- package/dist/generator/utils.d.ts.map +1 -0
- package/dist/generator/utils.js +57 -0
- package/dist/generator/utils.js.map +1 -0
- package/dist/helpers.d.ts +20 -1
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.js +98 -18
- package/dist/helpers.js.map +1 -1
- package/dist/index.d.ts +5 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -26
- package/dist/index.js.map +1 -1
- package/dist/{parse_args.d.ts → loader.d.ts} +2 -5
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +144 -0
- package/dist/loader.js.map +1 -0
- package/dist/options.d.ts +34 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/options.js +162 -0
- package/dist/options.js.map +1 -0
- package/dist/plugins/browser-console.d.ts +5 -4
- package/dist/plugins/browser-console.d.ts.map +1 -1
- package/dist/plugins/browser-console.js +27 -8
- package/dist/plugins/browser-console.js.map +1 -1
- package/dist/plugins/network.d.ts +20 -33
- package/dist/plugins/network.d.ts.map +1 -1
- package/dist/plugins/network.js +173 -214
- package/dist/plugins/network.js.map +1 -1
- package/dist/plugins/performance.d.ts +4 -19
- package/dist/plugins/performance.d.ts.map +1 -1
- package/dist/plugins/performance.js +5 -5
- package/dist/plugins/performance.js.map +1 -1
- package/dist/plugins/plugin-manager.d.ts +9 -5
- package/dist/plugins/plugin-manager.d.ts.map +1 -1
- package/dist/plugins/plugin-manager.js +44 -29
- package/dist/plugins/plugin-manager.js.map +1 -1
- package/dist/plugins/tracing.d.ts +6 -6
- package/dist/plugins/tracing.d.ts.map +1 -1
- package/dist/plugins/tracing.js +8 -7
- package/dist/plugins/tracing.js.map +1 -1
- package/dist/push/bundler.d.ts +34 -0
- package/dist/push/bundler.d.ts.map +1 -0
- package/dist/push/bundler.js +114 -0
- package/dist/push/bundler.js.map +1 -0
- package/dist/{reporters/reporter.js → push/index.d.ts} +4 -3
- package/dist/push/index.d.ts.map +1 -0
- package/dist/push/index.js +55 -0
- package/dist/push/index.js.map +1 -0
- package/dist/push/monitor.d.ts +32 -0
- package/dist/push/monitor.d.ts.map +1 -0
- package/dist/push/monitor.js +62 -0
- package/dist/push/monitor.js.map +1 -0
- package/dist/push/plugin.d.ts +33 -0
- package/dist/push/plugin.d.ts.map +1 -0
- package/dist/push/plugin.js +124 -0
- package/dist/push/plugin.js.map +1 -0
- package/dist/push/request.d.ts +42 -0
- package/dist/push/request.d.ts.map +1 -0
- package/dist/push/request.js +84 -0
- package/dist/push/request.js.map +1 -0
- package/dist/reporters/base.d.ts +14 -6
- package/dist/reporters/base.d.ts.map +1 -1
- package/dist/reporters/base.js +54 -48
- package/dist/reporters/base.js.map +1 -1
- package/dist/reporters/index.d.ts +18 -8
- package/dist/reporters/index.d.ts.map +1 -1
- package/dist/reporters/index.js.map +1 -1
- package/dist/reporters/json.d.ts +18 -67
- package/dist/reporters/json.d.ts.map +1 -1
- package/dist/reporters/json.js +153 -175
- package/dist/reporters/json.js.map +1 -1
- package/dist/reporters/junit.d.ts +7 -1
- package/dist/reporters/junit.d.ts.map +1 -1
- package/dist/reporters/junit.js +94 -89
- package/dist/reporters/junit.js.map +1 -1
- package/dist/sdk/lh-trace-processor.d.ts +35 -9
- package/dist/sdk/lh-trace-processor.d.ts.map +1 -1
- package/dist/sdk/lh-trace-processor.js +114 -53
- package/dist/sdk/lh-trace-processor.js.map +1 -1
- package/dist/sdk/trace-metrics.d.ts +4 -4
- package/dist/sdk/trace-metrics.d.ts.map +1 -1
- package/dist/sdk/trace-metrics.js +5 -6
- package/dist/sdk/trace-metrics.js.map +1 -1
- package/dist/sdk/trace-processor.d.ts +11 -3
- package/dist/sdk/trace-processor.d.ts.map +1 -1
- package/dist/sdk/trace-processor.js +17 -9
- package/dist/sdk/trace-processor.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1888
- package/package.json +31 -19
- package/src/cli.ts +187 -154
- package/src/common_types.ts +188 -34
- package/src/config.ts +2 -5
- package/src/core/gatherer.ts +55 -27
- package/src/core/index.ts +36 -15
- package/src/core/logger.ts +1 -12
- package/src/core/runner.ts +216 -152
- package/src/dsl/journey.ts +29 -5
- package/src/dsl/locations.ts +38 -0
- package/src/dsl/monitor.ts +87 -0
- package/src/dsl/step.ts +9 -2
- package/src/formatter/javascript.ts +367 -0
- package/src/generator/index.ts +212 -0
- package/src/generator/utils.ts +54 -0
- package/src/helpers.ts +106 -10
- package/src/index.ts +21 -22
- package/src/loader.ts +162 -0
- package/src/options.ts +173 -0
- package/src/plugins/browser-console.ts +30 -8
- package/src/plugins/network.ts +208 -267
- package/src/plugins/performance.ts +6 -22
- package/src/plugins/plugin-manager.ts +49 -31
- package/src/plugins/tracing.ts +8 -9
- package/src/push/bundler.ts +95 -0
- package/src/push/index.ts +59 -0
- package/src/push/monitor.ts +68 -0
- package/src/push/plugin.ts +114 -0
- package/src/push/request.ts +111 -0
- package/src/reporters/base.ts +63 -52
- package/src/reporters/index.ts +26 -3
- package/src/reporters/json.ts +203 -206
- package/src/reporters/junit.ts +98 -93
- package/src/sdk/lh-trace-processor.ts +132 -68
- package/src/sdk/trace-metrics.ts +10 -6
- package/src/sdk/trace-processor.ts +28 -13
- package/templates/.github/workflows/run-synthetics.yml +26 -0
- package/templates/README.md +21 -0
- package/templates/journeys/advanced-example-helpers.ts +54 -0
- package/templates/journeys/advanced-example.journey.ts +43 -0
- package/templates/journeys/example.journey.ts +18 -0
- package/templates/synthetics.config.ts +26 -0
- package/CHANGELOG.md +0 -102
- package/NOTICE.txt +0 -221
- package/dist/parse_args.d.ts.map +0 -1
- package/dist/parse_args.js +0 -89
- package/dist/parse_args.js.map +0 -1
- package/dist/reporters/reporter.d.ts.map +0 -1
- package/dist/reporters/reporter.js.map +0 -1
- package/src/parse_args.ts +0 -127
package/src/common_types.ts
CHANGED
|
@@ -23,25 +23,52 @@
|
|
|
23
23
|
*
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
-
import {
|
|
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 {
|
|
35
|
+
import { BuiltInReporterName, ReporterInstance } from './reporters';
|
|
36
|
+
import { MonitorConfig } from './dsl/monitor';
|
|
29
37
|
|
|
30
38
|
export type VoidCallback = () => void;
|
|
31
|
-
export type
|
|
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
|
-
|
|
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
|
-
|
|
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:
|
|
82
|
-
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
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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
|
-
|
|
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
|
/**
|
package/src/core/gatherer.ts
CHANGED
|
@@ -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(
|
|
45
|
+
Gatherer.browser = await chromium.connect(wsEndpoint);
|
|
57
46
|
} else {
|
|
58
47
|
Gatherer.browser = await chromium.launch({
|
|
59
|
-
|
|
60
|
-
|
|
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 {
|
|
106
|
+
const { network, metrics } = options;
|
|
77
107
|
const pluginManager = new PluginManager(driver);
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
|
56
|
-
|
|
57
|
-
|
|
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) => {
|
package/src/core/logger.ts
CHANGED
|
@@ -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
|
-
|
|
37
|
+
console.log(time + italic(grey(msg)) + '\n');
|
|
49
38
|
}
|