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 6a73605
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 14 deletions.
8 changes: 3 additions & 5 deletions src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* THE SOFTWARE.
*
*/
import { Journey, JourneyCallback, JourneyOptions, Suite } from '../dsl';
import { Journey, JourneyCallback, JourneyOptions } from '../dsl';
import Runner from './runner';
import { VoidCallback, HooksCallback, Location } from '../common_types';
import { wrapFnWithLocation } from '../helpers';
Expand All @@ -33,7 +33,8 @@ import { MonitorConfig } from '../dsl/monitor';
/* TODO: Testing
* Local vs global matrix: Local matrix fully overwrites global matrix, rather than merging
* Adjustments: Duplicates in adjustments do not run extra journeys
* Regular params are combina
* Regular params are combined with matrix params
* Project monitors: name and id are overwritten only for matrix monitors
/**
* Use a gloabl Runner which would be accessed by the runtime and
Expand All @@ -55,11 +56,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 6a73605

Please sign in to comment.