Skip to content

Commit

Permalink
Add the first e2e test
Browse files Browse the repository at this point in the history
Selenium-powered.
  • Loading branch information
motet-a committed Jul 17, 2017
1 parent 9093fa2 commit cd2170e
Show file tree
Hide file tree
Showing 13 changed files with 554 additions and 58 deletions.
14 changes: 11 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@

dist: trusty
sudo: false
sudo: true
language: node_js

node_js: "8"

cache: yarn
cache:
yarn: true
directories:
- server/node_modules
- client/node_modules

env:
- NODE_ENV=development
- NODE_ENV=development GTSEARCH_SERVER_HOST_FROM_SELENIUM=192.168.0.1

install:
- curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 0.27.5
- export PATH="$HOME/.yarn/bin:$PATH"
- cd client && yarn && cd ..
- cd server && yarn

script:
- docker network create -d bridge --subnet 192.168.0.0/24 --gateway 192.168.0.1 dockernet
- docker run --net dockernet --rm -v /dev/shm:/dev/shm --name selenium -d -p 4444:4444 selenium/standalone-chrome
- cd ../client && yarn run build && cd ../server
- yarn run test
4 changes: 2 additions & 2 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ services:

server:
environment:
GTSEARCH_ADDRESS: "0.0.0.0"
GTSEARCH_PORT: "80"
- "GTSEARCH_ADDRESS=0.0.0.0"
- "GTSEARCH_PORT=80"
build:
context: ./server/
dockerfile: Dockerfile.dev
Expand Down
34 changes: 34 additions & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
version: '3'
services:

client:
build:
context: ./client/
dockerfile: Dockerfile.dev
volumes:
- ./client/src:/gs/client/src:ro
- client-dist:/gs/client/dist

server:
environment:
- "GTSEARCH_ADDRESS=0.0.0.0"
- "GTSEARCH_PORT=80"
- "GTSEARCH_SELENIUM_HOST=selenium"
build:
context: ./server/
dockerfile: Dockerfile.dev
volumes:
- ./server/src:/gs/server/src:ro
- ./client/index.html:/gs/client/index.html:ro
- client-dist:/gs/client/dist:ro
ports:
- "8081:80"
command: sleep infinity

selenium:
image: selenium/standalone-chrome
volumes:
- /dev/shm:/dev/shm

volumes:
client-dist:
6 changes: 1 addition & 5 deletions server/Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ COPY package.json yarn.lock ./

ENV NODE_ENV=development

RUN apt-get update \
&& apt-get install -y --no-install-recommends python \
&& yarn \
&& apt-get purge -y --auto-remove python \
&& rm -rf /var/lib/apt/lists/*
RUN yarn

CMD ["yarn", "run", "watch"]
3 changes: 2 additions & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"chai": "^4.0.2",
"mocha": "^3.4.2",
"nodemon": "^1.11.0",
"sinon": "^2.3.6"
"sinon": "^2.3.6",
"webdriverio": "^4.8.0"
}
}
6 changes: 3 additions & 3 deletions server/src/clones.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ class Clones {
}
}

const newClones = baseDirName =>
const createClones = baseDirName =>
new Clones(baseDirName)

Object.assign(newClones, {errors, isClonesError})
Object.assign(createClones, {errors, isClonesError})

module.exports = newClones
module.exports = createClones
32 changes: 32 additions & 0 deletions server/src/create-test-server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

const createSearches = require('./searches')
const {dummyLogger} = require('./log')
const createDb = require('./db')
const createClones = require('./clones')
const serve = require('./serve')

module.exports = async () => {
const address = '0.0.0.0'
const port = 8081

const db = await createDb('test')
await db._db.truncateTables()
await db.setupAdmin()

const adminPassword = await db.resetAdminPassword()
const clones = createClones('test-clones')
const searches = createSearches()
const log = dummyLogger

const server = await serve({
db, clones, searches, log,
address, port,
})

return {
adminPassword,
db, clones, searches, log,
server,
address, port,
}
}
6 changes: 3 additions & 3 deletions server/src/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ class Db {
}
}

const newDb = async fileName => {
const createDb = async fileName => {
assert(typeof fileName === 'string')

const filePath = path.join(
Expand All @@ -225,6 +225,6 @@ const newDb = async fileName => {
return db
}

Object.assign(newDb, {repoSpec, errors, isDbError})
Object.assign(createDb, {repoSpec, errors, isDbError})

module.exports = newDb
module.exports = createDb
50 changes: 50 additions & 0 deletions server/src/e2e/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

const {assert} = require('chai')
const wdio = require('webdriverio')

const createTestServer = require('../create-test-server')

describe('e2e', function () {
this.timeout(1000 * 1000)

let client
let serverConfig

const serverHostFormSelenium = process.env.GTSEARCH_SERVER_HOST_FROM_SELENIUM || 'server'

const navigate = (path = '') =>
client.url('http://' + serverHostFormSelenium + ':' + serverConfig.port)

before(async () => {
serverConfig = await createTestServer()

client = wdio.remote({
host: process.env.GTSEARCH_SELENIUM_HOST || 'localhost',
port: ~~process.env.GTSEARCH_SELENIUM_PORT || 4444,
desiredCapabilities: {
browserName: 'chrome',
},
})

await client.init()
})

after(async () => {
serverConfig.server.close()
await client.endAll()
})

it('loads properly the index page',
() => {
return navigate()
.getTitle().then(title => assert(title === 'gtsearch'))
.getText('h1').then(text => assert(text === 'repositories'))
}
)

it('clones a repository')

it('pulls an existing repository')

it('searches in a repository')
})
1 change: 1 addition & 0 deletions server/src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ require('./clones.test')
require('./ws.test')
require('./search.test')
require('./buffered-search.test')
require('./e2e/index.test')
37 changes: 11 additions & 26 deletions server/src/ws.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ const WebSocket = require('ws')
const {promisify} = require('util')
const EventEmitter = require('events')

const createSearches = require('./searches')
const {dummyLogger} = require('./log')
const createDb = require('./db')
const createClones = require('./clones')
const createTestServer = require('./create-test-server')
const serve = require('./serve')


Expand Down Expand Up @@ -74,35 +71,23 @@ const fixtures = {


describe('ws', () => {
let serverConfig
let db
let clones
let searches
let server
let adminPassword

let admin
let user

const address = 'localhost'
const port = 8081

const createClient = () =>
new Client(new WebSocket('ws://' + address + ':' + port))
new Client(new WebSocket(
'ws://' + serverConfig.address + ':' + serverConfig.port
))

before(async () => {
assert(!server)
db = await createDb('test')
await db._db.truncateTables()
await db.setupAdmin()
adminPassword = await db.resetAdminPassword()
clones = createClones('test-clones')
searches = createSearches()

server = await serve({
db, clones, searches,
address, port,
log: dummyLogger,
})
assert(!serverConfig)
serverConfig = await createTestServer()
db = serverConfig.db
adminPassword = serverConfig.adminPassword

admin = createClient()
user = createClient()
Expand All @@ -113,8 +98,8 @@ describe('ws', () => {
await user.receive()
})

after(async () => {
server.close()
after(() => {
serverConfig.server.close()
})

beforeEach(async () => {
Expand Down
Loading

0 comments on commit cd2170e

Please sign in to comment.