packages/reflow-core/src/context.ts
export
const createReflowContext = function(filepath) {
const self = this;
return {
describe(name) {
self.suites[name] = filepath
},
subflow(name, configCb) {
console.log(`Registering "${name}" Subflow.`);
self.subflows[name] = configCb
},
flow(name, fn) {
self.flows[name] = {
name,
path: filepath,
fn,
};
},
hook(name) {
console.log(`Registering "${name}" Hook.`);
self.hooks[name] = filepath;
},
getHook(name, tags) {
const suitePath = self.hooks[name];
if(!suitePath) throw new Error(`Unable to find hook [ ${name} ].`);
return {
name,
tags,
path: suitePath,
type: 'hook',
}
},
getSubflow(name, tags) {
const subflowDetail = self.subflows[name];
if(!subflowDetail) throw new Error(`Unable to get subflow [ ${name} ].`);
const activeTags = self.options.tags;
if(_.isMatch(tags, activeTags)) {
return evaluateSubflow(name , subflowDetail)
}
return null;
},
getSuite(name, tags) {
const suitePath = self.suites[name];
if(!suitePath) throw new Error(`Unable to find suite [ ${name} ].`);
return {
name,
tags,
path: suitePath,
type: 'suite',
};
},
fork(suites) {
const activeTags = self.options.tags;
const activeFork = suites
.filter(Boolean)
.filter(suite => _.isMatch(suite.tags, activeTags))
.filter(Boolean)
return activeFork.length? activeFork : null
},
}
};