Skip to content

Commit 4e9ecd9

Browse files
handle project monitors
1 parent 03897ef commit 4e9ecd9

File tree

2 files changed

+38
-12
lines changed

2 files changed

+38
-12
lines changed

src/core/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,8 @@ export const journey = wrapFnWithLocation(
5555
if (typeof options === 'string') {
5656
options = { name: options, id: options };
5757
}
58-
const suite = new Suite(location);
5958
const j = new Journey(options, callback, location);
60-
suite.addJourney(j);
6159
runner.addJourney(j);
62-
runner.addSuite(suite);
6360
return j;
6461
}
6562
);

src/core/runner.ts

Lines changed: 38 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,24 +418,37 @@ 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;
414428
}
429+
console.warn('journey.name', journey.name);
415430
this.#currentJourney = journey;
416431
/**
417432
* Execute dummy callback to get all monitor specific
418433
* configurations for the current journey
419434
*/
420435
journey.callback({ params: params } as any);
436+
console.warn('journey.monitor.config', journey.monitor.config);
421437
journey.monitor.update({
422-
...this.monitor?.config,
438+
...this.monitor?.config,
423439
params: Object.keys(params).length ? params : undefined
424440
});
441+
442+
/* Only overwrite name and id values when using matrix */
443+
if (journey.matrix) {
444+
journey.monitor.config.name = journey.name;
445+
journey.monitor.config.id = journey.id;
446+
}
447+
console.warn('journey.monitor.config2', journey.monitor.config);
425448
journey.monitor.validate();
426449
monitors.push(journey.monitor);
427450
}
451+
// console.warn('monitors', monitors);
428452
return monitors;
429453
}
430454

@@ -453,11 +477,19 @@ export default class Runner {
453477
j.name = name;
454478
j.id = name;
455479
j.params = matrixParams;
480+
j.matrix = matrix;
456481
this.addJourney(j);
457482
suite.addJourney(j);
458483
});
459-
})
460-
484+
})
485+
}
486+
487+
getAllJourneys() {
488+
const journeys = Array.from(this.suites.values()).reduce((acc, suite) => {
489+
const suiteJourneys = suite.entries;
490+
return [...acc, ...suiteJourneys];
491+
}, []);
492+
return journeys;
461493
}
462494

463495
async run(options: RunOptions) {
@@ -477,10 +509,7 @@ export default class Runner {
477509

478510
this.parseMatrix(options);
479511

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

485514
for (const journey of journeys) {
486515
/**

0 commit comments

Comments
 (0)