@elastic/synthetics 1.25.0 → 1.26.1
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/dist/cli.js +3 -1
- package/dist/cli.js.map +1 -1
- package/dist/common_types.d.ts +8 -0
- package/dist/common_types.d.ts.map +1 -1
- package/dist/core/certs.d.ts +55 -0
- package/dist/core/certs.d.ts.map +1 -0
- package/dist/core/certs.js +111 -0
- package/dist/core/certs.js.map +1 -0
- package/dist/core/gatherer.d.ts.map +1 -1
- package/dist/core/gatherer.js +16 -0
- package/dist/core/gatherer.js.map +1 -1
- package/dist/core/runner.d.ts.map +1 -1
- package/dist/core/runner.js +1 -0
- package/dist/core/runner.js.map +1 -1
- package/dist/core/transform.d.ts +1 -0
- package/dist/core/transform.d.ts.map +1 -1
- package/dist/dsl/monitor.d.ts +2 -1
- package/dist/dsl/monitor.d.ts.map +1 -1
- package/dist/dsl/monitor.js.map +1 -1
- package/dist/options.d.ts +1 -0
- package/dist/options.d.ts.map +1 -1
- package/dist/options.js +16 -0
- package/dist/options.js.map +1 -1
- package/dist/plugins/network.d.ts.map +1 -1
- package/dist/plugins/network.js +29 -21
- package/dist/plugins/network.js.map +1 -1
- package/dist/push/run-local.d.ts.map +1 -1
- package/dist/push/run-local.js +13 -2
- package/dist/push/run-local.js.map +1 -1
- package/package.json +8 -18
- package/src/cli.ts +3 -0
- package/src/common_types.ts +12 -0
- package/src/core/certs.ts +122 -0
- package/src/core/gatherer.ts +22 -0
- package/src/core/runner.ts +1 -0
- package/src/dsl/monitor.ts +2 -0
- package/src/options.ts +25 -0
- package/src/plugins/network.ts +31 -23
- package/src/push/run-local.ts +23 -14
- package/.husky/install.mjs +0 -7
package/src/plugins/network.ts
CHANGED
|
@@ -64,18 +64,22 @@ export class NetworkManager {
|
|
|
64
64
|
* to not result in exception
|
|
65
65
|
*/
|
|
66
66
|
private _addBarrier(page: Page, promise: Promise<void>) {
|
|
67
|
-
if (!page)
|
|
67
|
+
if (!page) {
|
|
68
|
+
promise.catch(error => {
|
|
69
|
+
log(`Plugins: failed to collect network metadata: ${error}`);
|
|
70
|
+
});
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
68
73
|
const race = Promise.race([
|
|
69
|
-
new Promise<void>(resolve =>
|
|
70
|
-
page.on('close', () => {
|
|
71
|
-
this._barrierPromises.delete(race);
|
|
72
|
-
resolve();
|
|
73
|
-
})
|
|
74
|
-
),
|
|
74
|
+
new Promise<void>(resolve => page.once('close', () => resolve())),
|
|
75
75
|
promise,
|
|
76
76
|
]);
|
|
77
77
|
this._barrierPromises.add(race);
|
|
78
|
-
race
|
|
78
|
+
race
|
|
79
|
+
.catch(error => {
|
|
80
|
+
log(`Plugins: failed to collect network metadata: ${error}`);
|
|
81
|
+
})
|
|
82
|
+
.finally(() => this._barrierPromises.delete(race));
|
|
79
83
|
}
|
|
80
84
|
|
|
81
85
|
private _nullableFrameBarrier(req: Request): Frame | null {
|
|
@@ -98,10 +102,10 @@ export class NetworkManager {
|
|
|
98
102
|
/**
|
|
99
103
|
* Listen for all network events from PW context
|
|
100
104
|
*/
|
|
101
|
-
context.on('request', this._onRequest
|
|
102
|
-
context.on('response', this._onResponse
|
|
103
|
-
context.on('requestfinished', this._onRequestCompleted
|
|
104
|
-
context.on('requestfailed', this._onRequestCompleted
|
|
105
|
+
context.on('request', this._onRequest);
|
|
106
|
+
context.on('response', this._onResponse);
|
|
107
|
+
context.on('requestfinished', this._onRequestCompleted);
|
|
108
|
+
context.on('requestfailed', this._onRequestCompleted);
|
|
105
109
|
}
|
|
106
110
|
|
|
107
111
|
private _findNetworkEntry(
|
|
@@ -110,7 +114,7 @@ export class NetworkManager {
|
|
|
110
114
|
return request[NETWORK_ENTRY_SUMBOL];
|
|
111
115
|
}
|
|
112
116
|
|
|
113
|
-
private _onRequest(request: Request) {
|
|
117
|
+
private _onRequest = (request: Request) => {
|
|
114
118
|
const url = request.url();
|
|
115
119
|
/**
|
|
116
120
|
* Data URI should not show up as network requests
|
|
@@ -165,9 +169,9 @@ export class NetworkManager {
|
|
|
165
169
|
|
|
166
170
|
request[NETWORK_ENTRY_SUMBOL] = networkEntry;
|
|
167
171
|
this.results.push(networkEntry);
|
|
168
|
-
}
|
|
172
|
+
};
|
|
169
173
|
|
|
170
|
-
private async
|
|
174
|
+
private _onResponse = async (response: Response) => {
|
|
171
175
|
const request = response.request();
|
|
172
176
|
const networkEntry = this._findNetworkEntry(request);
|
|
173
177
|
if (!networkEntry) return;
|
|
@@ -220,9 +224,9 @@ export class NetworkManager {
|
|
|
220
224
|
if (details) networkEntry.response.securityDetails = details;
|
|
221
225
|
})
|
|
222
226
|
);
|
|
223
|
-
}
|
|
227
|
+
};
|
|
224
228
|
|
|
225
|
-
private async
|
|
229
|
+
private _onRequestCompleted = async (request: Request) => {
|
|
226
230
|
const networkEntry = this._findNetworkEntry(request);
|
|
227
231
|
if (!networkEntry) return;
|
|
228
232
|
|
|
@@ -255,9 +259,18 @@ export class NetworkManager {
|
|
|
255
259
|
};
|
|
256
260
|
})
|
|
257
261
|
);
|
|
258
|
-
}
|
|
262
|
+
};
|
|
259
263
|
|
|
260
264
|
async stop() {
|
|
265
|
+
/**
|
|
266
|
+
* First detach the listeners so that no new network events are recorded
|
|
267
|
+
*/
|
|
268
|
+
const context = this.driver.context;
|
|
269
|
+
context.off('request', this._onRequest);
|
|
270
|
+
context.off('response', this._onResponse);
|
|
271
|
+
context.off('requestfinished', this._onRequestCompleted);
|
|
272
|
+
context.off('requestfailed', this._onRequestCompleted);
|
|
273
|
+
|
|
261
274
|
/**
|
|
262
275
|
* Waiting for all network events is error prone and might hang the tests
|
|
263
276
|
* from getting closed forever when there are upstream bugs in browsers or
|
|
@@ -266,11 +279,6 @@ export class NetworkManager {
|
|
|
266
279
|
if (this._barrierPromises.size > 0) {
|
|
267
280
|
log(`Plugins: dropping ${this._barrierPromises.size} network events`);
|
|
268
281
|
}
|
|
269
|
-
const context = this.driver.context;
|
|
270
|
-
context.off('request', this._onRequest.bind(this));
|
|
271
|
-
context.off('response', this._onResponse.bind(this));
|
|
272
|
-
context.off('requestfinished', this._onRequestCompleted.bind(this));
|
|
273
|
-
context.off('requestfailed', this._onRequestCompleted.bind(this));
|
|
274
282
|
this._barrierPromises.clear();
|
|
275
283
|
log(`Plugins: stopped collecting network events`);
|
|
276
284
|
return this.results;
|
package/src/push/run-local.ts
CHANGED
|
@@ -74,21 +74,30 @@ async function runNpmInstall(directory) {
|
|
|
74
74
|
|
|
75
75
|
async function runTest(directory, schema: MonitorSchema) {
|
|
76
76
|
return new Promise<void>((resolve, reject) => {
|
|
77
|
-
const
|
|
78
|
-
'
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
77
|
+
const args = [
|
|
78
|
+
'@elastic/synthetics',
|
|
79
|
+
'.',
|
|
80
|
+
'--playwright-options',
|
|
81
|
+
JSON.stringify(schema.playwrightOptions),
|
|
82
|
+
'--params',
|
|
83
|
+
JSON.stringify(schema.params),
|
|
84
|
+
];
|
|
85
|
+
const allowlist = schema.certificateErrorSpkiAllowlist;
|
|
86
|
+
if (allowlist != null) {
|
|
87
|
+
const entries = Array.isArray(allowlist) ? allowlist : [allowlist];
|
|
88
|
+
const pemEntries = entries
|
|
89
|
+
.map(entry =>
|
|
90
|
+
Buffer.isBuffer(entry) ? entry.toString('utf-8') : entry
|
|
91
|
+
)
|
|
92
|
+
.filter((entry): entry is string => Boolean(entry));
|
|
93
|
+
if (pemEntries.length > 0) {
|
|
94
|
+
args.push('--certificate-error-spki-allowlist', ...pemEntries);
|
|
90
95
|
}
|
|
91
|
-
|
|
96
|
+
}
|
|
97
|
+
const runTest = spawn('npx', args, {
|
|
98
|
+
cwd: directory,
|
|
99
|
+
stdio: 'inherit',
|
|
100
|
+
});
|
|
92
101
|
|
|
93
102
|
runTest.on('close', resolve);
|
|
94
103
|
runTest.on('error', err => {
|