Skip to content

Instantly share code, notes, and snippets.

@paulbjensen
Created June 18, 2018 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulbjensen/953cdcaf06c2bbc6a218117351d705be to your computer and use it in GitHub Desktop.
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
/*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