Skip to content

Instantly share code, notes, and snippets.

View paulbjensen's full-sized avatar

Paul Jensen paulbjensen

View GitHub Profile
@paulbjensen
paulbjensen / hooks_v1.js
Last active June 18, 2018 08:26
The hooks.js file for Cucumber, part of an article on Medium
// Dependencies
const { After, Before, AfterAll } = require('cucumber');
const scope = require('./support/scope');
Before(async () => {
// You can clean up database models here
});
After(async () => {
// Here we check if a scenario has instantiated a browser and a current page
@paulbjensen
paulbjensen / web_index.js
Created June 18, 2018 08:52
The index.js file for the web repo, part of an article on Medium
// This is used to serve the app for integration tests with the API via Cucumber
/*eslint no-console: ["error", { allow: ["log"] }] */
// Dependencies
//
const express = require('express');
const httpShutdown = require('http-shutdown');
const path = require('path');
const app = express();
const config = require('./config');
@paulbjensen
paulbjensen / api_index.js
Created June 18, 2018 09:06
The API repo's index.js file, part of an article on Medium.
'use strict';
/*eslint no-console: ["error", { allow: ["log"] }] */
// Dependencies
const express = require('express');
const Raven = require('raven');
const { port, allowedOrigins, sentryDSN } = require('./config');
Raven.config(sentryDSN).install();
const httpShutdown = require('http-shutdown');
const bodyParser = require('body-parser');
@paulbjensen
paulbjensen / world_v2.js
Created June 18, 2018 09:19
Version 2 of the world.js file, part of an article on Medium
// Dependencies
const api = require('api');
const web = require('web');
const { setWorldConstructor } = require('cucumber');
const puppeteer = require('puppeteer');
const scope = require('./support/scope');
const World = function() {
scope.host = web.host;
scope.driver = puppeteer;
@paulbjensen
paulbjensen / hooks_v2.js
Created June 18, 2018 09:31
Version 2 of our hooks.js file, part of an article on Medium
/*eslint no-console: ["error", { allow: ["log"] }] */
// Dependencies
const { After, Before, AfterAll } = require('cucumber');
const scope = require('./support/scope');
Before(async () => {
});
After(async () => {
if (scope.browser && scope.context.currentPage) {
@paulbjensen
paulbjensen / hooks_v3.js
Created June 18, 2018 09:37
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,
@paulbjensen
paulbjensen / common.js
Created June 18, 2018 10:21
Step definitions, for an article on Medium
// Dependencies
const { Given, When, Then } = require('cucumber');
const {
visitHomepage,
assertUserHasPassword,
assertUserHasEmail,
userExists,
closeAccount,
pending,
clickOnItem,
@paulbjensen
paulbjensen / actions.js
Created June 18, 2018 10:24
The actions.js file, part of an article for Medium.
// Dependencies
const assert = require('assert');
const {
Dashboard,
DashboardUser,
User,
Organisation,
OrganisationUser,
ForgotPassword
} = require('api/models');
@paulbjensen
paulbjensen / login_step_definition.js
Created June 18, 2018 10:42
The login step definition, part of an article on Medium
Given('I login', { timeout: 10000 }, async () => {
await visitHomepage();
await clickOnItem('Login');
await takenToPage('login');
await fillInFormField('identifier', email);
await fillInFormField('password', password);
await pressButton('Login');
return await shouldBeOnPage('dashboard');
});
@paulbjensen
paulbjensen / pages.js
Created June 18, 2018 10:52
The pages.js support file, part of an article for Medium
const { Dashboard, Organisation } = require('api/models');
const pages = {
home: '/',
login: '/login',
signup: '/signup',
'forgot-password': '/forgot-password',
dashboard: '/dashboard',
account: '/account',
organisations: '/account/organisations',