Skip to content

Instantly share code, notes, and snippets.

Avatar

Paul Jensen paulbjensen

View GitHub Profile
@paulbjensen
paulbjensen / generateWebConfig.js
Created Jun 18, 2018
The generateWebConfig.js file, part of an article on Medium
View generateWebConfig.js
// Writes a file to src/config.js exporting the baseUrl property
const config = require('../config');
const fs = require('fs');
const path = require('path');
const {
baseUrl,
googleAnalytics,
sentryDSN,
useDevTools,
env,
@paulbjensen
paulbjensen / selectors.js
Created Jun 18, 2018
selectors.js, part of an article on Medium
View selectors.js
/*
NOTE - at some point these selectors will need to be scoped based on the page
that the user is accessing in the cucumber step
*/
const selectors = {
links: {
Signup: 'a[href="/signup"]',
Login: 'a[href="/login"]',
Logout: 'a.logout',
'I have forgotten my password': 'a[href="/forgot-password"]',
@paulbjensen
paulbjensen / pages.js
Created Jun 18, 2018
The pages.js support file, part of an article for Medium
View pages.js
const { Dashboard, Organisation } = require('api/models');
const pages = {
home: '/',
login: '/login',
signup: '/signup',
'forgot-password': '/forgot-password',
dashboard: '/dashboard',
account: '/account',
organisations: '/account/organisations',
@paulbjensen
paulbjensen / login_step_definition.js
Created Jun 18, 2018
The login step definition, part of an article on Medium
View login_step_definition.js
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 / actions.js
Created Jun 18, 2018
The actions.js file, part of an article for Medium.
View actions.js
// Dependencies
const assert = require('assert');
const {
Dashboard,
DashboardUser,
User,
Organisation,
OrganisationUser,
ForgotPassword
} = require('api/models');
@paulbjensen
paulbjensen / common.js
Created Jun 18, 2018
Step definitions, for an article on Medium
View common.js
// Dependencies
const { Given, When, Then } = require('cucumber');
const {
visitHomepage,
assertUserHasPassword,
assertUserHasEmail,
userExists,
closeAccount,
pending,
clickOnItem,
@paulbjensen
paulbjensen / hooks_v3.js
Created Jun 18, 2018
Version 3 of the hooks.js file, part of an article on Medium
View hooks_v3.js
/*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 / hooks_v2.js
Created Jun 18, 2018
Version 2 of our hooks.js file, part of an article on Medium
View hooks_v2.js
/*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 / world_v2.js
Created Jun 18, 2018
Version 2 of the world.js file, part of an article on Medium
View world_v2.js
// 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 / api_index.js
Created Jun 18, 2018
The API repo's index.js file, part of an article on Medium.
View api_index.js
'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');