@elastic/synthetics 1.0.0-beta.4 → 1.0.0-beta.41

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 (220) hide show
  1. package/README.md +4 -3
  2. package/dist/cli.js +137 -160
  3. package/dist/cli.js.map +1 -1
  4. package/dist/common_types.d.ts +161 -31
  5. package/dist/common_types.d.ts.map +1 -1
  6. package/dist/config.d.ts +3 -5
  7. package/dist/config.d.ts.map +1 -1
  8. package/dist/config.js +7 -6
  9. package/dist/config.js.map +1 -1
  10. package/dist/core/browser-service.d.ts +1 -1
  11. package/dist/core/browser-service.d.ts.map +1 -1
  12. package/dist/core/browser-service.js +7 -6
  13. package/dist/core/browser-service.js.map +1 -1
  14. package/dist/core/expect.d.ts +25 -25
  15. package/dist/core/expect.d.ts.map +1 -1
  16. package/dist/core/expect.js.map +1 -1
  17. package/dist/core/gatherer.d.ts +4 -8
  18. package/dist/core/gatherer.d.ts.map +1 -1
  19. package/dist/core/gatherer.js +53 -15
  20. package/dist/core/gatherer.js.map +1 -1
  21. package/dist/core/index.d.ts +5 -1
  22. package/dist/core/index.d.ts.map +1 -1
  23. package/dist/core/index.js +23 -11
  24. package/dist/core/index.js.map +1 -1
  25. package/dist/core/logger.d.ts +0 -1
  26. package/dist/core/logger.d.ts.map +1 -1
  27. package/dist/core/logger.js +3 -16
  28. package/dist/core/logger.js.map +1 -1
  29. package/dist/core/runner.d.ts +12 -63
  30. package/dist/core/runner.d.ts.map +1 -1
  31. package/dist/core/runner.js +156 -90
  32. package/dist/core/runner.js.map +1 -1
  33. package/dist/core/transform.d.ts +37 -0
  34. package/dist/core/transform.d.ts.map +1 -0
  35. package/dist/core/transform.js +148 -0
  36. package/dist/core/transform.js.map +1 -0
  37. package/dist/dsl/index.js +5 -1
  38. package/dist/dsl/index.js.map +1 -1
  39. package/dist/dsl/journey.d.ts +9 -4
  40. package/dist/dsl/journey.d.ts.map +1 -1
  41. package/dist/dsl/journey.js +37 -9
  42. package/dist/dsl/journey.js.map +1 -1
  43. package/dist/dsl/monitor.d.ts +83 -0
  44. package/dist/dsl/monitor.d.ts.map +1 -0
  45. package/dist/dsl/monitor.js +108 -0
  46. package/dist/dsl/monitor.js.map +1 -0
  47. package/dist/dsl/step.d.ts +3 -2
  48. package/dist/dsl/step.d.ts.map +1 -1
  49. package/dist/dsl/step.js +6 -1
  50. package/dist/dsl/step.js.map +1 -1
  51. package/dist/formatter/javascript.d.ts +98 -0
  52. package/dist/formatter/javascript.d.ts.map +1 -0
  53. package/dist/formatter/javascript.js +298 -0
  54. package/dist/formatter/javascript.js.map +1 -0
  55. package/dist/generator/index.d.ts +24 -0
  56. package/dist/generator/index.d.ts.map +1 -0
  57. package/dist/generator/index.js +241 -0
  58. package/dist/generator/index.js.map +1 -0
  59. package/dist/{reporters/reporter.js → generator/utils.d.ts} +5 -3
  60. package/dist/generator/utils.d.ts.map +1 -0
  61. package/dist/generator/utils.js +84 -0
  62. package/dist/generator/utils.js.map +1 -0
  63. package/dist/helpers.d.ts +28 -3
  64. package/dist/helpers.d.ts.map +1 -1
  65. package/dist/helpers.js +152 -20
  66. package/dist/helpers.js.map +1 -1
  67. package/dist/index.d.ts +6 -7
  68. package/dist/index.d.ts.map +1 -1
  69. package/dist/index.js +5 -26
  70. package/dist/index.js.map +1 -1
  71. package/dist/loader.d.ts +34 -0
  72. package/dist/loader.d.ts.map +1 -0
  73. package/dist/loader.js +149 -0
  74. package/dist/loader.js.map +1 -0
  75. package/dist/locations/index.d.ts +45 -0
  76. package/dist/locations/index.d.ts.map +1 -0
  77. package/dist/locations/index.js +83 -0
  78. package/dist/locations/index.js.map +1 -0
  79. package/dist/{reporters/reporter.d.ts → locations/public-locations.d.ts} +12 -8
  80. package/dist/locations/public-locations.d.ts.map +1 -0
  81. package/dist/locations/public-locations.js +41 -0
  82. package/dist/locations/public-locations.js.map +1 -0
  83. package/dist/options.d.ts +41 -0
  84. package/dist/options.d.ts.map +1 -0
  85. package/dist/options.js +198 -0
  86. package/dist/options.js.map +1 -0
  87. package/dist/plugins/browser-console.d.ts +5 -4
  88. package/dist/plugins/browser-console.d.ts.map +1 -1
  89. package/dist/plugins/browser-console.js +44 -24
  90. package/dist/plugins/browser-console.js.map +1 -1
  91. package/dist/plugins/index.js +5 -1
  92. package/dist/plugins/index.js.map +1 -1
  93. package/dist/plugins/network.d.ts +20 -33
  94. package/dist/plugins/network.d.ts.map +1 -1
  95. package/dist/plugins/network.js +177 -216
  96. package/dist/plugins/network.js.map +1 -1
  97. package/dist/plugins/performance.d.ts +4 -19
  98. package/dist/plugins/performance.d.ts.map +1 -1
  99. package/dist/plugins/performance.js +6 -5
  100. package/dist/plugins/performance.js.map +1 -1
  101. package/dist/plugins/plugin-manager.d.ts +9 -5
  102. package/dist/plugins/plugin-manager.d.ts.map +1 -1
  103. package/dist/plugins/plugin-manager.js +46 -30
  104. package/dist/plugins/plugin-manager.js.map +1 -1
  105. package/dist/plugins/tracing.d.ts +6 -6
  106. package/dist/plugins/tracing.d.ts.map +1 -1
  107. package/dist/plugins/tracing.js +10 -7
  108. package/dist/plugins/tracing.js.map +1 -1
  109. package/dist/push/bundler.d.ts +35 -0
  110. package/dist/push/bundler.d.ts.map +1 -0
  111. package/dist/push/bundler.js +131 -0
  112. package/dist/push/bundler.js.map +1 -0
  113. package/dist/push/index.d.ts +9 -0
  114. package/dist/push/index.d.ts.map +1 -0
  115. package/dist/push/index.js +227 -0
  116. package/dist/push/index.js.map +1 -0
  117. package/dist/push/kibana_api.d.ts +56 -0
  118. package/dist/push/kibana_api.d.ts.map +1 -0
  119. package/dist/push/kibana_api.js +135 -0
  120. package/dist/push/kibana_api.js.map +1 -0
  121. package/dist/push/monitor.d.ts +51 -0
  122. package/dist/push/monitor.d.ts.map +1 -0
  123. package/dist/push/monitor.js +244 -0
  124. package/dist/push/monitor.js.map +1 -0
  125. package/dist/{parse_args.d.ts → push/plugin.d.ts} +9 -6
  126. package/dist/push/plugin.d.ts.map +1 -0
  127. package/dist/push/plugin.js +66 -0
  128. package/dist/push/plugin.js.map +1 -0
  129. package/dist/push/request.d.ts +45 -0
  130. package/dist/push/request.d.ts.map +1 -0
  131. package/dist/push/request.js +109 -0
  132. package/dist/push/request.js.map +1 -0
  133. package/dist/push/utils.d.ts +31 -0
  134. package/dist/push/utils.d.ts.map +1 -0
  135. package/dist/push/utils.js +64 -0
  136. package/dist/push/utils.js.map +1 -0
  137. package/dist/reporters/base.d.ts +14 -6
  138. package/dist/reporters/base.d.ts.map +1 -1
  139. package/dist/reporters/base.js +58 -50
  140. package/dist/reporters/base.js.map +1 -1
  141. package/dist/reporters/index.d.ts +18 -8
  142. package/dist/reporters/index.d.ts.map +1 -1
  143. package/dist/reporters/index.js.map +1 -1
  144. package/dist/reporters/json.d.ts +17 -62
  145. package/dist/reporters/json.d.ts.map +1 -1
  146. package/dist/reporters/json.js +149 -179
  147. package/dist/reporters/json.js.map +1 -1
  148. package/dist/reporters/junit.d.ts +7 -1
  149. package/dist/reporters/junit.d.ts.map +1 -1
  150. package/dist/reporters/junit.js +90 -95
  151. package/dist/reporters/junit.js.map +1 -1
  152. package/dist/sdk/lh-trace-processor.d.ts +35 -9
  153. package/dist/sdk/lh-trace-processor.d.ts.map +1 -1
  154. package/dist/sdk/lh-trace-processor.js +114 -53
  155. package/dist/sdk/lh-trace-processor.js.map +1 -1
  156. package/dist/sdk/trace-metrics.d.ts +4 -4
  157. package/dist/sdk/trace-metrics.d.ts.map +1 -1
  158. package/dist/sdk/trace-metrics.js +3 -4
  159. package/dist/sdk/trace-metrics.js.map +1 -1
  160. package/dist/sdk/trace-processor.d.ts +11 -3
  161. package/dist/sdk/trace-processor.d.ts.map +1 -1
  162. package/dist/sdk/trace-processor.js +17 -9
  163. package/dist/sdk/trace-processor.js.map +1 -1
  164. package/package.json +39 -24
  165. package/src/cli.ts +219 -151
  166. package/src/common_types.ts +193 -31
  167. package/src/config.ts +3 -6
  168. package/src/core/expect.ts +58 -24
  169. package/src/core/gatherer.ts +64 -24
  170. package/src/core/index.ts +36 -15
  171. package/src/core/logger.ts +1 -12
  172. package/src/core/runner.ts +151 -136
  173. package/src/core/transform.ts +160 -0
  174. package/src/dsl/journey.ts +39 -6
  175. package/src/dsl/monitor.ts +140 -0
  176. package/src/dsl/step.ts +9 -2
  177. package/src/formatter/javascript.ts +367 -0
  178. package/src/generator/index.ts +308 -0
  179. package/src/generator/utils.ts +84 -0
  180. package/src/helpers.ts +159 -13
  181. package/src/index.ts +22 -22
  182. package/src/loader.ts +167 -0
  183. package/src/locations/index.ts +95 -0
  184. package/src/{reporters/reporter.ts → locations/public-locations.ts} +12 -9
  185. package/src/options.ts +227 -0
  186. package/src/plugins/browser-console.ts +30 -8
  187. package/src/plugins/network.ts +208 -267
  188. package/src/plugins/performance.ts +6 -22
  189. package/src/plugins/plugin-manager.ts +49 -31
  190. package/src/plugins/tracing.ts +8 -9
  191. package/src/push/bundler.ts +112 -0
  192. package/src/push/index.ts +282 -0
  193. package/src/push/kibana_api.ts +191 -0
  194. package/src/push/monitor.ts +276 -0
  195. package/src/push/plugin.ts +66 -0
  196. package/src/push/request.ts +141 -0
  197. package/src/push/utils.ts +77 -0
  198. package/src/reporters/base.ts +63 -52
  199. package/src/reporters/index.ts +26 -3
  200. package/src/reporters/json.ts +183 -202
  201. package/src/reporters/junit.ts +98 -93
  202. package/src/sdk/lh-trace-processor.ts +132 -68
  203. package/src/sdk/trace-metrics.ts +8 -4
  204. package/src/sdk/trace-processor.ts +28 -13
  205. package/templates/.github/workflows/run-synthetics.yml +27 -0
  206. package/templates/README.md +21 -0
  207. package/templates/journeys/advanced-example-helpers.ts +54 -0
  208. package/templates/journeys/advanced-example.journey.ts +43 -0
  209. package/templates/journeys/example.journey.ts +18 -0
  210. package/templates/lightweight/heartbeat.yml +8 -0
  211. package/templates/synthetics.config.ts +35 -0
  212. package/CHANGELOG.md +0 -131
  213. package/NOTICE.txt +0 -221
  214. package/dist/parse_args.d.ts.map +0 -1
  215. package/dist/parse_args.js +0 -95
  216. package/dist/parse_args.js.map +0 -1
  217. package/dist/reporters/reporter.d.ts.map +0 -1
  218. package/dist/reporters/reporter.js.map +0 -1
  219. package/dist/tsconfig.tsbuildinfo +0 -1888
  220. package/src/parse_args.ts +0 -135
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@elastic/synthetics",
3
- "version": "1.0.0-beta.4",
3
+ "version": "1.0.0-beta.41",
4
4
  "description": "Elastic synthetic monitoring agent",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "scripts": {
8
- "clean": "rm -rf dist",
8
+ "clean": "rimraf dist",
9
9
  "prepublish": "npm run clean && npm run build",
10
10
  "build": "tsc",
11
+ "build:locations": "sh utils/update_locations.sh",
11
12
  "watch": "tsc -w",
12
13
  "lint": "eslint . --rulesdir utils/eslint-rules",
13
14
  "lint:fix": "npm run lint -- --fix",
@@ -22,7 +23,8 @@
22
23
  },
