Skip to content

Commit c112b3c

Browse files
handle project monitors
1 parent 03897ef commit c112b3c

File tree

3 files changed

+38
-14
lines changed

3 files changed

+38
-14
lines changed

src/core/index.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* THE SOFTWARE.
2323
*
2424
*/
25-
import { Journey, JourneyCallback, JourneyOptions, Suite } from '../dsl';
25+
import { Journey, JourneyCallback, JourneyOptions } from '../dsl';
2626
import Runner from './runner';
2727
import { VoidCallback, HooksCallback, Location } from '../common_types';
2828
import { wrapFnWithLocation } from '../helpers';
@@ -33,7 +33,8 @@ import { MonitorConfig } from '../dsl/monitor';
3333
/* TODO: Testing
3434
* Local vs global matrix: Local matrix fully overwrites global matrix, rather than merging
3535
* Adjustments: Duplicates in adjustments do not run extra journeys
36-
* Regular params are combina
36+
* Regular params are combined with matrix params
37+
* Project monitors: name and id are overwritten only for matrix monitors
3738
3839
/**
3940
* Use a gloabl Runner which would be accessed by the runtime and
@@ -55,11 +56,8 @@ export const journey = wrapFnWithLocation(
5556
if (typeof options === 'string') {
5657
options = { name: options, id: options };
5758
}
58-
const suite = new Suite(location);
5959
const j = new Journey(options, callback, location);
60-
suite.addJourney(j);
6160
runner.addJourney(j);
62-
runner.addSuite(suite);
6361
return j;
6462
}
6563
);

src/core/runner.ts

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,14 @@ export default class Runner {
141141
}
142142

143143
addJourney(journey: Journey) {
144+
const journeySuite = this.suites.get(journey.location);
145+
if (journeySuite) {
146+
journeySuite.addJourney(journey);
147+
} else {
148+
const suite = new Suite(journey.location);
149+
suite.addJourney(journey);
150+
this.addSuite(suite);
151+
}
144152
this.journeys.push(journey);
145153
this.#currentJourney = journey;
146154
}
@@ -392,10 +400,13 @@ export default class Runner {
392400
}
393401

394402
buildMonitors(options: RunOptions) {
403+
/* Build out monitors according to matrix specs */
404+
this.parseMatrix(options);
405+
395406
/**
396407
* Update the global monitor configuration required for
397408
* setting defaults
398-
*/
409+
*/
399410
this.updateMonitor({
400411
throttling: options.throttling,
401412
schedule: options.schedule,
@@ -407,7 +418,10 @@ export default class Runner {
407418

408419
const { match, tags } = options;
409420
const monitors: Monitor[] = [];
410-
for (const journey of this.journeys) {
421+
422+
const journeys = this.getAllJourneys();
423+
424+
for (const journey of journeys) {
411425
const params = Object.freeze({ ...this.monitor.config?.params, ...options.params, ...journey.params });
412426
if (!journey.isMatch(match, tags)) {
413427
continue;
@@ -419,9 +433,15 @@ export default class Runner {
419433
*/
420434
journey.callback({ params: params } as any);
421435
journey.monitor.update({
422-
...this.monitor?.config,
436+
...this.monitor?.config,
423437
params: Object.keys(params).length ? params : undefined
424438
});
439+
440+
/* Only overwrite name and id values when using matrix */
441+
if (journey.matrix) {
442+
journey.monitor.config.name = journey.name;
443+
journey.monitor.config.id = journey.id;
444+
}
425445
journey.monitor.validate();
426446
monitors.push(journey.monitor);
427447
}
@@ -453,11 +473,19 @@ export default class Runner {
453473
j.name = name;
454474
j.id = name;
455475
j.params = matrixParams;
476+
j.matrix = matrix;
456477
this.addJourney(j);
457478
suite.addJourney(j);
458479
});
459-
})
460-
480+
})
481+
}
482+
483+
getAllJourneys() {
484+
const journeys = Array.from(this.suites.values()).reduce((acc, suite) => {
485+
const suiteJourneys = suite.entries;
486+
return [...acc, ...suiteJourneys];
487+
}, []);
488+
return journeys;
461489
}
462490

463491
async run(options: RunOptions) {
@@ -477,10 +505,7 @@ export default class Runner {
477505

478506
this.parseMatrix(options);
479507

480-
const journeys = Array.from(this.suites.values()).reduce((acc, suite) => {
481-
const suiteJourneys = suite.entries;
482-
return [...acc, ...suiteJourneys];
483-
}, []);
508+
const journeys = this.getAllJourneys();
484509

485510
for (const journey of journeys) {
486511
/**

src/loader.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export async function loadTestFiles(options: CliArgs, args: string[]) {
7171
loadInlineScript(source);
7272
return;
7373
}
74+
7475
/**
7576
* Handle piped files by reading the STDIN
7677
* ex: ls example/suites/*.js | npx @elastic/synthetics

0 commit comments

Comments
 (0)