Skip to content
Permalink
Browse files
Started acceptance testing
  • Loading branch information
sellers3 committed Nov 25, 2019
1 parent a63c3c4 commit 7b00c58f45bc988be3e89b4eead5e84f1a22c7ca
Show file tree
Hide file tree
Showing 11 changed files with 274 additions and 12 deletions.
@@ -0,0 +1,3 @@
cd databases/
rm -rf *.db
cd ..
@@ -0,0 +1,62 @@
'use strict'

const puppeteer = require('puppeteer')
const { configureToMatchImageSnapshot } = require('jest-image-snapshot')
const width = 800
const height = 600
const delayMS = 0
const shell = require('shelljs')

let browser
let page

// 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: false, slowMo: delayMS, args: [`--window-size=${width},${height}`] })
page = await browser.newPage()
await page.setViewport({ width, height })
})

beforeEach( () => shell.exec('./abolishDB.sh'))

afterAll( () => browser.close() )

describe('menu', () => {

test('Main Menu', async done => {

await page.goto('http://localhost:8080/login', { timeout: 30000, waitUntil: 'load' })
await page.goto('http://localhost:8080/login', { timeout: 30000, waitUntil: 'load' })

await page.click('[href="/register"]')

await page.type('input[name=user]', 'Craig')
await page.type('input[name=pass]', 'bread')

await page.waitFor(1000)
await page.click('input[type=submit]')
await page.waitFor(1000)

let title = await page.title()
expect(title).toBe('Log In')

await page.type('input[name=user]', 'Craig')
await page.type('input[name=pass]', 'bread')

await page.click('input[type=submit]')
title = await page.title()
expect(title).toBe('Main Menu')

await page.click('button[name=Menu]')
title = await page.title()
expect(title).toBe('Main Menu')

done()
})
})
@@ -0,0 +1,120 @@
'use strict'

const puppeteer = require('puppeteer')
const { configureToMatchImageSnapshot } = require('jest-image-snapshot')
const width = 800
const height = 600
const delayMS = 0
const shell = require('shelljs')

let browser
let page

// 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: false, slowMo: delayMS, args: [`--window-size=${width},${height}`] })
page = await browser.newPage()
await page.setViewport({ width, height })
})

beforeEach( () => shell.exec('./abolishDB.sh'))

afterAll( () => browser.close() )

describe('login test cases', () => {

test('No Username', async done => {

await page.goto('http://localhost:8080/login', { timeout: 30000, waitUntil: 'load' })
await page.goto('http://localhost:8080/login', { timeout: 30000, waitUntil: 'load' })

await page.type('input[name=pass]', 'bread')

await page.click('input[type=submit]')

const title = await page.title()
expect(title).toBe('ERROR')
done()
})

test('No password', async done => {

await page.goto('http://localhost:8080/login', { timeout: 30000, waitUntil: 'load' })
await page.goto('http://localhost:8080/login', { timeout: 30000, waitUntil: 'load' })

await page.type('input[name=user]', 'bread')

await page.click('input[type=submit]')

const title = await page.title()
expect(title).toBe('ERROR')
done()
})
})

describe('register', () => {

test('No Username register', async done => {
shell.exec('abolishDB.sh')
await page.goto('http://localhost:8080/login', { timeout: 30000, waitUntil: 'load' })
await page.goto('http://localhost:8080/login', { timeout: 30000, waitUntil: 'load' })

await page.click('[href="/register"]')

await page.type('input[name=pass]', 'bread')

await page.click('input[type=submit]')

const title = await page.title()
expect(title).toBe('ERROR')
done()
})

test('No Password register', async done => {

await page.goto('http://localhost:8080/login', { timeout: 30000, waitUntil: 'load' })
await page.goto('http://localhost:8080/login', { timeout: 30000, waitUntil: 'load' })

await page.click('[href="/register"]')

await page.type('input[name=user]', 'bread')

await page.click('input[type=submit]')

const title = await page.title()
expect(title).toBe('ERROR')
done()
})

test('Successful register', async done => {

await page.goto('http://localhost:8080/login', { timeout: 30000, waitUntil: 'load' })
await page.goto('http://localhost:8080/login', { timeout: 30000, waitUntil: 'load' })

await page.click('[href="/register"]')

await page.type('input[name=user]', 'Craig')
await page.type('input[name=pass]', 'bread')

await page.click('input[type=submit]')

let title = await page.title()
expect(title).toBe('Log In')

await page.type('input[name=user]', 'Craig')
await page.type('input[name=pass]', 'bread')

await page.click('input[type=submit]')
title = await page.title()
expect(title).toBe('Main Menu')
done()
})
})


