Created
June 18, 2018 09:37
-
-
Save paulbjensen/953cdcaf06c2bbc6a218117351d705be to your computer and use it in GitHub Desktop.
Version 3 of the hooks.js file, part of an article on Medium
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*eslint no-console: ["error", { allow: ["log"] }] */ | |
// Dependencies | |
const { After, Before, AfterAll } = require('cucumber'); | |
const {mongoose, redis } = require('api/db'); | |
const { | |
User, | |
Dashboard, | |
DashboardUser, | |
Session, | |
ForgotPassword, | |
Organisation, | |
OrganisationUser | |
} = require('api/models'); | |
const scope = require('./support/scope'); | |
Before(async () => { | |
await User.remove({}); | |
await Dashboard.remove({}); | |
await DashboardUser.remove({}); | |
await Organisation.remove({}); | |
await OrganisationUser.remove({}); | |
await Session.flush(); | |
await ForgotPassword.remove({}); | |
}); | |
After(async () => { | |
if (scope.browser && scope.context.currentPage) { | |
const cookies = await scope.context.currentPage.cookies(); | |
if (cookies && cookies.length > 0) { | |
await scope.context.currentPage.deleteCookie(...cookies); | |
} | |
await scope.context.currentPage.close(); | |
scope.context.currentPage = null; | |
} | |
}); | |
AfterAll(async () => { | |
if (scope.browser) await scope.browser.close(); | |
scope.api.shutdown(() => console.log('\nAPI is shut down')); | |
scope.web.shutdown(() => console.log('Web is shut down')); | |
mongoose.disconnect(); | |
redis.end(true); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment