@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
package/dist/loader.js ADDED
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+ /**
3
+ * MIT License
4
+ *
5
+ * Copyright (c) 2020-present, Elastic NV
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in
15
+ * all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ * THE SOFTWARE.
24
+ *
25
+ */
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.loadTestFiles = void 0;
28
+ const process_1 = require("process");
29
+ const path_1 = require("path");
30
+ const core_1 = require("./core");
31
+ const logger_1 = require("./core/logger");
32
+ const expect_1 = require("./core/expect");
33
+ const helpers_1 = require("./helpers");
34
+ const resolvedCwd = (0, process_1.cwd)();
35
+ async function loadTestFiles(options, args) {
36
+ /**
37
+ * Transform `.ts` files out of the box by invoking
38
+ * the `ts-node` via `transpile-only` mode that compiles
39
+ * TS files without doing any extensive type checks.
40
+ *
41
+ * We must register `ts-node` _before_ loading inline
42
+ * scripts too because otherwise we will not be able to
43
+ * require `.ts` configuration files.
44
+ */
45
+ /* eslint-disable-next-line @typescript-eslint/no-var-requires */
46
+ require('ts-node').register({
47
+ transpileOnly: true,
48
+ compilerOptions: {
49
+ esModuleInterop: true,
50
+ allowJs: true,
51
+ target: 'es2020',
52
+ },
53
+ });
54
+ /**
55
+ * Preload modules before running the tests
56
+ */
57
+ const modules = [].concat(options.require || []).filter(Boolean);
58
+ for (const name of modules) {
59
+ if ((0, helpers_1.isDepInstalled)(name)) {
60
+ require(name);
61
+ }
62
+ else {
63
+ throw new Error(`cannot find module '${name}'`);
64
+ }
65
+ }
66
+ if (options.inline) {
67
+ const source = await readStdin();
68
+ loadInlineScript(source);
69
+ return;
70
+ }
71
+ /**
72
+ * Handle piped files by reading the STDIN
73
+ * ex: ls example/suites/*.js | npx @elastic/synthetics
74
+ */
75
+ const files = args.length > 0 ? args : (await readStdin()).split('\n').filter(Boolean);
76
+ const suites = await prepareSuites(files, options.pattern);
77
+ requireSuites(suites);
78
+ }
79
+ exports.loadTestFiles = loadTestFiles;
80
+ const loadInlineScript = source => {
81
+ const scriptFn = new Function('step', 'page', 'context', 'browser', 'params', 'expect', source);
82
+ (0, core_1.journey)('inline', ({ page, context, browser, params }) => {
83
+ scriptFn.apply(null, [core_1.step, page, context, browser, params, expect_1.expect]);
84
+ });
85
+ };
86
+ /**
87
+ * Read the input from STDIN and run it as inline journey
88
+ */
89
+ async function readStdin() {
90
+ const chunks = [];
91
+ process_1.stdin.resume();
92
+ process_1.stdin.setEncoding('utf-8');
93
+ for await (const chunk of process_1.stdin) {
94
+ chunks.push(chunk);
95
+ }
96
+ return chunks.join();
97
+ }
98
+ function requireSuites(suites) {
99
+ for (const suite of suites) {
100
+ require(suite);
101
+ }
102
+ }
103
+ /**
104
+ * Handle both directory and files that are passed through TTY
105
+ * and add them to suites
106
+ */
107
+ async function prepareSuites(inputs, filePattern) {
108
+ const suites = new Set();
109
+ const addSuite = absPath => {
110
+ (0, logger_1.log)(`Processing file: ${absPath}`);
111
+ suites.add(require.resolve(absPath));
112
+ };
113
+ /**
114
+ * Match all files inside the directory with the
115
+ * .journey.{mjs|cjs|js|ts) extensions
116
+ */
117
+ const pattern = filePattern
118
+ ? new RegExp(filePattern, 'i')
119
+ : /.+\.journey\.([mc]js|[jt]s?)$/;
120
+ /**
121
+ * Ignore node_modules by default when running suites
122
+ */
123
+ const ignored = /node_modules/i;
124
+ for (const input of inputs) {
125
+ const absPath = (0, path_1.resolve)(resolvedCwd, input);
126
+ /**
127
+ * Validate for package.json file before running
128
+ * the suites
129
+ */
130
+ (0, helpers_1.findPkgJsonByTraversing)(absPath, resolvedCwd);
131
+ if ((0, helpers_1.isDirectory)(absPath)) {
132
+ await (0, helpers_1.totalist)(absPath, (rel, abs) => {
133
+ if (pattern.test(rel) && !ignored.test(rel)) {
134
+ addSuite(abs);
135
+ }
136
+ });
137
+ }
138
+ else {
139
+ addSuite(absPath);
140
+ }
141
+ }
142
+ return suites.values();
143
+ }
144
+ //# sourceMappingURL=loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":";AAAA;;;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AAC;IACvC,CAAC,CAAC;IACF;;;OAGG;IACH,MAAM,OAAO,GAAG,WAAW;QACzB,CAAC,CAAC,IAAI,MAAM,CAAC,WAAW,EAAE,GAAG,CAAC;QAC9B,CAAC,CAAC,+BAA+B,CAAC;IACpC;;OAEG;IACH,MAAM,OAAO,GAAG,eAAe,CAAC;IAEhC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;QAC1B,MAAM,OAAO,GAAG,IAAA,cAAO,EAAC,WAAW,EAAE,KAAK,CAAC,CAAC;QAC5C;;;WAGG;QACH,IAAA,iCAAuB,EAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QAC9C,IAAI,IAAA,qBAAW,EAAC,OAAO,CAAC,EAAE;YACxB,MAAM,IAAA,kBAAQ,EAAC,OAAO,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;gBACnC,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;oBAC3C,QAAQ,CAAC,GAAG,CAAC,CAAC;iBACf;YACH,CAAC,CAAC,CAAC;SACJ;aAAM;YACL,QAAQ,CAAC,OAAO,CAAC,CAAC;SACnB;KACF;IACD,OAAO,MAAM,CAAC,MAAM,EAAE,CAAC;AACzB,CAAC"}
@@ -0,0 +1,34 @@
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
+ import type { CliArgs, RunOptions } from './common_types';
26
+ export declare function normalizeOptions(cliArgs: CliArgs): RunOptions;
27
+ /**
28
+ * Parses the throttling CLI settings and also
29
+ * adapts to the format to keep the backwards compatability
30
+ * - Accepts old format `<5d/3u/20l>`
31
+ * - Processess new format otherwise `{download: 5, upload: 3, latency: 20}`
32
+ */
33
+ export declare function parseThrottling(value: string, prev?: string): any;
34
+ //# sourceMappingURL=options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAKH,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAqB,MAAM,gBAAgB,CAAC;AAW7E,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,UAAU,CAqG7D;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,OAwB3D"}
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+ /**
3
+ * MIT License
4
+ *
5
+ * Copyright (c) 2020-present, Elastic NV
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in
15
+ * all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ * THE SOFTWARE.
24
+ *
25
+ */
26
+ var __importDefault = (this && this.__importDefault) || function (mod) {
27
+ return (mod && mod.__esModule) ? mod : { "default": mod };
28
+ };
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ exports.parseThrottling = exports.normalizeOptions = void 0;
31
+ const deepmerge_1 = __importDefault(require("deepmerge"));
32
+ const config_1 = require("./config");
33
+ const helpers_1 = require("./helpers");
34
+ /**
35
+ * Set debug based on DEBUG ENV and -d flags
36
+ * namespace - synthetics
37
+ */
38
+ const namespace = 'synthetics';
39
+ if (process.env.DEBUG && process.env.DEBUG.includes(namespace)) {
40
+ process.env.DEBUG = '1';
41
+ }
42
+ function normalizeOptions(cliArgs) {
43
+ const options = {
44
+ ...cliArgs,
45
+ environment: process.env['NODE_ENV'] || 'development',
46
+ };
47
+ /**
48
+ * Group all events that can be consumed by heartbeat and
49
+ * eventually by the Synthetics UI.
50
+ */
51
+ if (cliArgs.richEvents) {
52
+ options.reporter = cliArgs.reporter ?? 'json';
53
+ options.ssblocks = true;
54
+ options.network = true;
55
+ options.trace = true;
56
+ options.quietExitCode = true;
57
+ }
58
+ if (cliArgs.capability) {
59
+ const supportedCapabilities = [
60
+ 'trace',
61
+ 'network',
62
+ 'filmstrips',
63
+ 'metrics',
64
+ 'ssblocks',
65
+ ];
66
+ /**
67
+ * trace - record chrome trace events(LCP, FCP, CLS, etc.) for all journeys
68
+ * network - capture network information for all journeys
69
+ * filmstrips - record detailed filmstrips for all journeys
70
+ * metrics - capture performance metrics (DOM Nodes, Heap size, etc.) for each step
71
+ * ssblocks - Dedupes the screenshots in to blocks to save storage space
72
+ */
73
+ for (const flag of cliArgs.capability) {
74
+ if (supportedCapabilities.includes(flag)) {
75
+ options[flag] = true;
76
+ }
77
+ else {
78
+ console.warn(`Missing capability "${flag}", current supported capabilities are ${supportedCapabilities.join(', ')}`);
79
+ }
80
+ }
81
+ }
82
+ /**
83
+ * Validate and read synthetics config file
84
+ * based on the environment
85
+ */
86
+ const config = cliArgs.config || !cliArgs.inline
87
+ ? (0, config_1.readConfig)(options.environment, cliArgs.config)
88
+ : {};
89
+ /**
90
+ * Order of preference for options that are used while running are
91
+ * 1. Local options configured via Runner API
92
+ * 2. CLI flags
93
+ * 3. Configuration file
94
+ */
95
+ options.params = Object.freeze((0, deepmerge_1.default)(config.params, cliArgs.params || {}));
96
+ /**
97
+ * Merge playwright options from CLI and Synthetics config
98
+ * and prefer individual options over other option
99
+ */
100
+ const playwrightOpts = (0, deepmerge_1.default)(config.playwrightOptions, cliArgs.playwrightOptions || {});
101
+ options.playwrightOptions = {
102
+ ...playwrightOpts,
103
+ headless: cliArgs.headless,
104
+ chromiumSandbox: cliArgs.sandbox ?? playwrightOpts?.chromiumSandbox,
105
+ ignoreHTTPSErrors: cliArgs.ignoreHttpsErrors ?? playwrightOpts?.ignoreHTTPSErrors,
106
+ };
107
+ /**
108
+ * Get the default monitor config from synthetics.config.ts file
109
+ */
110
+ const monitor = config.monitor;
111
+ if (cliArgs.throttling) {
112
+ const throttleConfig = deepmerge_1.default.all([
113
+ helpers_1.DEFAULT_THROTTLING_OPTIONS,
114
+ monitor?.throttling || {},
115
+ cliArgs.throttling,
116
+ ]);
117
+ options.throttling = throttleConfig;
118
+ options.networkConditions = (0, helpers_1.getNetworkConditions)(throttleConfig);
119
+ }
120
+ else {
121
+ /**
122
+ * Do not apply throttling when `--no-throttling` flag is passed
123
+ */
124
+ options.throttling = {};
125
+ }
126
+ options.schedule = cliArgs.schedule ?? monitor?.schedule;
127
+ options.locations = cliArgs.locations ?? monitor?.locations;
128
+ return options;
129
+ }
130
+ exports.normalizeOptions = normalizeOptions;
131
+ /**
132
+ * Parses the throttling CLI settings and also
133
+ * adapts to the format to keep the backwards compatability
134
+ * - Accepts old format `<5d/3u/20l>`
135
+ * - Processess new format otherwise `{download: 5, upload: 3, latency: 20}`
136
+ */
137
+ function parseThrottling(value, prev) {
138
+ const THROTTLING_REGEX = /([0-9]{1,}u)|([0-9]{1,}d)|([0-9]{1,}l)/gm;
139
+ if (THROTTLING_REGEX.test(value)) {
140
+ const throttling = {};
141
+ const conditions = value.split('/');
142
+ conditions.forEach(condition => {
143
+ const setting = condition.slice(0, condition.length - 1);
144
+ const token = condition.slice(-1);
145
+ switch (token) {
146
+ case 'd':
147
+ throttling.download = Number(setting);
148
+ break;
149
+ case 'u':
150
+ throttling.upload = Number(setting);
151
+ break;
152
+ case 'l':
153
+ throttling.latency = Number(setting);
154
+ break;
155
+ }
156
+ });
157
+ return throttling;
158
+ }
159
+ return JSON.parse(value || prev);
160
+ }
161
+ exports.parseThrottling = parseThrottling;
162
+ //# sourceMappingURL=options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.js","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;;;;;;AAEH,0DAA8B;AAC9B,qCAAsC;AACtC,uCAA6E;AAG7E;;;GAGG;AACH,MAAM,SAAS,GAAG,YAAY,CAAC;AAC/B,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,IAAI,OAAO,CAAC,GAAG,CA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AI,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;QAChC,MAAM,UAAU,GAAsB,EAAE,CAAC;QACzC,MAAM,UAAU,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAEpC,UAAU,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;YAC7B,MAAM,OAAO,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;YACzD,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YAClC,QAAQ,KAAK,EAAE;gBACb,KAAK,GAAG;oBACN,UAAU,CAAC,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;oBACtC,MAAM;gBACR,KAAK,GAAG;oBACN,UAAU,CAAC,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;oBACpC,MAAM;gBACR,KAAK,GAAG;oBACN,UAAU,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;oBACrC,MAAM;aACT;QACH,CAAC,CAAC,CAAC;QACH,OAAO,UAAU,CAAC;KACnB;IACD,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC;AACnC,CAAC;AAxBD,0CAwBC"}
@@ -22,15 +22,16 @@
22
22
  * THE SOFTWARE.
