From b008e9088aa2d4a2cc0f3fd0824e9529db0d749c Mon Sep 17 00:00:00 2001 From: flifloo Date: Thu, 4 Jun 2020 10:44:34 +0200 Subject: [PATCH] Setup testing --- .gitlab-ci.yml | 2 +- app.js | 2 ++ package.json | 8 +++++++- test/test-pages.js | 14 ++++++++++++++ 4 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 test/test-pages.js diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b6f96ba..b46dd06 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,4 +3,4 @@ image: node all_tests: script: - npm install - - node app.js + - npm test diff --git a/app.js b/app.js index d6cb6fa..2d10961 100644 --- a/app.js +++ b/app.js @@ -54,3 +54,5 @@ io.on("connection", (socket) => { request.end(); }) }); + +module.exports = server; diff --git a/package.json b/package.json index 94f3c57..a51ad8e 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "description": "Internet security awareness campaigns", "main": "app.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "start": "node app.js", + "test": "./node_modules/.bin/mocha" }, "repository": { "type": "git", @@ -17,5 +18,10 @@ "morgan": "^1.10.0", "pug": "^2.0.4", "socket.io": "^2.3.0" + }, + "devDependencies": { + "chai": "^4.2.0", + "mocha": "^7.2.0", + "request": "^2.88.2" } } diff --git a/test/test-pages.js b/test/test-pages.js new file mode 100644 index 0000000..d6cfc73 --- /dev/null +++ b/test/test-pages.js @@ -0,0 +1,14 @@ +const expect = require("chai").expect; +const request = require("request"); +const server = require("../app"); + +it("Main page content", (done) => { + request("http://localhost:8080" , function(error, response) { + expect(response.statusCode).to.equal(200); + done(); + }); +}); + +after(() => { + server.close(); +});