@elastic/synthetics 1.4.0 → 1.5.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/bundles/lib/index.js +432 -0
- package/dist/cli.js +3 -3
- package/dist/cli.js.map +1 -1
- package/dist/common_types.d.ts +12 -2
- package/dist/common_types.d.ts.map +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +7 -1
- package/dist/config.js.map +1 -1
- package/dist/core/browser-service.js +2 -2
- package/dist/core/browser-service.js.map +1 -1
- package/dist/core/expect.d.ts +1 -152
- package/dist/core/expect.d.ts.map +1 -1
- package/dist/core/expect.js +14 -5
- package/dist/core/expect.js.map +1 -1
- package/dist/core/gatherer.d.ts +1 -1
- package/dist/core/gatherer.d.ts.map +1 -1
- package/dist/core/gatherer.js +5 -5
- package/dist/core/gatherer.js.map +1 -1
- package/dist/core/runner.d.ts.map +1 -1
- package/dist/core/runner.js +8 -7
- package/dist/core/runner.js.map +1 -1
- package/dist/dsl/journey.d.ts +1 -1
- package/dist/dsl/journey.d.ts.map +1 -1
- package/dist/dsl/monitor.d.ts +4 -0
- package/dist/dsl/monitor.d.ts.map +1 -1
- package/dist/dsl/monitor.js.map +1 -1
- package/dist/helpers.d.ts +0 -5
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.js +1 -24
- package/dist/helpers.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/options.d.ts +2 -1
- package/dist/options.d.ts.map +1 -1
- package/dist/options.js +13 -4
- package/dist/options.js.map +1 -1
- package/dist/plugins/browser-console.d.ts +3 -2
- package/dist/plugins/browser-console.d.ts.map +1 -1
- package/dist/plugins/browser-console.js +33 -7
- package/dist/plugins/browser-console.js.map +1 -1
- package/dist/plugins/network.d.ts +1 -0
- package/dist/plugins/network.d.ts.map +1 -1
- package/dist/plugins/network.js +15 -2
- package/dist/plugins/network.js.map +1 -1
- package/dist/push/kibana_api.d.ts.map +1 -1
- package/dist/push/kibana_api.js +1 -1
- package/dist/push/kibana_api.js.map +1 -1
- package/dist/push/monitor.d.ts.map +1 -1
- package/dist/push/monitor.js +10 -2
- package/dist/push/monitor.js.map +1 -1
- package/dist/push/request.d.ts.map +1 -1
- package/dist/push/request.js +4 -3
- package/dist/push/request.js.map +1 -1
- package/dist/push/utils.js +1 -1
- package/dist/push/utils.js.map +1 -1
- package/dist/reporters/base.d.ts +3 -0
- package/dist/reporters/base.d.ts.map +1 -1
- package/dist/reporters/base.js +20 -22
- package/dist/reporters/base.js.map +1 -1
- package/dist/reporters/index.d.ts +1 -0
- package/dist/reporters/index.d.ts.map +1 -1
- package/dist/reporters/index.js.map +1 -1
- package/dist/reporters/json.d.ts.map +1 -1
- package/dist/reporters/json.js +34 -1
- package/dist/reporters/json.js.map +1 -1
- package/dist/reporters/junit.d.ts.map +1 -1
- package/dist/reporters/junit.js +4 -4
- package/dist/reporters/junit.js.map +1 -1
- package/dist/reporters/reporter-util.d.ts +35 -0
- package/dist/reporters/reporter-util.d.ts.map +1 -0
- package/dist/reporters/reporter-util.js +192 -0
- package/dist/reporters/reporter-util.js.map +1 -0
- package/package.json +16 -8
- package/src/cli.ts +3 -3
- package/src/common_types.ts +15 -2
- package/src/config.ts +12 -1
- package/src/core/browser-service.ts +1 -1
- package/src/core/expect.ts +13 -191
- package/src/core/gatherer.ts +1 -1
- package/src/core/runner.ts +15 -9
- package/src/dsl/journey.ts +1 -1
- package/src/dsl/monitor.ts +4 -0
- package/src/helpers.ts +0 -24
- package/src/index.ts +1 -1
- package/src/options.ts +16 -4
- package/src/plugins/browser-console.ts +39 -8
- package/src/plugins/network.ts +16 -3
- package/src/push/kibana_api.ts +4 -3
- package/src/push/monitor.ts +13 -2
- package/src/push/request.ts +12 -4
- package/src/push/utils.ts +1 -1
- package/src/reporters/base.ts +26 -33
- package/src/reporters/index.ts +5 -1
- package/src/reporters/json.ts +39 -3
- package/src/reporters/junit.ts +5 -5
- package/src/reporters/reporter-util.ts +217 -0
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2020-present, Elastic NV
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in
|
|
14
|
+
* all copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
22
|
+
* THE SOFTWARE.
|
|
23
|
+
*
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import { fileURLToPath } from 'url';
|
|
27
|
+
import { resolve, sep } from 'path';
|
|
28
|
+
import { readFileSync } from 'fs';
|
|
29
|
+
import { inspect } from 'util';
|
|
30
|
+
import { gray } from 'kleur/colors';
|
|
31
|
+
import { codeFrameColumns } from '@babel/code-frame';
|
|
32
|
+
import StackUtils from 'stack-utils';
|
|
33
|
+
import { Location, StackFrame, TestError } from '../common_types';
|
|
34
|
+
|
|
35
|
+
const stackUtils = new StackUtils({ internals: StackUtils.nodeInternals() });
|
|
36
|
+
|
|
37
|
+
const SYNTHETICS_PATH = resolve(__dirname, '..', '..');
|
|
38
|
+
const PW_CORE_PATH = require.resolve('playwright-core');
|
|
39
|
+
|
|
40
|
+
function prepareStackFrame(line: string): StackFrame {
|
|
41
|
+
const frame = stackUtils.parseLine(line);
|
|
42
|
+
if (!frame) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
// ignore node internals
|
|
46
|
+
if (frame.file?.startsWith('internal') || frame.file?.startsWith('node:')) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// handle relative URLs
|
|
51
|
+
let file = frame.file?.startsWith('file://')
|
|
52
|
+
? fileURLToPath(frame.file)
|
|
53
|
+
: resolve(process.cwd(), frame.file);
|
|
54
|
+
|
|
55
|
+
// ignore node_modules
|
|
56
|
+
if (file.includes(`${sep}node_modules${sep}`)) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// filter library and PW files
|
|
61
|
+
if (!filterLibInternals(file)) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// When we bundle the journeys, we store the absolute path of the journey
|
|
66
|
+
// files and write the sourcemap relative to these files. When we try to
|
|
67
|
+
// extract the sourcemap file location, the stacktrace will be relatively
|
|
68
|
+
// resolved to these files which would be under `journeys` folder. So we strip
|
|
69
|
+
// these extra `journeys` from the path to get the correct file location.
|
|
70
|
+
if (frame.file?.includes('journeys/journeys')) {
|
|
71
|
+
file = file.replace('journeys/journeys', 'journeys');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
file,
|
|
76
|
+
line: frame.line || 0,
|
|
77
|
+
column: frame.column || 0,
|
|
78
|
+
function: frame.function,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function filterLibInternals(file: string) {
|
|
83
|
+
// To ignore filtering the stack trace on tests
|
|
84
|
+
if (process.env.TEST_OVERRIDE) {
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
if (file.startsWith(SYNTHETICS_PATH)) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
// should have been filtered by node_modules, but just in case
|
|
91
|
+
if (file.startsWith(PW_CORE_PATH)) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function constructStackFromFrames(frames: StackFrame[]) {
|
|
97
|
+
const stackLines: string[] = [];
|
|
98
|
+
for (const frame of frames) {
|
|
99
|
+
stackLines.push(
|
|
100
|
+
` at ${frame.function ? frame.function + ' ' : ''}(${frame.file}:${
|
|
101
|
+
frame.line
|
|
102
|
+
}:${frame.column})`
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
return stackLines;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function prepareError(error: Error) {
|
|
109
|
+
const stack = error.stack;
|
|
110
|
+
const lines = stack.split('\n');
|
|
111
|
+
let startAt = lines.findIndex(line => line.startsWith(' at '));
|
|
112
|
+
if (startAt === -1) {
|
|
113
|
+
startAt = lines.length;
|
|
114
|
+
}
|
|
115
|
+
const message = lines.slice(0, startAt).join('\n');
|
|
116
|
+
const stackLines = lines.slice(startAt);
|
|
117
|
+
// figure out the location of the journey/step that throws the error and
|
|
118
|
+
// correct stack line corresponding to that error
|
|
119
|
+
const stackFrames: StackFrame[] = [];
|
|
120
|
+
for (const line of stackLines) {
|
|
121
|
+
const frame = prepareStackFrame(line);
|
|
122
|
+
if (!frame || !frame.file) {
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
stackFrames.push(frame);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
let location: Location | undefined;
|
|
129
|
+
if (stackFrames.length) {
|
|
130
|
+
const frame = stackFrames[0];
|
|
131
|
+
location = {
|
|
132
|
+
file: frame.file,
|
|
133
|
+
column: frame.column || 0,
|
|
134
|
+
line: frame.line || 0,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return {
|
|
139
|
+
message,
|
|
140
|
+
stack: constructStackFromFrames(stackFrames).join('\n'),
|
|
141
|
+
location,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export function highLightSource(location: Location): string {
|
|
146
|
+
if (!location) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
try {
|
|
151
|
+
const source = readFileSync(location.file, 'utf-8');
|
|
152
|
+
const code = codeFrameColumns(
|
|
153
|
+
source,
|
|
154
|
+
{ start: location },
|
|
155
|
+
{ highlightCode: true }
|
|
156
|
+
);
|
|
157
|
+
return code;
|
|
158
|
+
} catch (_) {
|
|
159
|
+
// ignore error
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// serializeError prefers receiving proper Errors, but since at runtime
|
|
164
|
+
// non Error exceptions can be thrown, it tolerates though. The
|
|
165
|
+
// redundant type Error | any expresses that.
|
|
166
|
+
export function serializeError(
|
|
167
|
+
error: Error | any,
|
|
168
|
+
highlightCode = true
|
|
169
|
+
): TestError {
|
|
170
|
+
if (!(error instanceof Error) || !error.stack) {
|
|
171
|
+
return { message: `thrown: ${inspect(error)}` };
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const testErr: TestError = { message: error.message };
|
|
175
|
+
const { message, stack, location } = prepareError(error);
|
|
176
|
+
testErr.message = message;
|
|
177
|
+
if (stack) {
|
|
178
|
+
testErr.stack = stack;
|
|
179
|
+
}
|
|
180
|
+
if (location && highlightCode) {
|
|
181
|
+
testErr.location = location;
|
|
182
|
+
testErr.source = highLightSource(testErr.location);
|
|
183
|
+
}
|
|
184
|
+
return testErr;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export function renderError(error: TestError) {
|
|
188
|
+
const summary = [];
|
|
189
|
+
// push empty string to add a new line before rendering error
|
|
190
|
+
summary.push('');
|
|
191
|
+
summary.push(error.message);
|
|
192
|
+
|
|
193
|
+
if (error.source) {
|
|
194
|
+
summary.push('');
|
|
195
|
+
summary.push(error.source);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (error.stack) {
|
|
199
|
+
summary.push('');
|
|
200
|
+
summary.push(gray(error.stack));
|
|
201
|
+
}
|
|
202
|
+
summary.join('');
|
|
203
|
+
|
|
204
|
+
return summary.join('\n');
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// strip color codes and ansi escape codes
|
|
208
|
+
const ansiRegex = new RegExp(
|
|
209
|
+
[
|
|
210
|
+
'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
|
|
211
|
+
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))',
|
|
212
|
+
].join('|'),
|
|
213
|
+
'g'
|
|
214
|
+
);
|
|
215
|
+
export function stripAnsiCodes(msg = '') {
|
|
216
|
+
return msg.replace(ansiRegex, '');
|
|
217
|
+
}
|