Muthu Kumar
6 years ago
1 changed files with 47 additions and 0 deletions
@ -0,0 +1,47 @@ |
|||
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; |
|||
|
|||
}; |
Loading…
Reference in new issue