Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
15 changed files
with
321 additions
and
15 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
#!/bin/sh | ||
|
||
set -e # using the options command to abort script at first error | ||
echo "running the 'post-commit' script" | ||
./node_modules/.bin/markdownlint --ignore node_modules . | ||
echo | ||
echo "POST-COMMIT" | ||
# ./node_modules/.bin/markdownlint --ignore node_modules . | ||
echo |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,60 @@ | ||
#!/bin/sh | ||
|
||
set -e # using the options command to abort script at first error | ||
echo "running the 'pre-commit' script" | ||
echo | ||
echo "PRE-COMMIT" | ||
|
||
EMAIL=$(git config user.email) | ||
|
||
# make sure the user has registered a valid university email address | ||
if [[ $EMAIL != *"@coventry.ac.uk" ]]; then | ||
echo " invalid config settings" | ||
echo " Your registered email is currently '$EMAIL'" | ||
echo " please run the following git commands:" | ||
echo " $ git config user.email xxx@coventry.ac.uk" | ||
echo " $ git config user.name 'zzz'" | ||
echo " where 'xxx' is your university username" | ||
echo " and 'zzz' is your name as it appears on your university ID badge" | ||
echo | ||
exit 1 | ||
fi | ||
|
||
# see if the user is trying to merge a branch into master | ||
branch="$(git rev-parse --abbrev-ref HEAD)" | ||
if [[ $2 == 'merge' ]]; then | ||
echo "merging branch" | ||
if [[ "$branch" == "master" ]]; then | ||
echo " trying to merge into the 'master' branch" | ||
echo " you should push the local branch to GitHub" | ||
echo " and merge to master using a pull request" | ||
echo | ||
exit 1 | ||
fi | ||
fi | ||
|
||
# see if the user is trying to commit to the master branch | ||
echo " you are trying to commit to the '$branch' branch" | ||
if [ "$branch" = "master" ]; then | ||
echo " you can't commit directly to the master branch" | ||
echo " create a local feature branch first" | ||
echo | ||
exit 1 | ||
fi | ||
|
||
# check for valid branch name: | ||
|
||
# valid_branch_regex="^iss\d{3}\/[a-z\-]+$" | ||
|
||
# if [[ ! $local_branch =~ $valid_branch_regex ]] | ||
# then | ||
# echo "invalid branch name" | ||
# echo " format is: 'iss000/issue-name'" | ||
# echo " replacing '000' with the issue number and 'issue-name' with the issue name" | ||
# echo " only lower-case letters and replace spaces in the issue name with dashes" | ||
# echo " rename your branch and try again" | ||
# exit 1 | ||
# fi | ||
|
||
./node_modules/.bin/eslint . | ||
|
||
echo " commit successful..." |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
|
||
set -e # using the options command to abort script at first error | ||
echo "running the 'pre-merge-commit' script" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/sh | ||
|
||
echo | ||
echo "PRE-PUSH" | ||
|
||
protected_branch='master' | ||
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,') | ||
|
||
if [ $protected_branch = $current_branch ] | ||
then | ||
read -p " You're about to push master, is that what you intended? [y|n] " -n 1 -r < /dev/tty | ||
echo | ||
if echo $REPLY | grep -E '^[Yy]$' > /dev/null | ||
then | ||
exit 0 # push will execute | ||
fi | ||
exit 1 # push will not execute | ||
fi |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/bin/sh | ||
|
||
# With thanks to Sergio Vaccaro <sergio.vaccaro@istat.it> | ||
|
||
set -e # using the options command to abort script at first error | ||
echo | ||
echo "PREPARE-COMMIT-MSG" | ||
|
||
# Branch to protect | ||
PROTECTED_BRANCH="master" | ||
|
||
# Remote | ||
REMOTE="" | ||
|
||
# Check for merges | ||
if [[ $2 != 'merge' ]]; then | ||
# Not a merge | ||
ECHO " not a merge" | ||
exit 0 | ||
fi | ||
|
||
# Current branch | ||
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) | ||
|
||
# Check if in PROTECTED_BRANCH | ||
if [[ "$CURRENT_BRANCH" != "$PROTECTED_BRANCH" ]]; then | ||
# Not in PROTECTED_BRANCH: can proceed | ||
ECHO " not in the ${PROTECTED_BRANCH} branch" | ||
exit 0 | ||
fi | ||
|
||
echo " you are trying to merge into the ${PROTECTED_BRANCH} branch" | ||
echo " merging branches to master must be done by creating a pull request" | ||
echo " this merge has been cancelled however you will need to" | ||
echo " reset the operation before continuing by running git reset --merge" | ||
echo | ||
exit 1 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
image: node:latest | ||
|
||
stages: | ||
- code-testing | ||
- staging-server | ||
- acceptance-testing | ||
|
||
linting: | ||
stage: code-testing | ||
script: | ||
- npm install | ||
- npm run linter | ||
|
||
dependency-checks: | ||
stage: code-testing | ||
script: | ||
- npm install | ||
- npm run dependency | ||
|
||
unit-testing: | ||
stage: code-testing | ||
script: | ||
- npm install | ||
- npm test | ||
|
||
code-coverage: | ||
stage: code-testing | ||
script: | ||
- npm install | ||
- npm run coverage | ||
|
||
coverage-report: | ||
stage: staging-server | ||
script: | ||
- npm install | ||
- npm run coverage | ||
artifacts: | ||
paths: | ||
- docs | ||
expire_in: 30 days | ||
only: | ||
- master |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
'use strict' | ||
|
||
const puppeteer = require('puppeteer') | ||
const { configureToMatchImageSnapshot } = require('jest-image-snapshot') | ||
const PuppeteerHar = require('puppeteer-har') | ||
const shell = require('shelljs') | ||
|
||
const width = 800 | ||
const height = 600 | ||
const delayMS = 5 | ||
|
||
let browser | ||
let page | ||
let har | ||
|
||
// threshold is the difference in pixels before the snapshots dont match | ||
const toMatchImageSnapshot = configureToMatchImageSnapshot({ | ||
customDiffConfig: { threshold: 2 }, | ||
noColors: true, | ||
}) | ||
expect.extend({ toMatchImageSnapshot }) | ||
|
||
beforeAll( async() => { | ||
browser = await puppeteer.launch({ headless: true, slowMo: delayMS, args: [`--window-size=${width},${height}`] }) | ||
page = await browser.newPage() | ||
har = new PuppeteerHar(page) | ||
await page.setViewport({ width, height }) | ||
await shell.exec('acceptanceTests/scripts/beforeAll.sh') | ||
}) | ||
|
||
afterAll( async() => { | ||
browser.close() | ||
await shell.exec('acceptanceTests/scripts/afterAll.sh') | ||
}) | ||
|
||
beforeEach(async() => { | ||
await shell.exec('acceptanceTests/scripts/beforeEach.sh') | ||
}) | ||
|
||
describe('Registering', () => { | ||
test('Register a user', async done => { | ||
//start generating a trace file. | ||
await page.tracing.start({path: 'trace/registering_user_har.json',screenshots: true}) | ||
await har.start({path: 'trace/registering_user_trace.har'}) | ||
//ARRANGE | ||
await page.goto('http://localhost:8080/register', { timeout: 30000, waitUntil: 'load' }) | ||
//ACT | ||
await page.type('input[name=user]', 'NewUser') | ||
await page.type('input[name=pass]', 'password') | ||
await page.click('input[type=submit]') | ||
await page.goto('http://localhost:8080/login', { timeout: 30000, waitUntil: 'load' }) | ||
await page.type('input[name=user]', 'NewUser') | ||
await page.type('input[name=pass]', 'password') | ||
await page.click('input[type=submit]') | ||
//ASSERT | ||
//check that the user is taken to the homepage after attempting to login as the new user: | ||
await page.waitForSelector('h1') | ||
expect( await page.evaluate( () => document.querySelector('h1').innerText ) ) | ||
.toBe('Home') | ||
|
||
// grab a screenshot | ||
const image = await page.screenshot() | ||
// compare to the screenshot from the previous test run | ||
expect(image).toMatchImageSnapshot() | ||
// stop logging to the trace files | ||
await page.tracing.stop() | ||
await har.stop() | ||
done() | ||
}, 16000) | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
echo afterAll | ||
#Delete the databases that were used for the acceptance testing. | ||
FILE=website.db | ||
if test -f "$FILE"; then | ||
rm -rf website.db | ||
fi | ||
#Restore the databases from before the acceptance tests were run, and delete the backups. | ||
FILE=websiteBackup.db | ||
if test -f "$FILE"; then | ||
cp websiteBackup.db website.db | ||
rm -rf websiteBackup.db | ||
fi | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
echo beforeAll | ||
|
||
#Make backups of the databases. | ||
FILE=website.db | ||
if test -f "$FILE"; then | ||
cp website.db websiteBackup.db | ||
rm -rf website.db | ||
fi | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
echo beforeEach | ||
#Delete the database files. | ||
FILE=website.db | ||
if test -f "$FILE"; then | ||
rm -rf website.db | ||
fi |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
echo hello | ||
mkdir -p screenshots | ||
mkdir -p trace | ||
# [ ! -d "node_modules" ] && echo "INSTALLING MODULES" && npm install | ||
node index.js& | ||
node_modules/.bin/jest --runInBand --detectOpenHandles acceptanceTests/* | ||
read -p "Press enter to continue" | ||
kill %1 |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
'use strict' | ||
|
||
module.exports = { | ||
server: { | ||
command: 'node index.js', | ||
port: 8080, | ||
}, | ||
launch: { | ||
headless: false, | ||
devtools: true, | ||
timeout: 30000 | ||
} | ||
} |
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
Oops, something went wrong.