@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.
- package/README.md +5 -4
- package/dist/cli.js +139 -165
- package/dist/cli.js.map +1 -1
- package/dist/common_types.d.ts +158 -34
- package/dist/common_types.d.ts.map +1 -1
- package/dist/config.d.ts +1 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +7 -6
- package/dist/config.js.map +1 -1
- package/dist/core/browser-service.d.ts +1 -1
- package/dist/core/browser-service.d.ts.map +1 -1
- package/dist/core/browser-service.js +7 -6
- package/dist/core/browser-service.js.map +1 -1
- package/dist/core/expect.d.ts +25 -25
- package/dist/core/expect.d.ts.map +1 -1
- package/dist/core/expect.js.map +1 -1
- package/dist/core/gatherer.d.ts +5 -8
- package/dist/core/gatherer.d.ts.map +1 -1
- package/dist/core/gatherer.js +75 -17
- 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 +10 -17
- package/dist/core/logger.js.map +1 -1
- package/dist/core/runner.d.ts +12 -63
- package/dist/core/runner.d.ts.map +1 -1
- package/dist/core/runner.js +159 -92
- package/dist/core/runner.js.map +1 -1
- package/dist/core/transform.d.ts +37 -0
- package/dist/core/transform.d.ts.map +1 -0
- package/dist/core/transform.js +148 -0
- package/dist/core/transform.js.map +1 -0
- package/dist/dsl/index.js +5 -1
- package/dist/dsl/index.js.map +1 -1
- package/dist/dsl/journey.d.ts +9 -7
- package/dist/dsl/journey.d.ts.map +1 -1
- package/dist/dsl/journey.js +32 -39
- package/dist/dsl/journey.js.map +1 -1
- package/dist/dsl/monitor.d.ts +93 -0
- package/dist/dsl/monitor.d.ts.map +1 -0
- package/dist/dsl/monitor.js +110 -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 +6 -1
- package/dist/dsl/step.js.map +1 -1
- package/dist/formatter/javascript.d.ts +115 -0
- package/dist/formatter/javascript.d.ts.map +1 -0
- package/dist/formatter/javascript.js +331 -0
- package/dist/formatter/javascript.js.map +1 -0
- package/dist/generator/index.d.ts +24 -0
- package/dist/generator/index.d.ts.map +1 -0
- package/dist/generator/index.js +241 -0
- package/dist/generator/index.js.map +1 -0
- package/dist/{reporters/reporter.js → generator/utils.d.ts} +5 -3
- package/dist/generator/utils.d.ts.map +1 -0
- package/dist/generator/utils.js +84 -0
- package/dist/generator/utils.js.map +1 -0
- package/dist/helpers.d.ts +36 -9
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.js +170 -24
- package/dist/helpers.js.map +1 -1
- package/dist/index.d.ts +5 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -26
- package/dist/index.js.map +1 -1
- package/dist/loader.d.ts +34 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +153 -0
- package/dist/loader.js.map +1 -0
- package/dist/locations/index.d.ts +45 -0
- package/dist/locations/index.d.ts.map +1 -0
- package/dist/locations/index.js +83 -0
- package/dist/locations/index.js.map +1 -0
- package/dist/{reporters/reporter.d.ts → locations/public-locations.d.ts} +12 -8
- package/dist/locations/public-locations.d.ts.map +1 -0
- package/dist/locations/public-locations.js +41 -0
- package/dist/locations/public-locations.js.map +1 -0
- package/dist/options.d.ts +42 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/options.js +146 -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 +47 -24
- package/dist/plugins/browser-console.js.map +1 -1
- package/dist/plugins/index.js +5 -1
- package/dist/plugins/index.js.map +1 -1
- package/dist/plugins/network.d.ts +24 -31
- package/dist/plugins/network.d.ts.map +1 -1
- package/dist/plugins/network.js +226 -229
- 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 +6 -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 +46 -30
- 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 +13 -7
- package/dist/plugins/tracing.js.map +1 -1
- package/dist/push/bundler.d.ts +35 -0
- package/dist/push/bundler.d.ts.map +1 -0
- package/dist/push/bundler.js +131 -0
- package/dist/push/bundler.js.map +1 -0
- package/dist/push/index.d.ts +10 -0
- package/dist/push/index.d.ts.map +1 -0
- package/dist/push/index.js +235 -0
- package/dist/push/index.js.map +1 -0
- package/dist/push/kibana_api.d.ts +56 -0
- package/dist/push/kibana_api.d.ts.map +1 -0
- package/dist/push/kibana_api.js +135 -0
- package/dist/push/kibana_api.js.map +1 -0
- package/dist/push/monitor.d.ts +55 -0
- package/dist/push/monitor.d.ts.map +1 -0
- package/dist/push/monitor.js +268 -0
- package/dist/push/monitor.js.map +1 -0
- package/dist/{parse_args.d.ts → push/plugin.d.ts} +9 -6
- package/dist/push/plugin.d.ts.map +1 -0
- package/dist/push/plugin.js +66 -0
- package/dist/push/plugin.js.map +1 -0
- package/dist/push/request.d.ts +45 -0
- package/dist/push/request.d.ts.map +1 -0
- package/dist/push/request.js +109 -0
- package/dist/push/request.js.map +1 -0
- package/dist/push/utils.d.ts +31 -0
- package/dist/push/utils.d.ts.map +1 -0
- package/dist/push/utils.js +64 -0
- package/dist/push/utils.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 +58 -50
- 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 +17 -62
- package/dist/reporters/json.d.ts.map +1 -1
- package/dist/reporters/json.js +147 -177
- 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 +90 -95
- 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 +3 -4
- 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/package.json +38 -30
- package/src/cli.ts +223 -158
- package/src/common_types.ts +191 -34
- package/src/config.ts +1 -1
- package/src/core/expect.ts +58 -24
- package/src/core/gatherer.ts +92 -25
- package/src/core/index.ts +36 -15
- package/src/core/logger.ts +8 -12
- package/src/core/runner.ts +158 -148
- package/src/core/transform.ts +160 -0
- package/src/dsl/journey.ts +41 -21
- package/src/dsl/monitor.ts +152 -0
- package/src/dsl/step.ts +9 -2
- package/src/formatter/javascript.ts +414 -0
- package/src/generator/index.ts +308 -0
- package/src/generator/utils.ts +84 -0
- package/src/helpers.ts +182 -16
- package/src/index.ts +21 -22
- package/src/loader.ts +171 -0
- package/src/locations/index.ts +95 -0
- package/src/{reporters/reporter.ts → locations/public-locations.ts} +12 -9
- package/src/options.ts +175 -0
- package/src/plugins/browser-console.ts +33 -8
- package/src/plugins/network.ts +266 -284
- package/src/plugins/performance.ts +6 -22
- package/src/plugins/plugin-manager.ts +49 -31
- package/src/plugins/tracing.ts +11 -9
- package/src/push/bundler.ts +112 -0
- package/src/push/index.ts +291 -0
- package/src/push/kibana_api.ts +191 -0
- package/src/push/monitor.ts +307 -0
- package/src/push/plugin.ts +66 -0
- package/src/push/request.ts +141 -0
- package/src/push/utils.ts +77 -0
- package/src/reporters/base.ts +63 -52
- package/src/reporters/index.ts +26 -3
- package/src/reporters/json.ts +181 -201
- package/src/reporters/junit.ts +98 -93
- package/src/sdk/lh-trace-processor.ts +132 -68
- package/src/sdk/trace-metrics.ts +8 -4
- package/src/sdk/trace-processor.ts +28 -13
- package/templates/.github/workflows/run-synthetics.yml +27 -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/lightweight/heartbeat.yml +9 -0
- package/templates/synthetics.config.ts +35 -0
- package/CHANGELOG.md +0 -181
- package/NOTICE.txt +0 -221
- package/dist/parse_args.d.ts.map +0 -1
- package/dist/parse_args.js +0 -98
- 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/dist/tsconfig.tsbuildinfo +0 -1895
- package/src/parse_args.ts +0 -146
package/src/loader.ts
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
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 { stdin, cwd } from 'process';
|
|
27
|
+
import { extname, resolve } from 'path';
|
|
28
|
+
import { CliArgs } from './common_types';
|
|
29
|
+
import { step, journey } from './core';
|
|
30
|
+
import { log } from './core/logger';
|
|
31
|
+
import { expect } from './core/expect';
|
|
32
|
+
import {
|
|
33
|
+
isDepInstalled,
|
|
34
|
+
isDirectory,
|
|
35
|
+
totalist,
|
|
36
|
+
findPkgJsonByTraversing,
|
|
37
|
+
} from './helpers';
|
|
38
|
+
import { installTransform } from './core/transform';
|
|
39
|
+
|
|
40
|
+
const resolvedCwd = cwd();
|
|
41
|
+
const JOURNEY_EXTENSIONS = ['.js', '.ts', '.mjs', '.cjs'];
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Perform global setup process required for running the test suites
|
|
45
|
+
* and also for bundling the monitors. The process includes
|
|
46
|
+
* - Transpiling the TS/JS test files
|
|
47
|
+
* - Loading these files for running test suites
|
|
48
|
+
*/
|
|
49
|
+
export async function globalSetup(options: CliArgs, args: string[]) {
|
|
50
|
+
const revert = installTransform();
|
|
51
|
+
await loadTestFiles(options, args);
|
|
52
|
+
return () => {
|
|
53
|
+
revert();
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export async function loadTestFiles(options: CliArgs, args: string[]) {
|
|
58
|
+
/**
|
|
59
|
+
* Preload modules before running the tests
|
|
60
|
+
*/
|
|
61
|
+
const modules = [].concat(options.require || []).filter(Boolean);
|
|
62
|
+
for (const name of modules) {
|
|
63
|
+
if (isDepInstalled(name)) {
|
|
64
|
+
require(name);
|
|
65
|
+
} else {
|
|
66
|
+
throw new Error(`cannot find module '${name}'`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (options.inline) {
|
|
71
|
+
const source = await readStdin();
|
|
72
|
+
loadInlineScript(source);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Handle piped files by reading the STDIN
|
|
77
|
+
* ex: ls example/suites/*.js | npx @elastic/synthetics
|
|
78
|
+
*/
|
|
79
|
+
const files =
|
|
80
|
+
args.length > 0 ? args : (await readStdin()).split('\n').filter(Boolean);
|
|
81
|
+
const suites = await prepareSuites(files, options.pattern);
|
|
82
|
+
requireSuites(suites);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const loadInlineScript = source => {
|
|
86
|
+
const scriptFn = new Function(
|
|
87
|
+
'step',
|
|
88
|
+
'page',
|
|
89
|
+
'context',
|
|
90
|
+
'browser',
|
|
91
|
+
'params',
|
|
92
|
+
'expect',
|
|
93
|
+
'request',
|
|
94
|
+
source
|
|
95
|
+
);
|
|
96
|
+
journey('inline', ({ page, context, browser, params, request }) => {
|
|
97
|
+
scriptFn.apply(null, [
|
|
98
|
+
step,
|
|
99
|
+
page,
|
|
100
|
+
context,
|
|
101
|
+
browser,
|
|
102
|
+
params,
|
|
103
|
+
expect,
|
|
104
|
+
request,
|
|
105
|
+
]);
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Read the input from STDIN and run it as inline journey
|
|
111
|
+
*/
|
|
112
|
+
async function readStdin() {
|
|
113
|
+
const chunks = [];
|
|
114
|
+
stdin.resume();
|
|
115
|
+
stdin.setEncoding('utf-8');
|
|
116
|
+
for await (const chunk of stdin) {
|
|
117
|
+
chunks.push(chunk);
|
|
118
|
+
}
|
|
119
|
+
return chunks.join();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function requireSuites(suites: Iterable<string>) {
|
|
123
|
+
for (const suite of suites) {
|
|
124
|
+
require(suite);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Handle both directory and files that are passed through TTY
|
|
130
|
+
* and add them to suites
|
|
131
|
+
*/
|
|
132
|
+
async function prepareSuites(inputs: string[], filePattern?: string) {
|
|
133
|
+
const suites = new Set<string>();
|
|
134
|
+
const addSuite = absPath => {
|
|
135
|
+
if (!JOURNEY_EXTENSIONS.includes(extname(absPath))) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
log(`Processing file: ${absPath}`);
|
|
139
|
+
suites.add(require.resolve(absPath));
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* Match all files inside the directory with the
|
|
143
|
+
* .journey.{mjs|cjs|js|ts) extensions
|
|
144
|
+
*/
|
|
145
|
+
const pattern = filePattern
|
|
146
|
+
? new RegExp(filePattern, 'i')
|
|
147
|
+
: /.+\.journey\.([mc]js|[jt]s?)$/;
|
|
148
|
+
/**
|
|
149
|
+
* Ignore node_modules by default when running suites
|
|
150
|
+
*/
|
|
151
|
+
const ignored = /node_modules/i;
|
|
152
|
+
|
|
153
|
+
for (const input of inputs) {
|
|
154
|
+
const absPath = resolve(resolvedCwd, input);
|
|
155
|
+
/**
|
|
156
|
+
* Validate for package.json file before running
|
|
157
|
+
* the suites
|
|
158
|
+
*/
|
|
159
|
+
findPkgJsonByTraversing(absPath, resolvedCwd);
|
|
160
|
+
if (isDirectory(absPath)) {
|
|
161
|
+
await totalist(absPath, (rel, abs) => {
|
|
162
|
+
if (pattern.test(rel) && !ignored.test(rel)) {
|
|
163
|
+
addSuite(abs);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
} else {
|
|
167
|
+
addSuite(absPath);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return suites.values();
|
|
171
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
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 { sendReqAndHandleError } from '../push/request';
|
|
27
|
+
import { indent, write } from '../helpers';
|
|
28
|
+
import { generateURL } from '../push/utils';
|
|
29
|
+
|
|
30
|
+
export type LocationCmdOptions = {
|
|
31
|
+
auth: string;
|
|
32
|
+
url: string;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
type LocationMetadata = {
|
|
36
|
+
id: string;
|
|
37
|
+
label: string;
|
|
38
|
+
isServiceManaged: boolean;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export type LocationAPIResponse = {
|
|
42
|
+
locations: Array<LocationMetadata>;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const PRIVATE_KEYWORD = '(private)';
|
|
46
|
+
|
|
47
|
+
export async function getLocations(options: LocationCmdOptions) {
|
|
48
|
+
const resp = await sendReqAndHandleError<LocationAPIResponse>({
|
|
49
|
+
url: generateURL(options, 'location'),
|
|
50
|
+
method: 'GET',
|
|
51
|
+
auth: options.auth,
|
|
52
|
+
});
|
|
53
|
+
return resp.locations;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function formatLocations(locations: Array<LocationMetadata>) {
|
|
57
|
+
const formatted: Array<string> = [];
|
|
58
|
+
for (const location of locations) {
|
|
59
|
+
let name = location.label;
|
|
60
|
+
if (location.isServiceManaged) {
|
|
61
|
+
[, name] = name.includes('-') ? name.split('-') : [, name];
|
|
62
|
+
name = name.toLowerCase().trim().split(' ').join('_');
|
|
63
|
+
} else {
|
|
64
|
+
name = `${name}${PRIVATE_KEYWORD}`;
|
|
65
|
+
}
|
|
66
|
+
formatted.push(name);
|
|
67
|
+
}
|
|
68
|
+
return formatted;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function groupLocations(locations: Array<string>) {
|
|
72
|
+
const grouped = { locations: [], privateLocations: [] };
|
|
73
|
+
for (const loc of locations) {
|
|
74
|
+
if (loc.includes(PRIVATE_KEYWORD)) {
|
|
75
|
+
grouped.privateLocations.push(loc.replace(PRIVATE_KEYWORD, ''));
|
|
76
|
+
} else {
|
|
77
|
+
grouped.locations.push(loc);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return grouped;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function renderLocations(locations: Array<string>) {
|
|
84
|
+
let outer = 'Available locations: \n';
|
|
85
|
+
let inner = '';
|
|
86
|
+
for (const location of locations) {
|
|
87
|
+
inner += `* ${location}\n`;
|
|
88
|
+
}
|
|
89
|
+
outer += indent(inner);
|
|
90
|
+
outer += `\nSet default location for monitors via
|
|
91
|
+
- Synthetics config file 'monitors.locations' | 'monitors.privateLocations' field
|
|
92
|
+
- Monitor API 'monitor.use({ locations: ["japan"], privateLocations: ["custom-location"] }')`;
|
|
93
|
+
|
|
94
|
+
write(outer);
|
|
95
|
+
}
|
|
@@ -23,13 +23,16 @@
|
|
|
23
23
|
*
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
// DO NOT EDIT - UPDATE WITH `npm run build:locations`
|
|
27
|
+
export const LocationsMap = {
|
|
28
|
+
japan: 'asia-northeast1-a',
|
|
29
|
+
india: 'asia-south1-a',
|
|
30
|
+
singapore: 'asia-southeast1-a',
|
|
31
|
+
australia_east: 'australia-southeast1-a',
|
|
32
|
+
united_kingdom: 'europe-west2-a',
|
|
33
|
+
germany: 'europe-west3-a',
|
|
34
|
+
canada_east: 'northamerica-northeast1-a',
|
|
35
|
+
brazil: 'southamerica-east1-a',
|
|
36
|
+
us_east: 'us-east4-a',
|
|
37
|
+
us_west: 'us-west1-a',
|
|
31
38
|
};
|
|
32
|
-
|
|
33
|
-
export default interface Reporter {
|
|
34
|
-
new (runner: Runner, options: ReporterOptions): any;
|
|
35
|
-
}
|
package/src/options.ts
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
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 merge from 'deepmerge';
|
|
27
|
+
import { createOption } from 'commander';
|
|
28
|
+
import { readConfig } from './config';
|
|
29
|
+
import type { CliArgs, RunOptions } from './common_types';
|
|
30
|
+
import { THROTTLING_WARNING_MSG, warn } from './helpers';
|
|
31
|
+
|
|
32
|
+
export function normalizeOptions(cliArgs: CliArgs): RunOptions {
|
|
33
|
+
const options: RunOptions = {
|
|
34
|
+
...cliArgs,
|
|
35
|
+
environment: process.env['NODE_ENV'] || 'development',
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Group all events that can be consumed by heartbeat and
|
|
39
|
+
* eventually by the Synthetics UI.
|
|
40
|
+
*/
|
|
41
|
+
if (cliArgs.richEvents) {
|
|
42
|
+
options.reporter = cliArgs.reporter ?? 'json';
|
|
43
|
+
options.ssblocks = true;
|
|
44
|
+
options.network = true;
|
|
45
|
+
options.trace = true;
|
|
46
|
+
options.quietExitCode = true;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (cliArgs.capability) {
|
|
50
|
+
const supportedCapabilities = [
|
|
51
|
+
'trace',
|
|
52
|
+
'network',
|
|
53
|
+
'filmstrips',
|
|
54
|
+
'metrics',
|
|
55
|
+
'ssblocks',
|
|
56
|
+
];
|
|
57
|
+
/**
|
|
58
|
+
* trace - record chrome trace events(LCP, FCP, CLS, etc.) for all journeys
|
|
59
|
+
* network - capture network information for all journeys
|
|
60
|
+
* filmstrips - record detailed filmstrips for all journeys
|
|
61
|
+
* metrics - capture performance metrics (DOM Nodes, Heap size, etc.) for each step
|
|
62
|
+
* ssblocks - Dedupes the screenshots in to blocks to save storage space
|
|
63
|
+
*/
|
|
64
|
+
for (const flag of cliArgs.capability) {
|
|
65
|
+
if (supportedCapabilities.includes(flag)) {
|
|
66
|
+
options[flag] = true;
|
|
67
|
+
} else {
|
|
68
|
+
console.warn(
|
|
69
|
+
`Missing capability "${flag}", current supported capabilities are ${supportedCapabilities.join(
|
|
70
|
+
', '
|
|
71
|
+
)}`
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Validate and read synthetics config file
|
|
79
|
+
* based on the environment
|
|
80
|
+
*/
|
|
81
|
+
const config =
|
|
82
|
+
cliArgs.config || !cliArgs.inline
|
|
83
|
+
? readConfig(options.environment, cliArgs.config)
|
|
84
|
+
: {};
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Order of preference for options that are used while running are
|
|
88
|
+
* 1. Local options configured via Runner API
|
|
89
|
+
* 2. CLI flags
|
|
90
|
+
* 3. Configuration file
|
|
91
|
+
*/
|
|
92
|
+
options.params = Object.freeze(merge(config.params, cliArgs.params || {}));
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Merge playwright options from CLI and Synthetics config
|
|
96
|
+
* and prefer individual options over other option
|
|
97
|
+
*/
|
|
98
|
+
const playwrightOpts = merge(
|
|
99
|
+
config.playwrightOptions,
|
|
100
|
+
cliArgs.playwrightOptions || {}
|
|
101
|
+
);
|
|
102
|
+
options.playwrightOptions = {
|
|
103
|
+
...playwrightOpts,
|
|
104
|
+
chromiumSandbox: cliArgs.sandbox ?? playwrightOpts?.chromiumSandbox,
|
|
105
|
+
ignoreHTTPSErrors:
|
|
106
|
+
cliArgs.ignoreHttpsErrors ?? playwrightOpts?.ignoreHTTPSErrors,
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Get the default monitor config from synthetics.config.ts file
|
|
111
|
+
*/
|
|
112
|
+
const monitor = config.monitor;
|
|
113
|
+
|
|
114
|
+
options.schedule = cliArgs.schedule ?? monitor?.schedule;
|
|
115
|
+
options.locations = cliArgs.locations ?? monitor?.locations;
|
|
116
|
+
options.privateLocations =
|
|
117
|
+
cliArgs.privateLocations ?? monitor?.privateLocations;
|
|
118
|
+
|
|
119
|
+
return options;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
|
|
123
|
+
function toObject(value: boolean | Record<string, any>): Record<string, any> {
|
|
124
|
+
const defaulVal = {};
|
|
125
|
+
if (typeof value === 'boolean') {
|
|
126
|
+
return defaulVal;
|
|
127
|
+
}
|
|
128
|
+
return value || defaulVal;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Parses the throttling CLI settings with `{download: 5, upload: 3, latency:
|
|
133
|
+
* 20}` format
|
|
134
|
+
*
|
|
135
|
+
* Since throttling is disabled for now, we warn the users if throttling/nothrottling
|
|
136
|
+
* flag is passed to the CLI
|
|
137
|
+
*/
|
|
138
|
+
export function parseThrottling() {
|
|
139
|
+
warn(THROTTLING_WARNING_MSG);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function getCommonCommandOpts() {
|
|
143
|
+
const params = createOption(
|
|
144
|
+
'-p, --params <jsonstring>',
|
|
145
|
+
'JSON object that gets injected to all journeys'
|
|
146
|
+
);
|
|
147
|
+
params.argParser(JSON.parse);
|
|
148
|
+
|
|
149
|
+
const playwrightOpts = createOption(
|
|
150
|
+
'--playwright-options <jsonstring>',
|
|
151
|
+
'JSON object to pass in custom Playwright options for the agent. Options passed will be merged with Playwright options defined in your synthetics.config.js file.'
|
|
152
|
+
);
|
|
153
|
+
playwrightOpts.argParser(JSON.parse);
|
|
154
|
+
|
|
155
|
+
const pattern = createOption(
|
|
156
|
+
'--pattern <pattern>',
|
|
157
|
+
'RegExp pattern to match journey/monitor files that are different from the default (ex: /*.journey.(ts|js)$/)'
|
|
158
|
+
);
|
|
159
|
+
const tags = createOption(
|
|
160
|
+
'--tags <name...>',
|
|
161
|
+
'run/push tests with a tag that matches the glob'
|
|
162
|
+
);
|
|
163
|
+
const match = createOption(
|
|
164
|
+
'--match <name>',
|
|
165
|
+
'run/push tests with a name or tags that matches the glob'
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
return {
|
|
169
|
+
params,
|
|
170
|
+
playwrightOpts,
|
|
171
|
+
pattern,
|
|
172
|
+
tags,
|
|
173
|
+
match,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
*
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
26
|
+
import { BrowserMessage, Driver } from '../common_types';
|
|
27
|
+
import { log } from '../core/logger';
|
|
28
28
|
import { Step } from '../dsl';
|
|
29
29
|
import { getTimestamp } from '../helpers';
|
|
30
30
|
|
|
@@ -34,6 +34,8 @@ export class BrowserConsole {
|
|
|
34
34
|
private messages: BrowserMessage[] = [];
|
|
35
35
|
_currentStep: Partial<Step> = null;
|
|
36
36
|
|
|
37
|
+
constructor(private driver: Driver) {}
|
|
38
|
+
|
|
37
39
|
private consoleEventListener = msg => {
|
|
38
40
|
if (!this._currentStep) {
|
|
39
41
|
return;
|
|
@@ -47,20 +49,43 @@ export class BrowserConsole {
|
|
|
47
49
|
type,
|
|
48
50
|
step: { name, index },
|
|
49
51
|
});
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
|
|
53
|
+
this.enforceMessagesLimit();
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
private pageErrorEventListener = (error: Error) => {
|
|
58
|
+
if (!this._currentStep) {
|
|
59
|
+
return;
|
|
53
60
|
}
|
|
61
|
+
const { name, index } = this._currentStep;
|
|
62
|
+
this.messages.push({
|
|
63
|
+
timestamp: getTimestamp(),
|
|
64
|
+
text: error.message,
|
|
65
|
+
type: 'error',
|
|
66
|
+
step: { name, index },
|
|
67
|
+
error,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
this.enforceMessagesLimit();
|
|
54
71
|
};
|
|
55
72
|
|
|
56
|
-
|
|
73
|
+
private enforceMessagesLimit() {
|
|
74
|
+
if (this.messages.length > defaultMessageLimit) {
|
|
75
|
+
this.messages.splice(0, 1);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
57
78
|
|
|
58
79
|
start() {
|
|
59
|
-
|
|
80
|
+
log(`Plugins: started collecting console events`);
|
|
81
|
+
this.driver.page.on('console', this.consoleEventListener);
|
|
82
|
+
this.driver.page.on('pageerror', this.pageErrorEventListener);
|
|
60
83
|
}
|
|
61
84
|
|
|
62
85
|
stop() {
|
|
63
|
-
this.page.off('console', this.consoleEventListener);
|
|
86
|
+
this.driver.page.off('console', this.consoleEventListener);
|
|
87
|
+
this.driver.page.off('pageerror', this.pageErrorEventListener);
|
|
88
|
+
log(`Plugins: stopped collecting console events`);
|
|
64
89
|
return this.messages;
|
|
65
90
|
}
|
|
66
91
|
}
|