@elastic/synthetics 1.0.0-beta.30 → 1.0.0-beta.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +51 -26
- package/dist/cli.js.map +1 -1
- package/dist/common_types.d.ts +4 -1
- package/dist/common_types.d.ts.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.map +1 -1
- package/dist/core/gatherer.js +3 -1
- package/dist/core/gatherer.js.map +1 -1
- package/dist/core/runner.d.ts.map +1 -1
- package/dist/core/runner.js +4 -3
- package/dist/core/runner.js.map +1 -1
- package/dist/dsl/index.js +5 -1
- package/dist/dsl/index.js.map +1 -1
- package/dist/dsl/journey.d.ts +2 -1
- package/dist/dsl/journey.d.ts.map +1 -1
- package/dist/dsl/journey.js +5 -1
- package/dist/dsl/journey.js.map +1 -1
- package/dist/dsl/monitor.d.ts +2 -1
- package/dist/dsl/monitor.d.ts.map +1 -1
- package/dist/dsl/monitor.js +2 -2
- package/dist/dsl/monitor.js.map +1 -1
- package/dist/generator/index.d.ts +11 -3
- package/dist/generator/index.d.ts.map +1 -1
- package/dist/generator/index.js +98 -27
- package/dist/generator/index.js.map +1 -1
- package/dist/generator/utils.d.ts +2 -1
- package/dist/generator/utils.d.ts.map +1 -1
- package/dist/generator/utils.js +27 -4
- package/dist/generator/utils.js.map +1 -1
- package/dist/helpers.d.ts +10 -5
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.js +41 -10
- package/dist/helpers.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/loader.js +11 -3
- package/dist/loader.js.map +1 -1
- package/dist/locations/index.d.ts +45 -0
- package/dist/locations/index.d.ts.map +1 -0
- package/dist/locations/index.js +90 -0
- package/dist/locations/index.js.map +1 -0
- package/dist/{dsl/locations.d.ts → locations/public-locations.d.ts} +1 -1
- package/dist/locations/public-locations.d.ts.map +1 -0
- package/dist/{dsl/locations.js → locations/public-locations.js} +1 -1
- package/dist/locations/public-locations.js.map +1 -0
- package/dist/options.d.ts +7 -0
- package/dist/options.d.ts.map +1 -1
- package/dist/options.js +21 -1
- package/dist/options.js.map +1 -1
- package/dist/plugins/index.js +5 -1
- package/dist/plugins/index.js.map +1 -1
- package/dist/push/bundler.d.ts.map +1 -1
- package/dist/push/bundler.js +12 -3
- package/dist/push/bundler.js.map +1 -1
- package/dist/push/index.d.ts +12 -1
- package/dist/push/index.d.ts.map +1 -1
- package/dist/push/index.js +137 -8
- package/dist/push/index.js.map +1 -1
- package/dist/push/monitor.d.ts +7 -0
- package/dist/push/monitor.d.ts.map +1 -1
- package/dist/push/monitor.js +23 -7
- package/dist/push/monitor.js.map +1 -1
- package/dist/push/plugin.d.ts.map +1 -1
- package/dist/push/plugin.js +11 -2
- package/dist/push/plugin.js.map +1 -1
- package/dist/push/request.d.ts +8 -7
- package/dist/push/request.d.ts.map +1 -1
- package/dist/push/request.js +22 -22
- package/dist/push/request.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -9
- package/src/cli.ts +79 -59
- package/src/common_types.ts +4 -0
- package/src/core/expect.ts +58 -24
- package/src/core/gatherer.ts +9 -2
- package/src/core/runner.ts +5 -6
- package/src/dsl/journey.ts +8 -1
- package/src/dsl/monitor.ts +2 -1
- package/src/generator/index.ts +138 -34
- package/src/generator/utils.ts +29 -3
- package/src/helpers.ts +40 -12
- package/src/index.ts +1 -0
- package/src/loader.ts +11 -2
- package/src/locations/index.ts +108 -0
- package/src/{dsl/locations.ts → locations/public-locations.ts} +0 -0
- package/src/options.ts +38 -0
- package/src/push/bundler.ts +7 -2
- package/src/push/index.ts +177 -10
- package/src/push/monitor.ts +38 -9
- package/src/push/plugin.ts +6 -1
- package/src/push/request.ts +27 -34
- package/templates/journeys/advanced-example-helpers.ts +9 -9
- package/templates/journeys/advanced-example.journey.ts +6 -6
- package/templates/journeys/example.journey.ts +1 -1
- package/templates/synthetics.config.ts +2 -1
- package/dist/dsl/locations.d.ts.map +0 -1
- package/dist/dsl/locations.js.map +0 -1
package/src/push/index.ts
CHANGED
|
@@ -23,24 +23,71 @@
|
|
|
23
23
|
*
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
+
import { join } from 'path';
|
|
27
|
+
import { existsSync } from 'fs';
|
|
28
|
+
import { readFile, writeFile } from 'fs/promises';
|
|
29
|
+
import { prompt } from 'enquirer';
|
|
30
|
+
import { bold, yellow } from 'kleur/colors';
|
|
26
31
|
import {
|
|
27
|
-
createMonitors,
|
|
28
32
|
ok,
|
|
29
33
|
formatAPIError,
|
|
30
34
|
formatFailedMonitors,
|
|
31
35
|
formatNotFoundError,
|
|
36
|
+
formatStaleMonitors,
|
|
32
37
|
} from './request';
|
|
38
|
+
import { buildMonitorSchema, createMonitors, MonitorSchema } from './monitor';
|
|
39
|
+
import { ProjectSettings } from '../generator';
|
|
33
40
|
import { Monitor } from '../dsl/monitor';
|
|
34
|
-
import {
|
|
35
|
-
|
|
36
|
-
|
|
41
|
+
import {
|
|
42
|
+
progress,
|
|
43
|
+
apiProgress,
|
|
44
|
+
write,
|
|
45
|
+
error,
|
|
46
|
+
SYNTHETICS_PATH,
|
|
47
|
+
aborted,
|
|
48
|
+
indent,
|
|
49
|
+
safeNDJSONParse,
|
|
50
|
+
done,
|
|
51
|
+
} from '../helpers';
|
|
52
|
+
import type { PushOptions } from '../common_types';
|
|
37
53
|
|
|
38
54
|
export async function push(monitors: Monitor[], options: PushOptions) {
|
|
55
|
+
if (monitors.length === 0) {
|
|
56
|
+
throw 'No Monitors found';
|
|
57
|
+
}
|
|
58
|
+
const duplicates = trackDuplicates(monitors);
|
|
59
|
+
if (duplicates.size > 0) {
|
|
60
|
+
throw error(formatDuplicateError(duplicates));
|
|
61
|
+
}
|
|
62
|
+
|
|
39
63
|
progress(`preparing all monitors`);
|
|
40
64
|
const schemas = await buildMonitorSchema(monitors);
|
|
65
|
+
|
|
66
|
+
progress(`creating all monitors`);
|
|
67
|
+
for (const schema of schemas) {
|
|
68
|
+
await pushMonitors({ schemas: [schema], keepStale: true, options });
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
progress(`deleting all stale monitors`);
|
|
72
|
+
await pushMonitors({ schemas, keepStale: false, options });
|
|
73
|
+
done('Pushed');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export async function pushMonitors({
|
|
77
|
+
schemas,
|
|
78
|
+
keepStale,
|
|
79
|
+
options,
|
|
80
|
+
}: {
|
|
81
|
+
schemas: MonitorSchema[];
|
|
82
|
+
keepStale: boolean;
|
|
83
|
+
options: PushOptions;
|
|
84
|
+
}) {
|
|
41
85
|
try {
|
|
42
|
-
|
|
43
|
-
|
|
86
|
+
const { body, statusCode } = await createMonitors(
|
|
87
|
+
schemas,
|
|
88
|
+
options,
|
|
89
|
+
keepStale
|
|
90
|
+
);
|
|
44
91
|
if (statusCode === 404) {
|
|
45
92
|
throw formatNotFoundError(await body.text());
|
|
46
93
|
}
|
|
@@ -48,12 +95,132 @@ export async function push(monitors: Monitor[], options: PushOptions) {
|
|
|
48
95
|
const { error, message } = await body.json();
|
|
49
96
|
throw formatAPIError(statusCode, error, message);
|
|
50
97
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
98
|
+
body.setEncoding('utf-8');
|
|
99
|
+
for await (const data of body) {
|
|
100
|
+
// Its kind of hacky for now where Kibana streams the response by
|
|
101
|
+
// writing the data as NDJSON events (data can be interleaved), we
|
|
102
|
+
// distinguish the final data by checking if the event was a progress vs complete event
|
|
103
|
+
const chunks = safeNDJSONParse(data);
|
|
104
|
+
for (const chunk of chunks) {
|
|
105
|
+
if (typeof chunk === 'string') {
|
|
106
|
+
// TODO: add progress back for all states once we get the fix
|
|
107
|
+
// on kibana side
|
|
108
|
+
keepStale && apiProgress(chunk);
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
const { failedMonitors, failedStaleMonitors } = chunk;
|
|
112
|
+
if (failedMonitors && failedMonitors.length > 0) {
|
|
113
|
+
throw formatFailedMonitors(failedMonitors);
|
|
114
|
+
}
|
|
115
|
+
if (failedStaleMonitors.length > 0) {
|
|
116
|
+
write(yellow(formatStaleMonitors(failedStaleMonitors)));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
54
119
|
}
|
|
55
|
-
done('Pushed');
|
|
56
120
|
} catch (e) {
|
|
57
121
|
error(e);
|
|
58
122
|
}
|
|
59
123
|
}
|
|
124
|
+
|
|
125
|
+
function trackDuplicates(monitors: Monitor[]) {
|
|
126
|
+
const monitorMap: Map<string, Monitor> = new Map();
|
|
127
|
+
const duplicates: Set<Monitor> = new Set();
|
|
128
|
+
for (const monitor of monitors) {
|
|
129
|
+
const id = monitor.config.id;
|
|
130
|
+
if (monitorMap.has(id)) {
|
|
131
|
+
duplicates.add(monitorMap.get(id));
|
|
132
|
+
duplicates.add(monitor);
|
|
133
|
+
}
|
|
134
|
+
monitorMap.set(id, monitor);
|
|
135
|
+
}
|
|
136
|
+
return duplicates;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function formatDuplicateError(monitors: Set<Monitor>) {
|
|
140
|
+
let outer = bold(`Aborted: Duplicate monitors found\n`);
|
|
141
|
+
|
|
142
|
+
let inner = '';
|
|
143
|
+
for (const monitor of monitors) {
|
|
144
|
+
const { config, source } = monitor;
|
|
145
|
+
inner += `* ${config.id} - ${source.file}:${source.line}:${source.column}\n`;
|
|
146
|
+
}
|
|
147
|
+
outer += indent(inner);
|
|
148
|
+
return outer;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const PROJECT_SETTINGS_PATH = join(SYNTHETICS_PATH, 'project.json');
|
|
152
|
+
const INSTALLATION_HELP = `Run 'npx @elastic/synthetics init' to create project with default settings.`;
|
|
153
|
+
|
|
154
|
+
export async function loadSettings() {
|
|
155
|
+
if (!existsSync(PROJECT_SETTINGS_PATH)) {
|
|
156
|
+
throw error(`Aborted. Synthetics project not set up.
|
|
157
|
+
|
|
158
|
+
${INSTALLATION_HELP}`);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const contents = await readFile(PROJECT_SETTINGS_PATH, 'utf-8');
|
|
162
|
+
return JSON.parse(contents) as ProjectSettings;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function validateSettings(opts: PushOptions) {
|
|
166
|
+
const INVALID = 'Aborted. Invalid synthetics project settings.';
|
|
167
|
+
|
|
168
|
+
let reason = '';
|
|
169
|
+
if (!opts.project) {
|
|
170
|
+
reason = 'Set project id via CLI as `--project <id>`';
|
|
171
|
+
} else if (!opts.locations && !opts.privateLocations) {
|
|
172
|
+
reason = `Set default location for all monitors via
|
|
173
|
+
- CLI as '--locations <values...> or --privateLocations <values...>'
|
|
174
|
+
- Synthetics config file 'monitors.locations' | 'monitors.privateLocations' field`;
|
|
175
|
+
} else if (!opts.schedule) {
|
|
176
|
+
reason = `Set default schedule in minutes for all monitors via
|
|
177
|
+
- CLI as '--schedule <mins>'
|
|
178
|
+
- Synthetics config file 'monitors.schedule' field`;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (!reason) return;
|
|
182
|
+
|
|
183
|
+
throw error(`${INVALID}
|
|
184
|
+
|
|
185
|
+
${reason}
|
|
186
|
+
|
|
187
|
+
${INSTALLATION_HELP}`);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
async function overrideSettings(project: string) {
|
|
191
|
+
const settings = JSON.parse(await readFile(PROJECT_SETTINGS_PATH, 'utf-8'));
|
|
192
|
+
settings.project = project;
|
|
193
|
+
|
|
194
|
+
await writeFile(
|
|
195
|
+
PROJECT_SETTINGS_PATH,
|
|
196
|
+
JSON.stringify(settings, null, 2),
|
|
197
|
+
'utf-8'
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export async function catchIncorrectSettings(
|
|
202
|
+
settings: ProjectSettings,
|
|
203
|
+
options: PushOptions
|
|
204
|
+
) {
|
|
205
|
+
let override = !settings.project;
|
|
206
|
+
if (settings.project && settings.project !== options.project) {
|
|
207
|
+
if (typeof process.env.TEST_OVERRIDE != null) {
|
|
208
|
+
override = Boolean(process.env.TEST_OVERRIDE);
|
|
209
|
+
} else {
|
|
210
|
+
// Add an extra line to make it easier to read the prompt
|
|
211
|
+
write('');
|
|
212
|
+
({ override } = await prompt<{ override: boolean }>({
|
|
213
|
+
type: 'confirm',
|
|
214
|
+
name: 'override',
|
|
215
|
+
message: `Monitors were pushed under the '${settings.project}' project. Are you sure you want to push them under the new '${options.project}' (note that this will duplicate the monitors, the old ones being orphaned)`,
|
|
216
|
+
initial: false,
|
|
217
|
+
}));
|
|
218
|
+
}
|
|
219
|
+
if (!override) {
|
|
220
|
+
throw aborted('Push command Aborted');
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
if (override) {
|
|
224
|
+
await overrideSettings(options.project);
|
|
225
|
+
}
|
|
226
|
+
}
|
package/src/push/monitor.ts
CHANGED
|
@@ -23,12 +23,14 @@
|
|
|
23
23
|
*
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
-
import { mkdir } from 'fs/promises';
|
|
26
|
+
import { mkdir, rm } from 'fs/promises';
|
|
27
27
|
import { join } from 'path';
|
|
28
28
|
import { Bundler } from './bundler';
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
29
|
+
import { sendRequest } from './request';
|
|
30
|
+
import { removeTrailingSlash, SYNTHETICS_PATH } from '../helpers';
|
|
31
|
+
import { LocationsMap } from '../locations/public-locations';
|
|
31
32
|
import { Monitor, MonitorConfig } from '../dsl/monitor';
|
|
33
|
+
import { PushOptions } from '../common_types';
|
|
32
34
|
|
|
33
35
|
export type MonitorSchema = Omit<MonitorConfig, 'locations'> & {
|
|
34
36
|
content: string;
|
|
@@ -36,19 +38,23 @@ export type MonitorSchema = Omit<MonitorConfig, 'locations'> & {
|
|
|
36
38
|
filter: Monitor['filter'];
|
|
37
39
|
};
|
|
38
40
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
export type APISchema = {
|
|
42
|
+
project: string;
|
|
43
|
+
keep_stale: boolean;
|
|
44
|
+
monitors: MonitorSchema[];
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
function translateLocation(locations?: MonitorConfig['locations']) {
|
|
48
|
+
if (!locations) return [];
|
|
49
|
+
return locations.map(loc => LocationsMap[loc] || loc).filter(Boolean);
|
|
41
50
|
}
|
|
42
51
|
|
|
43
52
|
export async function buildMonitorSchema(monitors: Monitor[]) {
|
|
44
|
-
if (monitors.length == 0) {
|
|
45
|
-
throw new Error('No Monitors found');
|
|
46
|
-
}
|
|
47
53
|
/**
|
|
48
54
|
* Set up the bundle artifacts path which can be used to
|
|
49
55
|
* create the bundles required for uploading journeys
|
|
50
56
|
*/
|
|
51
|
-
const bundlePath = join(
|
|
57
|
+
const bundlePath = join(SYNTHETICS_PATH, 'bundles');
|
|
52
58
|
await mkdir(bundlePath, { recursive: true });
|
|
53
59
|
const bundler = new Bundler();
|
|
54
60
|
const schemas: MonitorSchema[] = [];
|
|
@@ -64,5 +70,28 @@ export async function buildMonitorSchema(monitors: Monitor[]) {
|
|
|
64
70
|
filter: filter,
|
|
65
71
|
});
|
|
66
72
|
}
|
|
73
|
+
|
|
74
|
+
await rm(bundlePath, { recursive: true });
|
|
67
75
|
return schemas;
|
|
68
76
|
}
|
|
77
|
+
|
|
78
|
+
export async function createMonitors(
|
|
79
|
+
monitors: MonitorSchema[],
|
|
80
|
+
options: PushOptions,
|
|
81
|
+
keepStale: boolean
|
|
82
|
+
) {
|
|
83
|
+
const schema: APISchema = {
|
|
84
|
+
project: options.project,
|
|
85
|
+
keep_stale: keepStale,
|
|
86
|
+
monitors,
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
return await sendRequest({
|
|
90
|
+
url:
|
|
91
|
+
removeTrailingSlash(options.url) +
|
|
92
|
+
`/s/${options.space}/api/synthetics/service/project/monitors`,
|
|
93
|
+
method: 'PUT',
|
|
94
|
+
auth: options.auth,
|
|
95
|
+
body: JSON.stringify(schema),
|
|
96
|
+
});
|
|
97
|
+
}
|
package/src/push/plugin.ts
CHANGED
|
@@ -49,8 +49,13 @@ export type PluginData = {
|
|
|
49
49
|
export type PluginCallback = (data: PluginData) => void;
|
|
50
50
|
|
|
51
51
|
export function MultiAssetPlugin(callback: PluginCallback): esbuild.Plugin {
|
|
52
|
+
// Check that the path isn't in an external package by making sure it's at a standard
|
|
53
|
+
// local filesystem location
|
|
52
54
|
const isBare = (str: string) => {
|
|
53
|
-
|
|
55
|
+
// Note that we use `isAbsolute` to handle UNC/windows style paths like C:\path\to\thing
|
|
56
|
+
// This is not necessary for relative directories since `.\file` is not supported as an import
|
|
57
|
+
// nor is `~/path/to/file`.
|
|
58
|
+
if (path.isAbsolute(str) || str.startsWith('./') || str.startsWith('../')) {
|
|
54
59
|
return true;
|
|
55
60
|
}
|
|
56
61
|
return false;
|
package/src/push/request.ts
CHANGED
|
@@ -24,54 +24,37 @@
|
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
26
|
import { bold } from 'kleur/colors';
|
|
27
|
-
import { request } from 'undici';
|
|
28
|
-
import { PushOptions } from '../common_types';
|
|
27
|
+
import { Dispatcher, request } from 'undici';
|
|
29
28
|
import { indent, symbols } from '../helpers';
|
|
30
|
-
import { MonitorSchema } from './monitor';
|
|
31
29
|
|
|
32
30
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
33
31
|
const { version } = require('../../package.json');
|
|
34
32
|
|
|
35
|
-
export type
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
export type APIRequestOptions = {
|
|
34
|
+
url: string;
|
|
35
|
+
method: Dispatcher.HttpMethod;
|
|
36
|
+
auth: string;
|
|
37
|
+
body?: string;
|
|
39
38
|
};
|
|
40
39
|
|
|
41
|
-
function
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
options.
|
|
45
|
-
`/s/${options.space}/api/synthetics/service/project/monitors`
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export function ok(statusCode: number) {
|
|
50
|
-
return statusCode >= 200 && statusCode <= 299;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export async function createMonitors(
|
|
54
|
-
monitors: MonitorSchema[],
|
|
55
|
-
options: PushOptions
|
|
56
|
-
) {
|
|
57
|
-
const schema: APISchema = {
|
|
58
|
-
project: options.project,
|
|
59
|
-
keep_stale: false,
|
|
60
|
-
monitors,
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
return await request(getAPIUrl(options), {
|
|
64
|
-
method: 'PUT',
|
|
65
|
-
body: JSON.stringify(schema),
|
|
40
|
+
export async function sendRequest(options: APIRequestOptions) {
|
|
41
|
+
return await request(options.url, {
|
|
42
|
+
method: options.method,
|
|
43
|
+
body: options.body,
|
|
66
44
|
headers: {
|
|
67
45
|
authorization: `ApiKey ${options.auth}`,
|
|
68
46
|
'content-type': 'application/json',
|
|
69
47
|
'user-agent': `Elastic/Synthetics ${version}`,
|
|
70
48
|
'kbn-xsrf': 'true',
|
|
71
49
|
},
|
|
50
|
+
headersTimeout: 60 * 1000
|
|
72
51
|
});
|
|
73
52
|
}
|
|
74
53
|
|
|
54
|
+
export function ok(statusCode: number) {
|
|
55
|
+
return statusCode >= 200 && statusCode <= 299;
|
|
56
|
+
}
|
|
57
|
+
|
|
75
58
|
export type APIMonitorError = {
|
|
76
59
|
id?: string;
|
|
77
60
|
reason: string;
|
|
@@ -98,8 +81,8 @@ export function formatAPIError(
|
|
|
98
81
|
return outer;
|
|
99
82
|
}
|
|
100
83
|
|
|
101
|
-
|
|
102
|
-
let outer =
|
|
84
|
+
function formatMonitorError(errors: APIMonitorError[]) {
|
|
85
|
+
let outer = '';
|
|
103
86
|
for (const error of errors) {
|
|
104
87
|
const monitorId = error.id ? `: monitor(${error.id})` : '';
|
|
105
88
|
let inner = bold(`> ${error.reason}${monitorId}\n`);
|
|
@@ -109,3 +92,13 @@ export function formatFailedMonitors(errors: APIMonitorError[]) {
|
|
|
109
92
|
}
|
|
110
93
|
return outer;
|
|
111
94
|
}
|
|
95
|
+
|
|
96
|
+
export function formatFailedMonitors(errors: APIMonitorError[]) {
|
|
97
|
+
const heading = bold(`${symbols['failed']} Error\n`);
|
|
98
|
+
return heading + formatMonitorError(errors);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function formatStaleMonitors(errors: APIMonitorError[]) {
|
|
102
|
+
const heading = bold(`${symbols['warning']} Warnings\n`);
|
|
103
|
+
return heading + formatMonitorError(errors);
|
|
104
|
+
}
|
|
@@ -12,7 +12,7 @@ export const loadAppStep = (page: Page, url: string) => {
|
|
|
12
12
|
|
|
13
13
|
export const addTaskStep = (page: Page, task: string) => {
|
|
14
14
|
step(`add task ${task}`, async () => {
|
|
15
|
-
const input = await page
|
|
15
|
+
const input = await page.locator('input.new-todo');
|
|
16
16
|
await input.type(task);
|
|
17
17
|
await input.press('Enter');
|
|
18
18
|
});
|
|
@@ -21,12 +21,13 @@ export const addTaskStep = (page: Page, task: string) => {
|
|
|
21
21
|
const todosSelector = 'ul.todo-list li.todo';
|
|
22
22
|
|
|
23
23
|
export const findTask = async (page: Page, task: string) => {
|
|
24
|
-
return await page.
|
|
24
|
+
return await page.locator(`${todosSelector} >> text="${task}"`);
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
export const
|
|
28
|
-
step(`check that task list has exactly ${
|
|
29
|
-
|
|
27
|
+
export const assertTaskListCountStep = async (page: Page, count: number) => {
|
|
28
|
+
step(`check that task list has exactly ${count} elements`, async () => {
|
|
29
|
+
const tasks = await page.locator(todosSelector);
|
|
30
|
+
expect(await tasks.count()).toBe(count);
|
|
30
31
|
});
|
|
31
32
|
};
|
|
32
33
|
|
|
@@ -40,14 +41,13 @@ export const destroyTaskStep = async (page: Page, task: string) => {
|
|
|
40
41
|
step(`destroy task '${task}'`, async () => {
|
|
41
42
|
const label = await findTask(page, task);
|
|
42
43
|
// xpath indexes arrays starting at 1!!! Easy to forget!
|
|
43
|
-
const li = await label
|
|
44
|
-
const destroyButton = await li
|
|
45
|
-
|
|
44
|
+
const li = await label.locator('xpath=ancestor::li[1]');
|
|
45
|
+
const destroyButton = await li.locator('button');
|
|
46
46
|
// The destroy button is not visible until hovered. Setup a click test which
|
|
47
47
|
// will wait up to 30s for the button to be visible.
|
|
48
48
|
const clickFuture = destroyButton.click();
|
|
49
49
|
// now hover, making the destroy button clickable
|
|
50
|
-
li.hover();
|
|
50
|
+
await li.hover();
|
|
51
51
|
// now we are done
|
|
52
52
|
await clickFuture;
|
|
53
53
|
});
|
|
@@ -2,7 +2,7 @@ import { journey } from '@elastic/synthetics';
|
|
|
2
2
|
import {
|
|
3
3
|
loadAppStep,
|
|
4
4
|
addTaskStep,
|
|
5
|
-
|
|
5
|
+
assertTaskListCountStep,
|
|
6
6
|
checkForTaskStep,
|
|
7
7
|
destroyTaskStep,
|
|
8
8
|
} from './advanced-example-helpers';
|
|
@@ -17,10 +17,10 @@ journey('addition and completion of single task', ({ page, params }) => {
|
|
|
17
17
|
|
|
18
18
|
loadAppStep(page, params.url);
|
|
19
19
|
addTaskStep(page, testText);
|
|
20
|
-
|
|
20
|
+
assertTaskListCountStep(page, 1);
|
|
21
21
|
checkForTaskStep(page, testText);
|
|
22
22
|
destroyTaskStep(page, testText);
|
|
23
|
-
|
|
23
|
+
assertTaskListCountStep(page, 0);
|
|
24
24
|
});
|
|
25
25
|
|
|
26
26
|
journey('adding and removing multiple tasks', ({ page, params }) => {
|
|
@@ -31,13 +31,13 @@ journey('adding and removing multiple tasks', ({ page, params }) => {
|
|
|
31
31
|
addTaskStep(page, t);
|
|
32
32
|
});
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
assertTaskListCountStep(page, 3);
|
|
35
35
|
|
|
36
36
|
// remove the middle task and check that it worked
|
|
37
37
|
destroyTaskStep(page, testTasks[1]);
|
|
38
|
-
|
|
38
|
+
assertTaskListCountStep(page, 2);
|
|
39
39
|
|
|
40
40
|
// add a new task and check it exists
|
|
41
41
|
addTaskStep(page, 'Task 4');
|
|
42
|
-
|
|
42
|
+
assertTaskListCountStep(page, 3);
|
|
43
43
|
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"locations.d.ts","sourceRoot":"","sources":["../../src/dsl/locations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAGH,eAAO,MAAM,YAAY;;;;;;;;;;;CAWxB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"locations.js","sourceRoot":"","sources":["../../src/dsl/locations.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;;;AAEH,sDAAsD;AACzC,QAAA,YAAY,GAAG;IAC1B,KAAK,EAAE,mBAAmB;IAC1B,KAAK,EAAE,eAAe;IACtB,SAAS,EAAE,mBAAmB;IAC9B,cAAc,EAAE,wBAAwB;IACxC,cAAc,EAAE,gBAAgB;IAChC,OAAO,EAAE,gBAAgB;IACzB,WAAW,EAAE,2BAA2B;IACxC,MAAM,EAAE,sBAAsB;IAC9B,OAAO,EAAE,YAAY;IACrB,OAAO,EAAE,YAAY;CACtB,CAAC"}
|