diff --git a/test/fixtures/env.js b/test/fixtures/env.js index 6e4dffba..ccf9b90a 100644 --- a/test/fixtures/env.js +++ b/test/fixtures/env.js @@ -1,11 +1,6 @@ "use strict"; -global.log = { - error: () => console.error.apply(console, arguments), // eslint-disable-line no-console - warn: () => {}, - info: () => {}, - debug: () => {}, -}; +global.log = require("../../src/log.js"); var home = require("path").join(__dirname, ".lounge"); require("../../src/helper").setHome(home); diff --git a/test/plugins/auth/ldap.js b/test/plugins/auth/ldap.js index a52d7004..7b9213eb 100644 --- a/test/plugins/auth/ldap.js +++ b/test/plugins/auth/ldap.js @@ -111,15 +111,23 @@ function testLdapAuth() { describe("LDAP authentication plugin", function() { this.slow(200); - before((done) => { - this.server = startLdapServer(done); + let server; + let originalLogInfo; + + before(function(done) { + originalLogInfo = log.info; + log.info = () => {}; + + server = startLdapServer(done); }); - after(() => { - this.server.close(); + after(function() { + server.close(); + + log.info = originalLogInfo; }); - beforeEach(() => { + beforeEach(function() { Helper.config.public = false; Helper.config.ldap.enable = true; Helper.config.ldap.url = "ldap://localhost:" + String(serverPort); diff --git a/test/plugins/link.js b/test/plugins/link.js index f1c45699..65c8127f 100644 --- a/test/plugins/link.js +++ b/test/plugins/link.js @@ -9,25 +9,25 @@ const link = require("../../src/plugins/irc-events/link.js"); describe("Link plugin", function() { this.slow(200); - before(function(done) { - this.app = util.createWebserver(); - this.app.get("/real-test-image.png", function(req, res) { + let app; + + beforeEach(function(done) { + app = util.createWebserver(); + app.get("/real-test-image.png", function(req, res) { res.sendFile(path.resolve(__dirname, "../../client/img/apple-touch-icon-120x120.png")); }); - this.connection = this.app.listen(9002, done); - }); + this.connection = app.listen(9002, done); - after(function(done) { - this.connection.close(done); - }); - - beforeEach(function() { this.irc = util.createClient(); this.network = util.createNetwork(); Helper.config.prefetchStorage = false; }); + afterEach(function(done) { + this.connection.close(done); + }); + it("should be able to fetch basic information about URLs", function(done) { const url = "http://localhost:9002/basic"; const message = this.irc.createMessage({ @@ -45,7 +45,7 @@ describe("Link plugin", function() { shown: true, }]); - this.app.get("/basic", function(req, res) { + app.get("/basic", function(req, res) { res.send("test title"); }); @@ -67,7 +67,7 @@ describe("Link plugin", function() { link(this.irc, this.network.channels[0], message); - this.app.get("/basic-og", function(req, res) { + app.get("/basic-og", function(req, res) { res.send("test"); }); @@ -84,7 +84,7 @@ describe("Link plugin", function() { link(this.irc, this.network.channels[0], message); - this.app.get("/description-og", function(req, res) { + app.get("/description-og", function(req, res) { res.send(""); }); @@ -101,7 +101,7 @@ describe("Link plugin", function() { link(this.irc, this.network.channels[0], message); - this.app.get("/thumb", function(req, res) { + app.get("/thumb", function(req, res) { res.send("Google"); }); @@ -119,7 +119,7 @@ describe("Link plugin", function() { link(this.irc, this.network.channels[0], message); - this.app.get("/thumb-image-src", function(req, res) { + app.get("/thumb-image-src", function(req, res) { res.send(""); }); @@ -136,7 +136,7 @@ describe("Link plugin", function() { link(this.irc, this.network.channels[0], message); - this.app.get("/thumb-image-src", function(req, res) { + app.get("/thumb-image-src", function(req, res) { res.send(""); }); @@ -153,7 +153,7 @@ describe("Link plugin", function() { link(this.irc, this.network.channels[0], message); - this.app.get("/relative-thumb", function(req, res) { + app.get("/relative-thumb", function(req, res) { res.send("test relative image"); }); @@ -172,7 +172,7 @@ describe("Link plugin", function() { link(this.irc, this.network.channels[0], message); - this.app.get("/thumb-no-title", function(req, res) { + app.get("/thumb-no-title", function(req, res) { res.send(""); }); @@ -191,7 +191,7 @@ describe("Link plugin", function() { link(this.irc, this.network.channels[0], message); - this.app.get("/thumb-404", function(req, res) { + app.get("/thumb-404", function(req, res) { res.send("404 image"); }); @@ -241,11 +241,11 @@ describe("Link plugin", function() { shown: true, }]); - this.app.get("/one", function(req, res) { + app.get("/one", function(req, res) { res.send("first title"); }); - this.app.get("/two", function(req, res) { + app.get("/two", function(req, res) { res.send("second title"); }); diff --git a/test/server.js b/test/server.js index b06a748a..3ed0ec40 100644 --- a/test/server.js +++ b/test/server.js @@ -8,13 +8,19 @@ const io = require("socket.io-client"); describe("Server", function() { this.timeout(5000); let server; + let originalLogInfo; + + before(function() { + originalLogInfo = log.info; + log.info = () => {}; - before(() => { server = require("../src/server")(); }); - after((done) => { + after(function(done) { server.close(done); + + log.info = originalLogInfo; }); const webURL = `http://${Helper.config.host}:${Helper.config.port}/`; diff --git a/test/util.js b/test/util.js index f598d459..6c13d06e 100644 --- a/test/util.js +++ b/test/util.js @@ -7,12 +7,8 @@ var express = require("express"); var Network = require("../src/models/network"); var Chan = require("../src/models/chan"); -function MockClient(opts) { +function MockClient() { this.user = {nick: "test-user"}; - - for (var k in opts) { - this[k] = opts[k]; - } } util.inherits(MockClient, EventEmitter);