-
Notifications
You must be signed in to change notification settings - Fork 10
Switch e2e tests over to cypress #183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tw-paraxial
wants to merge
21
commits into
rabblerouser:master
Choose a base branch
from
test-automation-dojo:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
3f8af28
Duplicate the e2e seeder from seed.js using event-streams; use the ne…
6556833
[Amelyn/Para] Added cypress module...
paraxial b7cfbd6
Updated travis config; Changed spin up script; Removed user from dock…
paraxial a3a9871
Reverted changes to the prod dockerfile. e2e tests now run in own co…
paraxial d363e03
Edited go script to also include e2e test runner
paraxial 8ba0c1c
Correcting minor typos
paraxial 98ec8dc
[Alice/Amelyn/Para] Addressed some comments for PR 183
paraxial 55650c9
Fix script command typo.
038eab5
Make log messages appear for core_test_1 and core_core_1
3d93a3d
add scripts to install dependencies needed to run e2e test.
a1989da
Convert Admin with invalid credential e2e test from casperjs to cypress.
4ecceab
Fix issue with not being able to login when running e2e tests.
e7c4a55
Add more login tests.
07e0795
Remove tests temporarily.
0886ca0
Add config to differentiate between localhost docker container for
4aa3c15
Add script to run cypress tests on localhost
9639d68
Minor changes to main README.md
2ad225c
Update readme for end to end tests
cdba448
Update e2e readme
aab7ff4
Improve wording of e2e README.md
5ac6433
Revert "Remove tests temporarily."
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,51 +1,121 @@ | ||
| const uuid = require('node-uuid'); | ||
|
|
||
| const models = require('../src/models'); | ||
| const Branch = models.Branch; | ||
| const AdminUser = models.AdminUser; | ||
| const Member = models.Member; | ||
| const Group = models.Group; | ||
|
|
||
| const branchId = uuid(); | ||
| let branch; | ||
| let group; | ||
|
|
||
| console.log('Running script to seed data necessary for E2E tests'); | ||
|
|
||
| Promise.all([Branch, AdminUser, Group] | ||
| .map(model => model.destroy({ truncate: true, cascade: true, force: true })) | ||
| ) | ||
| .then(() => process.stdout.write('Database cleared of branches, groups, admins, organisers.\n')) | ||
|
|
||
| .then(() => AdminUser.create({ email: 'admin@rr.com', password: 'apassword', type: 'SUPER' })) | ||
| .then(() => process.stdout.write('Database seeded with admin: admin@rr.com.\n')) | ||
|
|
||
| .then(() => Branch.create({ id: branchId, name: 'A branch' })) | ||
| .then(created => { branch = created; }) | ||
| .then(() => process.stdout.write('Database seeded with branch: \'A branch\'.\n')) | ||
|
|
||
| .then(() => AdminUser.create({ email: 'organiser@rr.com', password: 'apassword', branchId, type: 'BRANCH' })) | ||
| .then(() => process.stdout.write('Database seeded with organiser: organiser@rr.com.\n')) | ||
|
|
||
| .then(() => Group.create({ name: 'A group with member', description: 'This is a description' })) | ||
| .then(created => { group = created; }) | ||
| .then(() => branch.addGroup(group)) | ||
| .then(() => process.stdout.write('Database seeded with group: \'a group with a member\'.\n')) | ||
|
|
||
| .then(() => Member.create( | ||
| { firstName: 'A name', lastName: 'surname', gender: 'social-construct', | ||
| memberSince: new Date(), email: 'a@name.com', primaryPhoneNumber: '0', | ||
| secondaryPhoneNumber: '1', residentialAddress: null, postalAddress: null, membershipType: 'full', | ||
| branchId, additionalInfo: '' }) | ||
| ) | ||
| .then(created => { | ||
| group.addMember(created); | ||
| return created.addGroup(group); | ||
| }) | ||
| .then(() => process.stdout.write('Database seeded with member: \'A name\'.\n')) | ||
|
|
||
| .then(() => process.exit(0)) | ||
| .catch(err => { | ||
| process.stdout.write(`Error: ${err}`); | ||
| process.exit(1); | ||
| }); | ||
| 'use strict'; | ||
|
|
||
| /* eslint no-console: off */ | ||
| /* eslint import/no-extraneous-dependencies: off */ | ||
|
|
||
| // This script can be run manually via yarn to prepare data for the app | ||
| // - It publishes a "branch-created" event onto the rabblerouser kinesis stream | ||
| // - It publishes an "admin-created" event onto the rabblerouser kinesis stream | ||
| // - In development, it also ensures that the kinesis stream and event S3 bucket have been created | ||
| // (In production, these are created by terraform before the app is deployed) | ||
|
|
||
| const AWS = require('aws-sdk'); | ||
| const branchesController = require('../src/controllers/branchesController'); | ||
| const adminController = require('../src/controllers/adminController'); | ||
| const adminType = require('../src/security/adminType'); | ||
|
|
||
| const createStream = () => { | ||
| console.log('Creating kinesis stream for development'); | ||
|
|
||
| const kinesis = new AWS.Kinesis({ | ||
| endpoint: process.env.KINESIS_ENDPOINT, | ||
| region: 'ap-southeast-2', | ||
| accessKeyId: 'FAKE', | ||
| secretAccessKey: 'ALSO FAKE', | ||
| }); | ||
|
|
||
| const StreamName = process.env.STREAM_NAME; | ||
| return kinesis.createStream({ StreamName, ShardCount: 1 }).promise().then( | ||
| () => console.log(`${StreamName} created`), | ||
| err => { | ||
| // Swallow these errors, but re-throw all others | ||
| if (err.message.includes('already exists')) { | ||
| console.log(`${StreamName} already exists`); | ||
| return; | ||
| } | ||
| throw new Error(`Could not create stream: ${err.message}`); | ||
| } | ||
| ); | ||
| }; | ||
|
|
||
| const createArchiveBucket = () => { | ||
| console.log('Creating archive S3 bucket for development'); | ||
|
|
||
| const s3 = new AWS.S3({ | ||
| endpoint: process.env.S3_ENDPOINT, | ||
| region: 'ap-southeast-2', | ||
| accessKeyId: 'FAKE', | ||
| secretAccessKey: 'ALSO FAKE', | ||
| }); | ||
|
|
||
| return s3.createBucket({ Bucket: process.env.ARCHIVE_BUCKET }).promise().then( | ||
| () => console.log(`${process.env.ARCHIVE_BUCKET} created`), | ||
| err => { throw new Error(`Could not create bucket: ${err.message}`); } | ||
| ); | ||
| }; | ||
|
|
||
| const createStreamAndBucket = () => { | ||
| if (process.env.NODE_ENV === 'production') { | ||
| console.log('Not creating kinesis stream or S3 bucket. These should already be there in production.'); | ||
| return undefined; | ||
| } | ||
| return Promise.all([createStream(), createArchiveBucket()]); | ||
| }; | ||
|
|
||
| const fakeRes = () => { | ||
| const res = { | ||
| lastStatus: null, | ||
| lastJson: null, | ||
| }; | ||
| res.status = status => { res.lastStatus = status; return res; }; | ||
| res.sendStatus = status => { res.lastStatus = status; return res; }; | ||
| res.json = json => { res.lastJson = json; return res; }; | ||
| return res; | ||
| }; | ||
|
|
||
| const createDefaultBranch = () => { | ||
| console.log('Creating default branch.'); | ||
| const req = { body: { name: 'A branch' } }; | ||
| const res = fakeRes(); | ||
| return branchesController.createBranch(req, res) | ||
| .then(() => { | ||
| if (res.lastStatus === 200) { | ||
| console.log('Default branch created'); | ||
| return Promise.resolve(); | ||
| } | ||
| console.log('Failed to create default branch'); | ||
| return Promise.reject({ status: res.lastStatus, json: res.lastJson }); | ||
| }); | ||
| }; | ||
|
|
||
| const createDefaultAdmin = () => { | ||
| console.log('Creating default admin'); | ||
| const req = { params: {}, body: { email: 'admin@rr.com', name: 'Default Super Admin', password: 'password4321' } }; | ||
| const res = fakeRes(); | ||
| return adminController.createAdmin(adminType.super)(req, res) | ||
| .then(() => { | ||
| if (res.lastStatus === 200) { | ||
| console.log(`Default admin created - username: ${req.body.email}, password: ${req.body.password}`); | ||
| return Promise.resolve(); | ||
| } | ||
| console.log('Failed to create default admin'); | ||
| return Promise.reject({ status: res.lastStatus, json: res.lastJson }); | ||
| }); | ||
| }; | ||
|
|
||
| const wait = () => { | ||
| console.log('Waiting for a few seconds for things to be ready...'); | ||
| return new Promise(resolve => setTimeout(resolve, 5000)); | ||
| }; | ||
|
|
||
| console.log('Running seed script'); | ||
| Promise.resolve() | ||
| .then(createStreamAndBucket) | ||
| .then(wait) | ||
| .then(createDefaultBranch) | ||
| .then(createDefaultAdmin) | ||
| .then(() => console.log('Seeded successfully.')) | ||
| .catch(error => { | ||
| console.error('Seed failed:', error); | ||
| process.exit(1); | ||
| }); |
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,8 @@ | ||
| #!/bin/sh | ||
| set -e | ||
| set -x | ||
|
|
||
| export NODE_ENV=test | ||
| docker-compose -f docker-compose.yml -f docker-compose.test.yml up -d | ||
|
|
||
| yarn start & | ||
|
|
||
| echo "Will wait for the server to be available for testing..." | ||
| attempts=0 | ||
| until $(curl --output /dev/null --silent --head --fail http://localhost:3000); do | ||
| attempts=$((attempts+1)) | ||
| if [ "$attempts" = '100' ]; then | ||
| echo "Tried to contact the site, but it's taking too long. Possibly it's broken. Either way it's ignoring me and I don't appreciate this." | ||
| exit 1 | ||
| fi | ||
| sleep 5 | ||
| done | ||
| echo "Oh hai server!" | ||
|
|
||
| yarn --cwd backend e2e-seed && yarn --cwd e2e ci-test | ||
| docker logs -f --since=1m core_test_1 | ||
| docker logs -f --since=1m core_core_1 | ||
| docker logs -f --since=1m core_kinesis_1 |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| version: '2' | ||
| services: | ||
| core: | ||
| command: > | ||
| sh -c "yarn --cwd backend | ||
| && yarn --cwd backend e2e-seed | ||
| && ./bin/copy_assets.sh | ||
| && yarn start" | ||
| test: | ||
| image: cypress/browsers:chrome65-ff57 | ||
| volumes: | ||
| - '.:/app' | ||
| links: | ||
| - core | ||
| command: > | ||
| bash -c "yarn --cwd app/e2e | ||
| && yarn --cwd app/e2e test-command" | ||
| depends_on: | ||
| - core |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| ./cypress/screenshots | ||
| ./cypress/videos |
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| $(yarn bin)/cypress open --env configFile=development |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "baseUrl": "http://localhost:3000" | ||
| } |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "baseUrl": "http://core:3000" | ||
| } |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "baseUrl": "http://core:3000" | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm hesitant to add more scripts to the package.json, as it's already a bit out of control. Can we just do
NODE_ENV=test yarn startanywhere we need this?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personal preference - I see what you mean, but, this one feels like a useful shorthand that would be used relatively commonly, and also serves as documentation for future devs.