23
24
  "files": [
24
25
  "dist",
25
- "src"
26
+ "src",
27
+ "templates"
26
28
  ],
27
29
  "lint-staged": {
28
30
  "*.{js,ts}": [
@@ -38,32 +40,45 @@
38
40
  "author": "",
39
41
  "license": "MIT",
40
42
  "dependencies": {
41
- "commander": "^7.0.0",
43
+ "archiver": "^5.3.1",
44
+ "commander": "^9.4.1",
42
45
  "deepmerge": "^4.2.2",
43
- "expect": "^27.0.2",
46
+ "enquirer": "^2.3.6",
47
+ "esbuild": "^0.16.10",
48
+ "expect": "^28.1.3",
44
49
  "http-proxy": "^1.18.1",
45
- "kleur": "^4.1.3",
46
- "micromatch": "^4.0.4",
47
- "playwright-chromium": "=1.11.0",
48
- "sharp": "^0.28.3",
49
- "snakecase-keys": "^3.2.1",
50
- "sonic-boom": "^1.3.0",
51
- "source-map-support": "^0.5.19",
52
- "ts-node": "^9.1.1",
53
- "typescript": "^4.1.3"
50
+ "kleur": "^4.1.5",
51
+ "micromatch": "^4.0.5",
52
+ "pirates": "^4.0.5",
53
+ "playwright-chromium": "=1.31.1",
54
+ "playwright-core": "=1.31.1",
55
+ "semver": "^7.3.8",
56
+ "sharp": "^0.31.1",
57
+ "snakecase-keys": "^4.0.1",
58
+ "sonic-boom": "^3.2.0",
59
+ "source-map-support": "^0.5.21",
60
+ "typescript": "^4.8.4",
61
+ "undici": "^5.11.0",
62
+ "yaml": "^2.1.3"
54
63
  },
55
64
  "devDependencies": {
56
- "@types/jest": "^26.0.19",
57
- "@types/micromatch": "^4.0.1",
58
- "@types/node": "^14.14.14",
59
- "@types/sharp": "^0.28.2",
60
- "@typescript-eslint/eslint-plugin": "^3.10.1",
61
- "@typescript-eslint/parser": "^3.10.1",
62
- "eslint": "^7.15.0",
65
+ "@types/jest": "^28.1.8",
66
+ "@types/micromatch": "^4.0.2",
67
+ "@types/node": "^16.11.59",
68
+ "@types/sharp": "^0.28.6",
69
+ "@typescript-eslint/eslint-plugin": "^5.38.0",
70
+ "@typescript-eslint/parser": "^5.38.0",
71
+ "eslint": "^8.23.1",
63
72
  "husky": "^4.3.6",
64
- "jest": "^26.6.3",
73
+ "is-positive": "3.1.0",
74
+ "jest": "^28.1.3",
65
75
  "lint-staged": "^10.5.3",
66
- "prettier": "^2.2.1",
67
- "ts-jest": "^26.4.4"
76
+ "prettier": "^2.7.1",
77
+ "rimraf": "^3.0.2",
78
+ "ts-jest": "^28.0.8",
79
+ "unzipper": "^0.10.11"
80
+ },
81
+ "engines": {
82
+ "node": ">=18.12.0"
68
83
  }
69
84
  }
package/src/cli.ts CHANGED
@@ -25,168 +25,236 @@
25
25
  *
26
26
  */
27
27
 
28
- import { stdin, cwd } from 'process';
29
- import { resolve } from 'path';
30
- import merge from 'deepmerge';
31
- import { step, journey } from './core';
32
- import { log } from './core/logger';
33
- import program, { options } from './parse_args';
28
+ import { program, Option } from 'commander';
29
+ import { cwd } from 'process';
30
+ import { CliArgs, PushOptions } from './common_types';
31
+ import { reporters } from './reporters';
34
32
  import {
35
- findPkgJsonByTraversing,
36
- isDepInstalled,
37
- isDirectory,
38
- totalist,
39
- } from './helpers';
33
+ normalizeOptions,
34
+ parseThrottling,
35
+ getCommonCommandOpts,
36
+ } from './options';
37
+ import { globalSetup } from './loader';
40
38
  import { run } from './';
