You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
958 B
47 lines
958 B
const Gunner = require('@klenty/gunner');
|
|
|
|
const convertHook = require('./units/convertHook');
|
|
const convertTest = require('./units/convertTest');
|
|
|
|
module.exports = strategy => plan => {
|
|
|
|
const gunner = new Gunner(plan.name);
|
|
|
|
gunner.before(Gunner.Start, () => {
|
|
return strategy.createResource(
|
|
'request',
|
|
plan.resources.request,
|
|
);
|
|
});
|
|
|
|
gunner.before(Gunner.Start, () => {
|
|
return strategy.createResource(
|
|
'db',
|
|
plan.resources.db,
|
|
);
|
|
});
|
|
|
|
const addHook = convertHook(gunner);
|
|
|
|
// Convert 'before' hooks
|
|
(plan.before || []).forEach(addHook('before'));
|
|
|
|
// Convert tests
|
|
(plan.tests || []).forEach(convertTest(gunner));
|
|
|
|
// Convert 'after' hooks
|
|
(plan.after || []).forEach(addHook('after'));
|
|
|
|
const closeConnections = db => {
|
|
return db.__mongoose__
|
|
&& db.__mongoose__.connection.close();
|
|
};
|
|
|
|
gunner.after(Gunner.End, state => {
|
|
const [ , db ] = state['@start'];
|
|
return closeConnections(db);
|
|
});
|
|
|
|
return gunner;
|
|
|
|
};
|
|
|