From 5d6f6de379fc5a744e9784a9c522d2f7ccfb3174 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Fri, 23 Aug 2019 18:39:54 +0200 Subject: [PATCH] Export app as a separate entry from master.js Change the module exports from master.js to allow additional objects to be passed to allow better unit testing. --- master.js | 4 +++- master.spec.js | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/master.js b/master.js index 23a01acc..abd61b28 100644 --- a/master.js +++ b/master.js @@ -971,7 +971,9 @@ async function startServer() { } } -module.exports = app; +module.exports = { + app, +} if (module === require.main) { console.warn(` diff --git a/master.spec.js b/master.spec.js index 61cbf3cc..6c229611 100644 --- a/master.spec.js +++ b/master.spec.js @@ -4,7 +4,7 @@ const validateHTML = require('html5-validator'); const parallel = require('mocha.parallel'); const jwt = require("jsonwebtoken"); -const app = require('./master.js'); +const master = require('./master.js'); const config = require('./config.json'); const authenticate = require('lib/authenticate'); @@ -15,7 +15,7 @@ const token = jwt.sign( { id: "api" }, config.masterAuthSecret, { expiresIn: 600 }); async function get(path) { - return await request(app).get(path).expect(200); + return await request(master.app).get(path).expect(200); } async function getValidate(path) { @@ -46,7 +46,7 @@ describe('Master server endpoint testing', function() { it(`sends some HTML when accessing ${path}`, () => getValidate(path)); } }); - let persistentMaster = request(app); + let persistentMaster = request(master.app); describe("#POST /api/place", function() { it("adds an itemStack to the masters inventory", function() { return persistentMaster.post("/api/place").send({