41
- import { readConfig } from './config';
42
-
43
- const resolvedCwd = cwd();
44
- /**
45
- * Set debug based on DEBUG ENV and -d flags
46
- * namespace - synthetics
47
- */
48
- const namespace = 'synthetics';
49
- if (process.env.DEBUG === namespace || Boolean(options.debug)) {
50
- process.env.DEBUG = '1';
51
- }
52
-
53
- const loadInlineScript = source => {
54
- const scriptFn = new Function('step', 'page', 'browser', 'params', source);
55
- journey('inline', async ({ page, browser, params }) => {
56
- scriptFn.apply(null, [step, page, browser, params]);
57
- });
58
- };
59
-
60
- async function readStdin() {
61
- const chunks = [];
62
- stdin.resume();
63
- stdin.setEncoding('utf-8');
64
- for await (const chunk of stdin) {
65
- chunks.push(chunk);
66
- }
67
- return chunks.join();
68
- }
39
+ import { runner } from './core';
40
+ import { SyntheticsLocations } from './dsl/monitor';
41
+ import {
42
+ push,
43
+ loadSettings,
44
+ validateSettings,
45
+ catchIncorrectSettings,
46
+ } from './push';
47
+ import {
48
+ formatLocations,
49
+ getLocations,
50
+ renderLocations,
51
+ LocationCmdOptions,
52
+ } from './locations';
53
+ import { resolve } from 'path';
54
+ import { Generator } from './generator';
55
+ import { error } from './helpers';
56
+ import { LocationsMap } from './locations/public-locations';
57
+ import { createLightweightMonitors } from './push/monitor';
69
58
 
