@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/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@elastic/synthetics",
3
- "version": "1.0.0-beta.3",
3
+ "version": "1.0.0-beta.30",
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,42 @@
38
40
  "author": "",
39
41
  "license": "MIT",
40
42
  "dependencies": {
41
- "commander": "^7.0.0",
43
+ "@cspotcode/source-map-support": "^0.8.1",
44
+ "archiver": "^5.3.0",
45
+ "commander": "^9.0.0",
42
46
  "deepmerge": "^4.2.2",
47
+ "enquirer": "^2.3.6",
48
+ "esbuild": "^0.14.27",
43
49
  "expect": "^27.0.2",
44
50
  "http-proxy": "^1.18.1",
45
- "kleur": "^4.1.3",
51
+ "kleur": "^4.1.4",
46
52
  "micromatch": "^4.0.4",
47
- "playwright-chromium": "=1.11.0",
48
- "sharp": "^0.28.3",
53
+ "playwright-chromium": "=1.20.1",
54
+ "playwright-core": "=1.20.1",
55
+ "sharp": "^0.30.6",
49
56
  "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"
57
+ "sonic-boom": "^2.6.0",
58
+ "ts-node": "^10.8.1",
59
+ "typescript": "^4.5.5",
60
+ "undici": "^5.0.0"
54
61
  },
55
62
  "devDependencies": {
56
- "@types/jest": "^26.0.19",
63
+ "@types/jest": "^27.4.0",
57
64
  "@types/micromatch": "^4.0.1",
58
- "@types/node": "^14.14.14",
65
+ "@types/node": "^14.17.5",
59
66
  "@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",
67
+ "@typescript-eslint/eslint-plugin": "^5.0.0",
68
+ "@typescript-eslint/parser": "^5.0.0",
69
+ "eslint": "^8.0.1",
63
70
  "husky": "^4.3.6",
64
- "jest": "^26.6.3",
71
+ "jest": "^28.0.2",
65
72
  "lint-staged": "^10.5.3",
66
- "prettier": "^2.2.1",
67
- "ts-jest": "^26.4.4"
73
+ "prettier": "^2.4.1",
74
+ "rimraf": "^3.0.2",
75
+ "ts-jest": "^28.0.2",
76
+ "unzipper": "^0.10.11"
77
+ },
78
+ "engines": {
79
+ "node": ">14.14.0"
68
80
  }
69
81
  }
package/src/cli.ts CHANGED
@@ -25,169 +25,202 @@
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';
34
- import {
35
- findPkgJsonByTraversing,
36
- isDepInstalled,
37
- isDirectory,
38
- totalist,
39
- } from './helpers';
28
+ import { program, Option } from 'commander';
29
+ import { cwd } from 'process';
30
+ import { CliArgs, PushOptions } from './common_types';
31
+ import { reporters } from './reporters';
32
+ import { normalizeOptions, parseThrottling } from './options';
33
+ import { loadTestFiles } from './loader';
40
34
  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
- }
69
-
70
- function requireSuites(suites: Iterable<string>) {
71
- for (const suite of suites) {
72
- require(suite);
73
- }
74
- }
35
+ import { runner } from './core';
36
+ import { SyntheticsLocations } from './dsl/monitor';
37
+ import { push } from './push';
38
+ import { resolve } from 'path';
39
+ import { Generator } from './generator';
40
+ import { error } from './helpers';
75
41
 
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;
42
+ /* eslint-disable-next-line @typescript-eslint/no-var-requires */
43
+ const { name, version } = require('../package.json');
97
44
 
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);
45
+ program
46
+ .name(`npx ${name}`)
47
+ .usage('[options] [dir] [files] file')
48
+ .option(
49
+ '-c, --config <path>',
50
+ 'configuration path (default: synthetics.config.js)'
51
+ )
52
+ .option(
53
+ '-p, --params <jsonstring>',
54
+ 'JSON object that gets injected to all journeys',
55
+ JSON.parse
56
+ )
57
+ .addOption(
58
+ new Option('--reporter <value>', `output repoter format`).choices(
59
+ Object.keys(reporters)
60
+ )
61
+ )
62
+ .option(
63
+ '--pattern <pattern>',
64
+ 'RegExp file patterns to search inside directory'
65
+ )
66
+ .option('--inline', 'Run inline journeys from heartbeat')
67
+ .option('-r, --require <modules...>', 'module(s) to preload')
68
+ .option('--no-headless', 'run browser in headful mode')
69
+ .option('--sandbox', 'enable chromium sandboxing')
70
+ .option('--rich-events', 'Mimics a heartbeat run')
71
+ .option(
72
+ '--capability <features...>',
73
+ 'Enable capabilities through feature flags'
74
+ )
75
+ .addOption(
76
+ new Option('--screenshots [flag]', 'take screenshots at end of each step')
77
+ .choices(['on', 'off', 'only-on-failure'])
78
+ .default('on')
79
+ )
80
+ .option(
81
+ '--dry-run',
82
+ "don't actually execute anything, report only registered journeys"
83
+ )
84
+ .option(
85
+ '--tags <name...>',
86
+ 'run only journeys with a tag that matches the glob'
87
+ )
88
+ .option(
89
+ '--match <name>',
90
+ 'run only journeys with a name or tag that matches the glob'
91
+ )
92
+ .option(
93
+ '--outfd <fd>',
94
+ 'specify a file descriptor for logs. Default is stdout',
95
+ parseInt
96
+ )
97
+ .option(
98
+ '--ws-endpoint <endpoint>',
99
+ 'Browser WebSocket endpoint to connect to'
100
+ )
101
+ .option(
102
+ '--pause-on-error',
103
+ 'pause on error until a keypress is made in the console. Useful during development'
104
+ )
105
+ .option(
106
+ '--ignore-https-errors',
107
+ 'ignores any HTTPS errors in sites being tested, including ones related to unrecognized certs or signatures. This can be insecure!'
108
+ )
109
+ .option(
110
+ '--quiet-exit-code',
111
+ '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'
112
+ )
113
+ .option(
114
+ '--throttling <config>',
115
+ '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 }.',
116
+ parseThrottling,
117
+ {}
118
+ )
119
+ .option('--no-throttling', 'Turns off default network throttling.')
120
+ .option(
121
+ '--playwright-options <jsonstring>',
122
+ '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. Options defined via --playwright-options take precedence.',
123
+ JSON.parse
124
+ )
125
+ .version(version)
126
+ .description('Run synthetic tests')
127
+ .action(async (cliArgs: CliArgs) => {
128
+ try {
129
+ await loadTestFiles(cliArgs, program.args);
130
+ const options = normalizeOptions(cliArgs);
131
+ const results = await run(options);
132
+ /**
133
+ * Exit with error status if any journey fails
134
+ */
135
+ if (!options.quietExitCode) {
136
+ for (const result of Object.values(results)) {
137
+ if (result.status === 'failed') {
138
+ process.exit(1);
139
+ }
109
140
  }
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
141
  }
142
+ } catch (e) {
143
+ console.error(e);
144
+ process.exit(1);
133
145
  }
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
- }
146
+ });
159
147
 
