Skip to content
Permalink
Browse files
Downloaded latest changes from template
  • Loading branch information
pastorpv committed Nov 26, 2019
1 parent 1a8c962 commit 28ed331cd45d2978fe6cbd90f3b59b9def067f67
Show file tree
Hide file tree
Showing 15 changed files with 321 additions and 15 deletions.
@@ -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
@@ -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..."
@@ -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"
@@ -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
@@ -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
@@ -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
@@ -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)
})
@@ -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


@@ -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

@@ -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
@@ -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
@@ -1,9 +1,10 @@

'use strict'

module.exports = {
displayName: 'test',
verbose: true,
collectCoverage: true,
'preset': 'jest-puppeteer',
coverageThreshold: {
global: {
branches: 0,
@@ -0,0 +1,14 @@

'use strict'

module.exports = {
server: {
command: 'node index.js',
port: 8080,
},
launch: {
headless: false,
devtools: true,
timeout: 30000
}
}
@@ -1,24 +1,22 @@
{
"name": "my_music",
"version": "1.1.3",
"author": "Vicente Pastor Pastor, Charles Neal, Luke Charles, Mateusz Watras, Gwyn Robins, Ricards Goldbergs",
"license": "ISC",
"description": "My Music Project",
"main": "index.js",
"engines": {
"node": "12.x"
},
"scripts": {
"coverage": "node_modules/.bin/jest --coverage 'unit tests/' && ./node_modules/.bin/istanbul check-coverage --statement 100 --branch 100 --function 100 --line 100",
"dependency": "node_modules/.bin/dependency-check -i bcrypt --unused --no-dev . && node_modules/.bin/dependency-check -i modules --missing .",
"start": "node index.js",
"jsdoc": "node_modules/.bin/jsdoc -c jsdoc.conf",
"linter": "node_modules/.bin/eslint .",
"unit": "node_modules/.bin/jest --coverage 'unit tests/'"
},
"jest": {
"projects": [
"<rootDir>/jest-test.config.js"
]
"test": "node_modules/.bin/jest --coverage",
"acceptance": "acceptanceTests/scripts/test.sh"
},
"author": "",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"fs-extra": "^7.0.1",
@@ -34,17 +32,33 @@
"markdown": "^0.5.0",
"markdownlint-cli": "^0.18.0",
"mime-types": "^2.1.25",
"sqlite": "^3.0.3",
"sqlite-async": "^1.0.12"
},
"devDependencies": {
"babel-eslint": "^10.0.3",
"coverage": "^0.4.1",
"dependency": "0.0.1",
"dependency-check": "^4.1.0",
"eslint": "^5.15.2",
"handlebars-validate": "^0.1.2",
"http-status-codes": "^1.3.2",
"istanbul": "^0.4.5",
"jest": "^24.9.0",
"jest-image-snapshot": "^2.11.0",
"jest-puppeteer": "^4.3.0",
"jscpd": "^2.0.16",
"jsdoc": "^3.6.3",
"jsdoc-route-plugin": "^0.1.0",
"markdownlint": "^0.17.0"
"markdownlint": "^0.17.0",
"puppeteer": "^1.20.0",
"puppeteer-har": "^1.1.1",
"start-server-and-test": "^1.10.6",
"supertest": "^4.0.2"
},
"jest": {
"projects": [
"<rootDir>/jest-test.config.js"
],
"preset": "jest-puppeteer"
}
}

0 comments on commit 28ed331

Please sign in to comment.