70
- function requireSuites(suites: Iterable<string>) {
71
- for (const suite of suites) {
72
- require(suite);
73
- }
74
- }
59
+ /* eslint-disable-next-line @typescript-eslint/no-var-requires */
60
+ const { name, version } = require('../package.json');
75
61
 
76
- /**
77
- * Handle both directory and files that are passed through TTY
78
- * and add them to suites
79
- */
80
- async function prepareSuites(inputs: string[]) {
81
- const suites = new Set<string>();
82
- const addSuite = absPath => {
83
- log(`Processing file: ${absPath}`);
84
- suites.add(require.resolve(absPath));
85
- };
86
- /**
87
- * Match all files inside the directory with the
88
- * .journey.{mjs|cjs|js|ts) extensions
89
- */
90
- const pattern = options.pattern
91
- ? new RegExp(options.pattern, 'i')
92
- : /.+\.journey\.([mc]js|[jt]s?)$/;
93
- /**
94
- * Ignore node_modules by default when running suites
95
- */
96
- const ignored = /node_modules/i;
62
+ const { params, pattern, tags, match, playwrightOpts } = getCommonCommandOpts();
97
63
 
98
- for (const input of inputs) {
99
- const absPath = resolve(resolvedCwd, input);
100
- /**
101
- * Validate for package.json file before running
102
- * the suites
103
- */
104
- findPkgJsonByTraversing(absPath, resolvedCwd);
105
- if (isDirectory(absPath)) {
106
- await totalist(absPath, (rel, abs) => {
107
- if (pattern.test(rel) && !ignored.test(rel)) {
108
- addSuite(abs);
64
+ program
65
+ .name(`npx ${name}`)
66
+ .usage('[options] [dir] [files] file')
67
+ .option(
68
+ '-c, --config <path>',
69
+ 'configuration path (default: synthetics.config.js)'
70
+ )
71
+ .addOption(pattern)
72
+ .addOption(tags)
73
+ .addOption(match)
74
+ .addOption(params)
75
+ .addOption(
76
+ new Option('--reporter <value>', `output reporter format`).choices(
77
+ Object.keys(reporters)
78
+ )
79
+ )
80
+ .option('--inline', 'Run inline journeys from heartbeat')
81
+ .option('-r, --require <modules...>', 'module(s) to preload')
82
+ .option('--no-headless', 'run browser in headful mode')
83
+ .option('--sandbox', 'enable chromium sandboxing')
84
+ .option('--rich-events', 'Mimics a heartbeat run')
85
+ .option(
86
+ '--capability <features...>',
87
+ 'Enable capabilities through feature flags'
88
+ )
89
+ .addOption(
90
+ new Option('--screenshots [flag]', 'take screenshots at end of each step')
91
+ .choices(['on', 'off', 'only-on-failure'])
92
+ .default('on')
93
+ )
94
+ .option(
95
+ '--dry-run',
96
+ "don't actually execute anything, report only registered journeys"
97
+ )
98
+ .option(
99
+ '--outfd <fd>',
100
+ 'specify a file descriptor for logs. Default is stdout',
101
+ parseInt
102
+ )
103
+ .option(
104
+ '--ws-endpoint <endpoint>',
105
+ 'Browser WebSocket endpoint to connect to'
106
+ )
107
+ .option(
108
+ '--pause-on-error',
109
+ 'pause on error until a keypress is made in the console. Useful during development'
110
+ )
111
+ .option(
112
+ '--ignore-https-errors',
113
+ 'ignores any HTTPS errors in sites being tested, including ones related to unrecognized certs or signatures. This can be insecure!'
114
+ )
115
+ .option(
116
+ '--quiet-exit-code',
117
+ 'always return 0 as an exit code status, regardless of test pass / fail. Only return > 0 exit codes on internal errors where the suite could not be run'
118
+ )
119
+ .option(
120
+ '--throttling <config>',
121
+ 'JSON object to throttle network conditions for download and upload throughput in megabits/second and latency in milliseconds. Ex: { "download": 10, "upload": 5, "latency": 200 }.',
122
+ parseThrottling,
123
+ {}
124
+ )
125
+ .option('--no-throttling', 'Turns off default network throttling.')
126
+ .addOption(playwrightOpts)
127
+ .version(version)
128
+ .description('Run synthetic tests')
129
+ .action(async (cliArgs: CliArgs) => {
130
+ const tearDown = await globalSetup(cliArgs, program.args);
131
+ try {
132
+ const options = normalizeOptions(cliArgs);
133
+ const results = await run(options);
134
+ /**
135
+ * Exit with error status if any journey fails
136
+ */
137
+ if (!options.quietExitCode) {
138
+ for (const result of Object.values(results)) {
139
+ if (result.status === 'failed') {
140
+ process.exit(1);
141
+ }
109
142
  }
110
- });
111
- } else {
112
- addSuite(absPath);
113
- }
114
- }
115
- return suites.values();
116
- }
117
-
118
- (async () => {
119
- if (options.inline) {
120
- const source = await readStdin();
121
- loadInlineScript(source);
122
- } else {
123
- /**
124
- * Preload modules before running the suites
125
- */
126
- const modules = [].concat(options.require || []).filter(Boolean);
127
- for (const name of modules) {
128
- if (isDepInstalled(name)) {
129
- require(name);
130
- } else {
131
- throw new Error(`cannot find module '${name}'`);
132
143
  }
144
+ } catch (e) {
145
+ console.error(e);
146
+ process.exit(1);
147
+ } finally {
148
+ tearDown();
133
149
  }
134
- /**
135
- * Transform `.ts` files out of the box by invoking
136
- * the `ts-node` via `transpile-only` mode that compiles
137
- * TS files without doing any extensive type checks
138
- */
139
- /* eslint-disable-next-line @typescript-eslint/no-var-requires */
140
- require('ts-node').register({
141
- transpileOnly: true,
142
- compilerOptions: {
143
- esModuleInterop: true,
144
- allowJs: true,
145
- target: 'es2018',
146
- },
147
- });
148
- /**
149
- * Handle piped files by reading the STDIN
150
- * ex: ls example/suites/*.js | npx @elastic/synthetics
151
- */
152
- const files =
153
- program.args.length > 0
154
- ? program.args
155
- : (await readStdin()).split('\n').filter(Boolean);
156
- const suites = await prepareSuites(files);
157
- requireSuites(suites);
158
- }
150
+ });
159
151
 
160
- /**
161
- * Use the NODE_ENV variable to control the environment
162
- */
163
- const environment = process.env['NODE_ENV'] || 'development';
164
- /**
165
- * Validate and handle configs
166
- */
167
- const config = readConfig(environment, options.config);
168
- const params = merge(config.params, JSON.parse(options.suiteParams));
169
- /**
170
- * use JSON reporter if json flag is enabled
171
- */
172
- const reporter = options.json ? 'json' : options.reporter;
152
+ // Push command
153
+ program
154
+ .command('push')
155
+ .description(
156
+ 'Push all journeys in the current directory to create monitors within the Kibana monitor management UI'
157
+ )
158
+ .addOption(
159
+ new Option(
160
+ '--auth <auth>',
161
+ 'API key used for Kibana authentication(https://www.elastic.co/guide/en/kibana/master/api-keys.html).'
162
+ )
163
+ .env('SYNTHETICS_API_KEY')
164
+ .makeOptionMandatory(true)
165
+ )
166
+ .option(
167
+ '--schedule <time-in-minutes>',
168
+ "schedule in minutes for the pushed monitors. Setting `10`, for example, configures monitors which don't have an interval defined to run every 10 minutes.",
169
+ parseInt
170
+ )
171
+ .addOption(
172
+ new Option(
173
+ '--locations <locations...>',
174
+ 'default list of locations from which your monitors will run.'
175
+ ).choices(SyntheticsLocations)
176
+ )
177
+ .option(
178
+ '--private-locations <locations...>',
179
+ 'default list of private locations from which your monitors will run.'
180
+ )
181
+ .option('--url <url>', 'Kibana URL to upload the monitors')
182
+ .option(
183
+ '--id <id>',
184
+ 'project id that will be used for logically grouping monitors'
185
+ )
186
+ .option(
187
+ '--space <space>',
188
+ 'the target Kibana spaces for the pushed monitors — spaces help you organise pushed monitors.'
189
+ )
190
+ .option('-y, --yes', 'skip all questions and run non-interactively')
191
+ .addOption(pattern)
192
+ .addOption(tags)
193
+ .addOption(match)
194
+ .addOption(params)
195
+ .addOption(playwrightOpts)
196
+ .action(async (cmdOpts: PushOptions) => {
197
+ const workDir = cwd();
198
+ const tearDown = await globalSetup({ inline: false, ...program.opts() }, [
199
+ workDir,
200
+ ]);
201
+ try {
202
+ const settings = await loadSettings();
203
+ const options = normalizeOptions({
204
+ ...program.opts(),
205
+ ...settings,
206
+ ...cmdOpts,
207
+ }) as PushOptions;
208
+ validateSettings(options);
209
+ await catchIncorrectSettings(settings, options);
210
+ const monitors = runner.buildMonitors(options);
211
+ monitors.push(...(await createLightweightMonitors(workDir, options)));
212
+ await push(monitors, options);
213
+ } catch (e) {
214
+ e && console.error(e);
215
+ process.exit(1);
216
+ } finally {
217
+ tearDown();
218
+ }
219
+ });
173
220
 
174
- const results = await run({
175
- params: Object.freeze(params),
176
- environment,
177
- reporter,
178
- ...options,
221
+ // Init command
222
+ program
223
+ .command('init [dir]')
224
+ .description('Initialize Elastic synthetics project')
225
+ .action(async (dir = '') => {
226
+ try {
227
+ const generator = await new Generator(resolve(process.cwd(), dir));
228
+ await generator.setup();
229
+ } catch (e) {
230
+ e && error(e);
231
+ process.exit(1);
232
+ }
179
233
  });
180
234
 
181
- /**
182
- * Exit with error status if any journey fails
183
- */
184
- for (const result of Object.values(results)) {
185
- if (result.status === 'failed') {
235
+ // Locations command
236
+ program
237
+ .command('locations')
238
+ .description(
239
+ `List all locations to run the synthetics monitors. Pass optional '--url' and '--auth' to list private locations.`
240
+ )
241
+ .option('--url <url>', 'Kibana URL to fetch all public and private locations')
242
+ .option(
243
+ '--auth <auth>',
244
+ 'API key used for Kibana authentication(https://www.elastic.co/guide/en/kibana/master/api-keys.html).'
245
+ )
246
+ .action(async (cmdOpts: LocationCmdOptions) => {
247
+ try {
248
+ let locations = Object.keys(LocationsMap);
249
+ if (cmdOpts.auth && cmdOpts.url) {
250
+ const allLocations = await getLocations(cmdOpts);
251
+ locations = formatLocations(allLocations);
252
+ }
253
+ renderLocations(locations);
254
+ } catch (e) {
255
+ e && error(e);
186
256
  process.exit(1);
187
257
  }
188
- }
189
- })().catch(e => {
190
- console.error(e);
191
- process.exit(1);
192
- });
258
+ });
259
+
260
+ program.parse(process.argv);