160
- /**
161
- * Use the NODE_ENV variable to control the environment if its not explicity
162
- * passed from either CLI or through the API
163
- */
164
- const environment = options.environment || process.env['NODE_ENV'];
165
- /**
166
- * Validate and handle configs
167
- */
168
- const config = readConfig(environment, options.config);
169
- const params = merge(config.params, JSON.parse(options.suiteParams));
170
- /**
171
- * use JSON reporter if json flag is enabled
172
- */
173
- const reporter = options.json ? 'json' : options.reporter;
148
+ // Push command
149
+ program
150
+ .command('push')
151
+ .description(
152
+ 'Push journeys in the current directory to create monitors within the Kibana monitor management UI'
153
+ )
154
+ .option(
155
+ '--pattern <pattern>',
156
+ 'RegExp file patterns to push inside current directory'
157
+ )
158
+ .option(
159
+ '--tags <name...>',
160
+ 'push only journeys with a tag that matches the glob'
161
+ )
162
+ .option(
163
+ '--match <name>',
164
+ 'push only journeys with a name or tag that matches the glob'
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
+ .requiredOption(
178
+ '--project <project-id>',
179
+ 'id that will be used for logically grouping monitors'
180
+ )
181
+ .requiredOption('--url <url>', 'kibana URL to upload the monitors')
182
+ .requiredOption(
183
+ '--auth <auth>',
184
+ 'API key used for Kibana authentication(https://www.elastic.co/guide/en/kibana/master/api-keys.html).'
185
+ )
186
+ .option(
187
+ '--space <space>',
188
+ 'the target Kibana spaces for the pushed monitors — spaces help you organise pushed monitors.',
189
+ 'default'
190
+ )
191
+ .action(async (cmdOpts: PushOptions) => {
192
+ try {
193
+ await loadTestFiles({ inline: false }, [cwd()]);
194
+ const options = normalizeOptions({ ...program.opts(), ...cmdOpts });
195
+ if (!options.schedule) {
196
+ throw error(`Set default schedule in minutes for all monitors via '--schedule <time-in-minutes>' OR
197
+ configure via Synthetics config file under 'monitors.schedule' field.`);
198
+ }
174
199
 
175
- const results = await run({
176
- params: Object.freeze(params),
177
- environment,
178
- reporter,
179
- ...options,
200
+ if (!options.locations) {
201
+ throw error(`Set default location for all monitors via CLI as '--locations <locations...>' OR
202
+ configure via Synthetics config file under 'monitors.locations' field.`);
203
+ }
204
+ const monitors = runner.buildMonitors(options);
205
+ await push(monitors, cmdOpts);
206
+ } catch (e) {
207
+ e && console.error(e);
208
+ process.exit(1);
209
+ }
180
210
  });
181
211
 
182
- /**
183
- * Exit with error status if any journey fails
184
- */
185
- for (const result of Object.values(results)) {
186
- if (result.status === 'failed') {
212
+ // Init command
213
+ program
214
+ .command('init <project-dir>')
215
+ .description('Initalize Elastic synthetics project')
216
+ .action(async (dir: string) => {
217
+ try {
218
+ const generator = await new Generator(resolve(process.cwd(), dir));
219
+ await generator.setup();
220
+ } catch (e) {
221
+ e && error(e);
187
222
  process.exit(1);
188
223
  }
189
- }
190
- })().catch(e => {
191
- console.error(e);
192
- process.exit(1);
193
- });
224
+ });
225
+
226
+ program.parse(process.argv);