add jest for running tests
Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
parent
792f61d55e
commit
1de51e3f2a
|
@ -6,7 +6,7 @@ const nodemon = require('gulp-nodemon')
|
||||||
|
|
||||||
gulp.task('devel', () => {
|
gulp.task('devel', () => {
|
||||||
nodemon({
|
nodemon({
|
||||||
script: 'src/app.js',
|
script: 'src/server.js',
|
||||||
presets: ['env', 'stage-2'],
|
presets: ['env', 'stage-2'],
|
||||||
exec: 'babel-node'
|
exec: 'babel-node'
|
||||||
})
|
})
|
||||||
|
|
40
package.json
40
package.json
|
@ -17,21 +17,57 @@
|
||||||
"@babel/node": "^7.0.0",
|
"@babel/node": "^7.0.0",
|
||||||
"@babel/plugin-transform-async-to-generator": "^7.1.0",
|
"@babel/plugin-transform-async-to-generator": "^7.1.0",
|
||||||
"@babel/preset-env": "^7.1.0",
|
"@babel/preset-env": "^7.1.0",
|
||||||
|
"babel-core": "^7.0.0-bridge.0",
|
||||||
"gulp": "^3.9.1",
|
"gulp": "^3.9.1",
|
||||||
"gulp-babel": "^8.0.0-beta.2",
|
"gulp-babel": "^8.0.0-beta.2",
|
||||||
"gulp-clean": "^0.4.0",
|
"gulp-clean": "^0.4.0",
|
||||||
"gulp-nodemon": "^2.2.1",
|
"gulp-nodemon": "^2.2.1",
|
||||||
"gulp-print": "^5.0.0",
|
"gulp-print": "^5.0.0",
|
||||||
"nodemon": "^1.18.4"
|
"jest": "^23.6.0",
|
||||||
|
"nodemon": "^1.18.4",
|
||||||
|
"supertest": "^3.3.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node app.js",
|
"start": "node server.js",
|
||||||
|
"test": "jest",
|
||||||
|
"testw": "jest --watchAll",
|
||||||
"devel": "gulp devel",
|
"devel": "gulp devel",
|
||||||
"clean": "gulp clean",
|
"clean": "gulp clean",
|
||||||
"build": "gulp build",
|
"build": "gulp build",
|
||||||
"image": "docker build -t statusteam/clicks-counter .",
|
"image": "docker build -t statusteam/clicks-counter .",
|
||||||
"push": "docker push statusteam/clicks-counter"
|
"push": "docker push statusteam/clicks-counter"
|
||||||
},
|
},
|
||||||
|
"jest": {
|
||||||
|
"moduleFileExtensions": [
|
||||||
|
"js",
|
||||||
|
"json"
|
||||||
|
],
|
||||||
|
"collectCoverage": true,
|
||||||
|
"collectCoverageFrom": [
|
||||||
|
"src/**/*.js",
|
||||||
|
"!**/node_modules/**",
|
||||||
|
"!**/build/**",
|
||||||
|
"!**/coverage/**"
|
||||||
|
],
|
||||||
|
"coverageThreshold": {
|
||||||
|
"global": {
|
||||||
|
"branches": 100,
|
||||||
|
"functions": 100,
|
||||||
|
"lines": 100,
|
||||||
|
"statements": 100
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"coverageReporters": [
|
||||||
|
"text",
|
||||||
|
"text-summary"
|
||||||
|
],
|
||||||
|
"testRegex": "/test/.*.js$",
|
||||||
|
"testPathIgnorePatterns": [
|
||||||
|
"/node_modules/",
|
||||||
|
"/build/",
|
||||||
|
"/coverage/"
|
||||||
|
]
|
||||||
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC"
|
"license": "ISC"
|
||||||
|
|
|
@ -9,7 +9,6 @@ import Redis from 'async-redis'
|
||||||
/* DEFAULTS */
|
/* DEFAULTS */
|
||||||
const REDIS_HOST = process.env.REDIS_HOST || 'localhost'
|
const REDIS_HOST = process.env.REDIS_HOST || 'localhost'
|
||||||
const REDIS_PORT = process.env.REDIS_PORT || 6379
|
const REDIS_PORT = process.env.REDIS_PORT || 6379
|
||||||
const LISTEN_PORT = process.env.LISTEN_PORT || 3000
|
|
||||||
|
|
||||||
const app = new Koa()
|
const app = new Koa()
|
||||||
const router = new Router()
|
const router = new Router()
|
||||||
|
@ -23,6 +22,7 @@ app.on('error', (err, ctx) => {
|
||||||
router.put('/clicks/:id', async ctx => {
|
router.put('/clicks/:id', async ctx => {
|
||||||
counter.incr(ctx.params.id)
|
counter.incr(ctx.params.id)
|
||||||
ctx.body = { [ctx.params.id]: await counter.state(ctx.params.id) }
|
ctx.body = { [ctx.params.id]: await counter.state(ctx.params.id) }
|
||||||
|
ctx.status = 201
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/clicks', async ctx => {
|
router.get('/clicks', async ctx => {
|
||||||
|
@ -38,6 +38,4 @@ app.use(Logger())
|
||||||
.use(router.routes())
|
.use(router.routes())
|
||||||
.use(router.allowedMethods())
|
.use(router.allowedMethods())
|
||||||
|
|
||||||
app.listen(LISTEN_PORT)
|
module.exports = app
|
||||||
console.log(`Redis connection: ${REDIS_HOST}:${REDIS_PORT}`)
|
|
||||||
console.log(`Started at: http://localhost:${LISTEN_PORT}/`)
|
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
import app from './app'
|
||||||
|
|
||||||
|
/* DEFAULTS */
|
||||||
|
const REDIS_HOST = process.env.REDIS_HOST || 'localhost'
|
||||||
|
const REDIS_PORT = process.env.REDIS_PORT || 6379
|
||||||
|
const LISTEN_PORT = process.env.LISTEN_PORT || 3000
|
||||||
|
|
||||||
|
app.listen(LISTEN_PORT)
|
||||||
|
console.log(`Redis connection: ${REDIS_HOST}:${REDIS_PORT}`)
|
||||||
|
console.log(`Started at: http://localhost:${LISTEN_PORT}/`)
|
|
@ -0,0 +1,12 @@
|
||||||
|
import request from 'supertest'
|
||||||
|
import app from '../src/app'
|
||||||
|
|
||||||
|
test('incrementing clicks works', async () => {
|
||||||
|
let resp = await request(app.callback()).put('/clicks/id')
|
||||||
|
expect(resp.status).toBe(201)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('clicks works', async () => {
|
||||||
|
let resp = await request(app.callback()).get('/clicks')
|
||||||
|
expect(resp.status).toBe(200)
|
||||||
|
})
|
Loading…
Reference in New Issue