@@ -4,6 +4,7 @@ module.exports = {
displayName: 'test',
verbose: true,
collectCoverage: true,
'preset': 'jest-puppeteer',
coverageThreshold: {
global: {
branches: 0,
@@ -0,0 +1,13 @@
'use strict'

module.exports = {
server: {
command: 'node index.js',
port: 8080,
},
launch: {
headless: false,
devtools: true,
timeout: 30000
}
}
@@ -52,9 +52,7 @@ module.exports = class Order {
}

async getItemInfo(data) {
console.log(data)
const sql = `SELECT ID, name, type, price FROM items WHERE ID = "${data}"`
console.log(sql)
const output = await this.db.all(sql)
return output
}
@@ -2,8 +2,6 @@
'use strict'

const bcrypt = require('bcrypt-promise')
// const fs = require('fs-extra')
//const mime = require('mime-types')
const sqlite = require('sqlite-async')
const saltRounds = 10

@@ -0,0 +1,45 @@
0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'run', 'acceptance' ]
2 info using npm@3.5.2
3 info using node@v8.10.0
4 verbose run-script [ 'preacceptance', 'acceptance', 'postacceptance' ]
5 info lifecycle 10_auth@1.0.0~preacceptance: 10_auth@1.0.0
6 silly lifecycle 10_auth@1.0.0~preacceptance: no script for preacceptance, continuing
7 info lifecycle 10_auth@1.0.0~acceptance: 10_auth@1.0.0
8 verbose lifecycle 10_auth@1.0.0~acceptance: unsafe-perm in lifecycle true
9 verbose lifecycle 10_auth@1.0.0~acceptance: PATH: /usr/share/npm/bin/node-gyp-bin:/home/cc/Documents/340CT_Project/node_modules/.bin:/home/cc/.local/bin:/home/cc/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
10 verbose lifecycle 10_auth@1.0.0~acceptance: CWD: /home/cc/Documents/340CT_Project
11 silly lifecycle 10_auth@1.0.0~acceptance: Args: [ '-c', './test.sh' ]
12 silly lifecycle 10_auth@1.0.0~acceptance: Returned: code: 1 signal: null
13 info lifecycle 10_auth@1.0.0~acceptance: Failed to exec acceptance script
14 verbose stack Error: 10_auth@1.0.0 acceptance: `./test.sh`
14 verbose stack Exit status 1
14 verbose stack at EventEmitter.<anonymous> (/usr/share/npm/lib/utils/lifecycle.js:232:16)
14 verbose stack at emitTwo (events.js:126:13)
14 verbose stack at EventEmitter.emit (events.js:214:7)
14 verbose stack at ChildProcess.<anonymous> (/usr/share/npm/lib/utils/spawn.js:24:14)
14 verbose stack at emitTwo (events.js:126:13)
14 verbose stack at ChildProcess.emit (events.js:214:7)
14 verbose stack at maybeClose (internal/child_process.js:925:16)
14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
15 verbose pkgid 10_auth@1.0.0
16 verbose cwd /home/cc/Documents/340CT_Project
17 error Linux 4.15.0-66-generic
18 error argv "/usr/bin/node" "/usr/bin/npm" "run" "acceptance"
19 error node v8.10.0
20 error npm v3.5.2
21 error code ELIFECYCLE
22 error 10_auth@1.0.0 acceptance: `./test.sh`
22 error Exit status 1
23 error Failed at the 10_auth@1.0.0 acceptance script './test.sh'.
23 error Make sure you have the latest version of node.js and npm installed.
23 error If you do, this is most likely a problem with the 10_auth package,
23 error not with npm itself.
23 error Tell the author that this fails on your system:
23 error ./test.sh
23 error You can get information on how to open an issue for this project with:
23 error npm bugs 10_auth
23 error Or if that isn't available, you can get their info via:
23 error npm owner ls 10_auth
23 error There is likely additional logging output above.
24 verbose exit [ 1, true ]
@@ -8,16 +8,17 @@
},
"scripts": {
"start": "node index.js",
"acceptance": "jest --coverage --detectOpenHandles",
"acceptance": "./test.sh",
"jsdoc": "node_modules/.bin/jsdoc -c jsdoc.conf",
"linter": "node_modules/.bin/eslint .",
"test": "jest --coverage --detectOpenHandles",
"test": "jest --coverage --detectOpenHandles unit tests/user.spec.js",
"unit": "node_modules/.bin/jest --coverage --runInBand tests/unit/"
},
"jest": {
"projects": [
"<rootDir>/jest-test.config.js"
]
],
"preset": "jest-puppeteer"
},
"author": "",
"license": "ISC",
@@ -45,12 +46,19 @@
"sqlite-async": "^1.0.12"
},
"devDependencies": {
"0x": "^4.9.1",
"eslint": "^5.15.2",
"handlebars-validate": "^0.1.2",
"http-status-codes": "^1.3.2",
"jest": "^24.1.0",
"jsdoc": "^3.6.3",
"jsdoc-route-plugin": "^0.1.0",
"markdownlint": "^0.17.0"
"markdownlint": "^0.17.0",
"jest-image-snapshot": "^2.11.0",
"jest-puppeteer": "^4.3.0",
"puppeteer": "^1.20.0",
"puppeteer-har": "^1.1.1",
"start-server-and-test": "^1.10.6",
"supertest": "^4.0.2"
}
}
14 test.sh
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

set -e
echo hello
mkdir -p screenshots
mkdir -p trace
cd databases/
rm -rf *.db
cd ..
# [ ! -d "node_modules" ] && echo "INSTALLING MODULES" && npm install
node index.js&
node_modules/.bin/jest --runInBand --detectOpenHandles acceptance\ tests/*
read -p "Press enter to continue"
kill %1
@@ -7,9 +7,9 @@
<header>
<h1>Main Menu</h1>
</header>
<button type="button" onclick="window.location='/menu'">Menu</button><br><br>
<button type="button" onclick="window.location='/order'">Order</button><br><br>
<button type="button" onclick="window.location='/ready'">Ready</button><br><br>
<button type="button" onclick="window.location='/login'">Log Out</button>
<button type="button" name="Menu" onclick="window.location='/menu'">Menu</button><br><br>
<button type="button" name="Order" onclick="window.location='/order'">Order</button><br><br>
<button type="button" name="Ready" onclick="window.location='/ready'">Ready</button><br><br>
<button type="button" name="Log Out" onclick="window.location='/login'">Log Out</button>
</body>
</html>

0 comments on commit 7b00c58

Please sign in to comment.