23
23
  *
24
24
  */
25
- import { Page } from 'playwright-chromium';
26
- import { BrowserMessage } from '../common_types';
25
+ import { BrowserMessage, Driver } from '../common_types';
27
26
  import { Step } from '../dsl';
28
27
  export declare class BrowserConsole {
29
- private page;
28
+ private driver;
30
29
  private messages;
31
30
  _currentStep: Partial<Step>;
31
+ constructor(driver: Driver);
32
32
  private consoleEventListener;
33
- constructor(page: Page);
33
+ private pageErrorEventListener;
34
+ private enforceMessagesLimit;
34
35
  start(): void;
35
36
  stop(): BrowserMessage[];
36
37
  }
@@ -1 +1 @@
1
- {"version":3,"file":"browser-console.d.ts","sourceRoot":"","sources":["../../src/plugins/browser-console.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAK9B,qBAAa,cAAc;IAuBb,OAAO,CAAC,IAAI;IAtBxB,OAAO,CAAC,QAAQ,CAAwB;IACxC,YAAY,EAAE,OAAO,CAAC,IAAI,CAAC,CAAQ;IAEnC,OAAO,CAAC,oBAAoB,CAiB1B;gBAEkB,IAAI,EAAE,IAAI;IAE9B,KAAK;IAIL,IAAI;CAIL"}
1
+ {"version":3,"file":"browser-console.d.ts","sourceRoot":"","sources":["../../src/plugins/browser-console.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAK9B,qBAAa,cAAc;IAIb,OAAO,CAAC,MAAM;IAH1B,OAAO,CAAC,QAAQ,CAAwB;IACxC,YAAY,EAAE,OAAO,CAAC,IAAI,CAAC,CAAQ;gBAEf,MAAM,EAAE,MAAM;IAElC,OAAO,CAAC,oBAAoB,CAgB1B;IAEF,OAAO,CAAC,sBAAsB,CAc5B;IAEF,OAAO,CAAC,oBAAoB;IAM5B,KAAK;IAKL,IAAI;CAKL"}
@@ -28,8 +28,8 @@ exports.BrowserConsole = void 0;
28
28
  const helpers_1 = require("../helpers");
29
29
  const defaultMessageLimit = 1000;
30
30
  class BrowserConsole {
31
- constructor(page) {
32
- this.page = page;
31
+ constructor(driver) {
32
+ this.driver = driver;
33
33
  this.messages = [];
34
34
  this._currentStep = null;
35
35
  this.consoleEventListener = msg => {
@@ -40,22 +40,41 @@ class BrowserConsole {
40
40
  if (type === 'error' || type === 'warning') {
41
41
  const { name, index } = this._currentStep;
42
42
  this.messages.push({
43
- timestamp: helpers_1.getTimestamp(),
43
+ timestamp: (0, helpers_1.getTimestamp)(),
44
44
  text: msg.text(),
45
45
  type,
46
46
  step: { name, index },
47
47
  });
48
- if (this.messages.length > defaultMessageLimit) {
49
- this.messages.splice(0, 1);
50
- }
48
+ this.enforceMessagesLimit();
51
49
  }
52
50
  };
51
+ this.pageErrorEventListener = (error) => {
52
+ if (!this._currentStep) {
53
+ return;
54
+ }
55
+ const { name, index } = this._currentStep;
56
+ this.messages.push({
57
+ timestamp: (0, helpers_1.getTimestamp)(),
58
+ text: error.message,
59
+ type: 'error',
60
+ step: { name, index },
61
+ error,
62
+ });
63
+ this.enforceMessagesLimit();
64
+ };
65
+ }
66
+ enforceMessagesLimit() {
67
+ if (this.messages.length > defaultMessageLimit) {
68
+ this.messages.splice(0, 1);
69
+ }
53
70
  }
54
71
  start() {
55
- this.page.on('console', this.consoleEventListener);
72
+ this.driver.page.on('console', this.consoleEventListener);
73
+ this.driver.page.on('pageerror', this.pageErrorEventListener);
56
74
  }
57
75
  stop() {
58
- this.page.off('console', this.consoleEventListener);
76
+ this.driver.page.off('console', this.consoleEventListener);
77
+ this.driver.page.off('pageerror', this.pageErrorEventListener);
59
78
  return this.messages;
60
79
  }
61
80
  }
@@ -1 +1 @@
1
- {"version":3,"file":"browser-console.js","sourceRoot":"","sources":["../../src/plugins/browser-console.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;;;AAKH,wCAA0C;AAE1C,MAAM,mBAAmB,GAAG,IAAI,CAAC;AAEjC,MAAa,cAAc;IAuBzB,YAAoB,IAAU;QAAV,SAAI,GAAJ,IAAI,CAAM;QAtBtB,aAAQ,GAAqB,EAAE,CAAC;QACxC,iBAAY,GAAkB,IAAI,CAAC;QAE3B,yBAAoB,GAAG,GAAG,CAAC,EAAE;YACnC,IAAI,CAAC,I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,CAAC,SAAS,EAAE,IAAI,CAAC,oBAAoB,CAAC,CAAC;QAC1D,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,WAAW,EAAE,IAAI,CAAC,sBAAsB,CAAC,CAAC;IAChE,CAAC;IAED,IAAI;QACF,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,oBAAoB,CAAC,CAAC;QAC3D,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,CAAC,sBAAsB,CAAC,CAAC;QAC/D,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;CACF;AAxDD,wCAwDC"}
@@ -22,45 +22,32 @@
22
22
  * THE SOFTWARE.
23
23
  *
24
24
  */
25
- import { CDPSession } from 'playwright-chromium';
26
- import { Protocol } from 'playwright-chromium/types/protocol';
27
- import { NetworkInfo } from '../common_types';
25
+ import { NetworkInfo, Driver } from '../common_types';
28
26
  import { Step } from '../dsl';
27
+ /**
28
+ * Used as a key in each Network Request to identify the
29
+ * associated request across distinct lifecycle events
30
+ */
31
+ export declare const NETWORK_ENTRY_SUMBOL: unique symbol;
29
32
  export declare class NetworkManager {
33
+ private driver;
30
34
  private _browser;
31
- private _InflightRequestMap;
35
+ private _barrierPromises;
32
36
  results: Array<NetworkInfo>;
33
37
  _currentStep: Partial<Step>;
34
- start(client: CDPSession): Promise<void>;
35
- _findNetworkRecord(requestId: string): NetworkInfo;
36
- _onRequestWillBeSent(event: Protocol.Network.requestWillBeSentPayload): void;
37
- _onRequestWillBeSentExtraInfo(event: Protocol.Network.requestWillBeSentExtraInfoPayload): void;
38
- _onDataReceived(event: Protocol.Network.dataReceivedPayload): void;
39
- _onResponseReceived(event: Protocol.Network.responseReceivedPayload): void;
40
- _onLoadingFinished(event: Protocol.Network.loadingFinishedPayload): void;
41
- _onLoadingFailed(event: Protocol.Network.loadingFailedPayload): void;
42
- _requestCompleted(requestId: string, endTime: number, encodedDataLength?: number): void;
43
- /**
44
- * Account for missing response received event and also adjust the
45
- * response received event based on when first byte event was recorded
46
- */
47
- getResponseReceivedTime(timing: Protocol.Network.Response['timing'], responseReceivedTime: number): number;
38
+ constructor(driver: Driver);
48
39
  /**
49
- * The timing calculations are based on the chrome devtools frontend
50
- * https://github.com/ChromeDevTools/devtools-frontend/blob/7f5478d8ceb7586f23f4073ab5c2085dac1ec26a/front_end/network/RequestTimingView.js#L98-L193
40
+ * Adds a protection barrier aganist all asynchronous extract operations from
41
+ * request/response object that are happening during page lifecycle, If the
42
+ * page is closed during the extraction, the barrier enforces those operations
43
+ * to not result in exception
51
44
  */
52
- calculateTimings(record: NetworkInfo): {
53
- blocked: number;
54
- queueing: number;
55
- dns: number;
56
- ssl: number;
57
- proxy: number;
58
- connect: number;
59
- send: number;
60
- wait: number;
61
- receive: number;
62
- total: number;
63
- };
64
- stop(): NetworkInfo[];
45
+ private _addBarrier;
46
+ start(): Promise<void>;
47
+ private _findNetworkEntry;
48
+ private _onRequest;
49
+ private _onResponse;
50
+ private _onRequestCompleted;
51
+ stop(): Promise<NetworkInfo[]>;
65
52
  }
66
53
  //# sourceMappingURL=network.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../src/plugins/network.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAe,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAG9B,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAc;IAC9B,OAAO,CAAC,mBAAmB,CAAkC;IAC7D,OAAO,EAAE,KAAK,CAAC,WAAW,CAAC,CAAM;IACjC,YAAY,EAAE,OA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