Skip to content

Commit

Permalink
handle project monitors
Browse files Browse the repository at this point in the history
  • Loading branch information
dominiqueclarke committed Feb 15, 2023
1 parent 03897ef commit 4e9ecd9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 12 deletions.
3 changes: 0 additions & 3 deletions src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,8 @@ export const journey = wrapFnWithLocation(
if (typeof options === 'string') {
options = { name: options, id: options };
}
const suite = new Suite(location);
const j = new Journey(options, callback, location);
suite.addJourney(j);
runner.addJourney(j);
runner.addSuite(suite);
return j;
}
);
Expand Down
47 changes: 38 additions & 9 deletions src/core/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ export default class Runner {
}

addJourney(journey: Journey) {
const journeySuite = this.suites.get(journey.location);
if (journeySuite) {
journeySuite.addJourney(journey);
} else {
const suite = new Suite(journey.location);
suite.addJourney(journey);
this.addSuite(suite);
}
this.journeys.push(journey);
this.#currentJourney = journey;
}
Expand Down Expand Up @@ -392,10 +400,13 @@ export default class Runner {
}

buildMonitors(options: RunOptions) {
/* Build out monitors according to matrix specs */
this.parseMatrix(options);

/**
* Update the global monitor configuration required for
* setting defaults
*/
*/
this.updateMonitor({
throttling: options.throttling,
schedule: options.schedule,
Expand All @@ -407,24 +418,37 @@ export default class Runner {

const { match, tags } = options;
const monitors: Monitor[] = [];
for (const journey of this.journeys) {

const journeys = this.getAllJourneys();

for (const journey of journeys) {
const params = Object.freeze({ ...this.monitor.config?.params, ...options.params, ...journey.params });
if (!journey.isMatch(match, tags)) {
continue;
}
console.warn('journey.name', journey.name);
this.#currentJourney = journey;
/**
* Execute dummy callback to get all monitor specific
* configurations for the current journey
*/
journey.callback({ params: params } as any);
console.warn('journey.monitor.config', journey.monitor.config);
journey.monitor.update({
...this.monitor?.config,
...this.monitor?.config,
params: Object.keys(params).length ? params : undefined
});

/* Only overwrite name and id values when using matrix */
if (journey.matrix) {
journey.monitor.config.name = journey.name;
journey.monitor.config.id = journey.id;
}
console.warn('journey.monitor.config2', journey.monitor.config);
journey.monitor.validate();
monitors.push(journey.monitor);
}
// console.warn('monitors', monitors);
return monitors;
}

Expand Down Expand Up @@ -453,11 +477,19 @@ export default class Runner {
j.name = name;
j.id = name;
j.params = matrixParams;
j.matrix = matrix;
this.addJourney(j);
suite.addJourney(j);
});
})

})
}

getAllJourneys() {
const journeys = Array.from(this.suites.values()).reduce((acc, suite) => {
const suiteJourneys = suite.entries;
return [...acc, ...suiteJourneys];
}, []);
return journeys;
}

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

this.parseMatrix(options);

const journeys = Array.from(this.suites.values()).reduce((acc, suite) => {
const suiteJourneys = suite.entries;
return [...acc, ...suiteJourneys];
}, []);
const journeys = this.getAllJourneys();

for (const journey of journeys) {
/**
Expand Down

0 comments on commit 4e9ecd9

Please sign in to comment.