Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit fca1c07

Browse files
author
Hans Kristian Flaatten
committed
jenkins: add lint and test stages
1 parent 0ad3ea0 commit fca1c07

8 files changed

+3387
-106
lines changed

.dockerignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
app/.eslintrc.json
2+
app/test.js
3+
app/yarn.lock

Dockerfile

-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ FROM node:8-alpine
22

33
WORKDIR /usr/src/app
44

5-
ADD ./app/package.json ./app/yarn.lock /usr/src/app/
6-
7-
RUN yarn install --production && yarn cache clean
8-
95
ADD ./app /usr/src/app/
106

117
CMD [ "node", "index.js" ]

Jenkinsfile

+26-2
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,36 @@ node('jenkins-docker-2') {
2626
checkout scm
2727
}
2828

29-
stage('Build') {
29+
stage('Install') {
30+
docker.image('node:8-alpine').inside() {
31+
sh 'yarn install --development'
32+
}
33+
}
34+
35+
stage('Lint') {
36+
docker.image('node-8-alpine').inside() {
37+
sh 'yarn run lint'
38+
}
39+
}
40+
41+
stage('Test') {
42+
docker.image('node-8-alpine').inside() {
43+
sh 'yarn run test'
44+
}
45+
}
46+
47+
stage('Prune') {
48+
docker.image('node-8-alpine').inside() {
49+
sh 'yarn install --production'
50+
}
51+
}
52+
53+
stage('Docker Build') {
3054
conf.DOCKER_IMAGE = "${conf.REGISTRY}/${conf.NAME}:${conf.TAG}"
3155
image = docker.build(conf.DOCKER_IMAGE)
3256
}
3357

34-
stage('Push') {
58+
stage('Docker Push') {
3559
docker.withRegistry("https://${conf.REGISTRY}", conf.REGISTRY) {
3660
image.push()
3761
}

app/.eslintrc.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "airbnb-base",
3+
"plugins": [
4+
"import"
5+
]
6+
}

app/index.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
const express = require('express')
2-
const app = express()
1+
const express = require('express');
32

4-
app.get('/', function (req, res) {
5-
res.send('Hello World!')
6-
})
3+
const app = express();
74

8-
app.listen(3000, function () {
9-
console.log('Example app listening on port 3000!')
10-
})
5+
app.get('/', (req, res) => res.send('Hello World!'));
6+
7+
if (!module.parent) {
8+
// eslint-disable-next-line no-console
9+
app.listen(3000, () => console.log('Example app listening on port 3000!'));
10+
}
11+
12+
module.exports = app;

app/package.json

+11
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,16 @@
88
"license": "MIT",
99
"dependencies": {
1010
"express": "^4.15.3"
11+
},
12+
"devDependencies": {
13+
"ava": "^0.19.1",
14+
"eslint": "^4.0.0",
15+
"eslint-config-airbnb-base": "^11.2.0",
16+
"eslint-plugin-import": "^2.5.0",
17+
"supertest": "^3.0.0"
18+
},
19+
"scripts": {
20+
"test": "ava",
21+
"lint": "eslint *.js"
1122
}
1223
}

app/test.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import supertest from 'supertest';
2+
3+
import test from 'ava';
4+
5+
import app from '.';
6+
7+
const req = supertest(app);
8+
9+
test('index', async (t) => {
10+
t.plan(2);
11+
12+
const res = await req.get('/');
13+
14+
t.is(res.status, 200);
15+
t.is(res.text, 'Hello World!');
16+
});

0 commit comments

Comments
 (0)