Skip to content

Commit 17cacd9

Browse files
committedOct 20, 2020
Update Test
1 parent 18f2966 commit 17cacd9

9 files changed

+7721
-1999
lines changed
 

‎.babelrc

-3
This file was deleted.

‎.eslintrc.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = {
2+
env: {
3+
jest: true,
4+
},
5+
extends: [
6+
'google',
7+
'plugin:prettier/recommended',
8+
'plugin:import/errors',
9+
'plugin:import/warnings',
10+
],
11+
parser: 'babel-eslint',
12+
rules: {
13+
'prettier/prettier': ['error', { singleQuote: true }],
14+
},
15+
};

‎README.md

+18-5
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,30 @@
22

33
* <a href="#install">Installation</a>
44
* <a href="#usage">Usage</a>
5+
* <a href="#test">Test</a>
56

67
## Install
78

9+
Clone the repo:
10+
```sh
11+
$ git clone https://github.com/gcoderbh/nodejs-es6-starter-template.git [your_project_name]
812
```
9-
git clone https://github.com/gcoderbh/nodejs-es6-starter-template.git
10-
cd nodejs-es6-starter-template
11-
npm ci
12-
nodemon
13+
14+
Install dependency:
15+
```sh
16+
$ cd [your_project_name]
17+
$ npm ci
1318
```
1419

1520
## Usage
21+
```sh
22+
$ nodemon
23+
```
1624

1725
start development in `src/index.js`
18-
see in your browser at [http://localhost:3000](http://localhost:3000)
26+
see in your browser at [http://localhost:3000](http://localhost:3000)
27+
28+
## Test
29+
```sh
30+
$ npm run test
31+
```

‎__test__/index.spec.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import request from 'supertest';
2+
import app from '../src/app';
3+
4+
it('return 200 on get base url', async () => {
5+
return request(app).get('/').expect(200);
6+
});

‎babel.config.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
presets: [
3+
[
4+
'@babel/preset-env',
5+
{
6+
targets: {
7+
esmodules: true,
8+
},
9+
},
10+
],
11+
],
12+
};

‎package-lock.json

+7,624-1,965
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+17-6
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,34 @@
55
"main": "src/index.js",
66
"scripts": {
77
"build": "rimraf dist/ && babel ./src/ --out-dir dist/ --ignore ./node_modules,./.babelrc,./package.json,./npm-debug.log --copy-files",
8-
"start": "npm run build && node dist/index.js"
8+
"start": "npm run build && node dist/index.js",
9+
"test": "jest --watchAll --no-cache"
910
},
1011
"keywords": [
1112
"nodejs",
12-
"jsvascript",
13+
"javascript",
1314
"es6",
1415
"nodemon",
1516
"babel",
16-
"docker"
17+
"jest"
1718
],
1819
"author": "gcoderbh",
1920
"license": "MIT",
2021
"devDependencies": {
21-
"babel-cli": "^6.26.0",
22-
"babel-preset-es2015": "^6.24.1",
22+
"@babel/cli": "^7.12.1",
23+
"@babel/core": "^7.12.3",
24+
"@babel/plugin-transform-regenerator": "^7.12.1",
25+
"@babel/preset-env": "^7.12.1",
26+
"eslint": "^7.11.0",
27+
"eslint-config-google": "^0.14.0",
28+
"eslint-config-prettier": "^6.13.0",
29+
"eslint-plugin-import": "^2.22.1",
30+
"eslint-plugin-prettier": "^3.1.4",
31+
"jest": "^26.6.0",
2332
"nodemon": "^2.0.6",
24-
"rimraf": "^3.0.2"
33+
"prettier": "^2.1.2",
34+
"rimraf": "^3.0.2",
35+
"supertest": "^5.0.0"
2536
},
2637
"dependencies": {
2738
"express": "^4.17.1"

‎src/app.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import os from 'os';
2+
import express from 'express';
3+
4+
const app = express();
5+
6+
const getHostname = async () =>
7+
await new Promise((resolve) => {
8+
setTimeout(() => {
9+
resolve(os.hostname());
10+
}, 2000);
11+
});
12+
13+
app.get('/', async (req, res) => {
14+
const hostname = await getHostname();
15+
res.json({
16+
status: true,
17+
hostname,
18+
});
19+
});
20+
21+
export default app;

‎src/index.js

+8-20
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,11 @@
1-
import os from "os";
2-
import express from 'express'
1+
import app from './app';
32

4-
const app = express()
5-
const port = process.env.PORT || 3000
3+
const port = process.env.PORT || 3000;
64

7-
const getHostname = async () => await new Promise(resolve => {
8-
setTimeout(() => {
9-
resolve(os.hostname())
10-
}, 2000);
11-
})
5+
const start = async () => {
6+
app.listen(port, () => {
7+
console.log(`Server start at port ${port}`);
8+
});
9+
};
1210

13-
app.get('/', async(req, res) => {
14-
const hostname = await getHostname()
15-
res.json({
16-
status: true,
17-
hostname
18-
})
19-
})
20-
21-
app.listen(port, () => {
22-
console.log(`Server start at port ${port}`)
23-
})
11+
start();

0 commit comments

Comments
 (0)
Please sign in to comment.