Skip to content
Permalink
Browse files

Setup build and tests

  • Loading branch information...
bhubr committed Aug 31, 2019
1 parent f54053b commit b79f5fa27e1a3606ad9548b5567349e615e5e6df

This file was deleted.

@@ -1 +1,2 @@
node_modules
build
@@ -0,0 +1,8 @@
// .prettierrc.js
module.exports = {
trailingComma: 'es5',
tabWidth: 2,
semi: true,
singleQuote: true
};

@@ -0,0 +1,3 @@
module.exports = {
presets: [['@babel/preset-env', {targets: {node: 'current'}}]],
};
@@ -4,8 +4,9 @@
"description": "",
"main": "build/index.js",
"scripts": {
"build": "npx babel src -d build",
"start": "nodemon --exec ./node_modules/@babel/node/bin/babel-node.js src/index",
"test": "echo \"Error: no test specified\" && exit 1"
"test": "jest"
},
"keywords": [],
"author": "",
@@ -19,6 +20,9 @@
"@babel/core": "^7.5.5",
"@babel/node": "^7.5.5",
"@babel/preset-env": "^7.5.5",
"nodemon": "^1.19.1"
"jest": "^24.9.0",
"nodemon": "^1.19.1",
"prettier": "^1.18.2",
"supertest": "^4.0.2"
}
}
@@ -0,0 +1,9 @@
// src/app.js
import express from 'express';
import bodyParser from 'body-parser';

const app = express();

app.get('/', (req, res) => res.json({ foo: 'bar' }));

module.exports = app;
@@ -1,9 +1,7 @@
// src/index.js
import express from 'express';
import bodyParser from 'body-parser';
import app from './app';

const port = process.env.PORT || 5000;
const app = express();

app.listen(port, (err) => {
if (err) {
@@ -12,4 +10,3 @@ app.listen(port, (err) => {
console.log(`Listening on port ${port}`);
}
});

@@ -0,0 +1,17 @@
// test/app.integration.test.js
import request from 'supertest';
import app from '../src/app';

describe('app', () => {
it('GETs / and should obtain { foo: "bar" }', async () => {
expect.assertions(1);
const res = await request(app)
.get('/')
.expect(200);
expect(res.body).toMatchInlineSnapshot(`
Object {
"foo": "bar",
}
`);
});
});

0 comments on commit b79f5fa

Please sign in to comment.
You can’t perform that action at this time.