From c68e1a2dfe9b944161fed802908fbd6f273e535b Mon Sep 17 00:00:00 2001 From: Eric Mc Sween Date: Fri, 12 Mar 2021 16:39:45 -0500 Subject: [PATCH] Add a global test setup Configure SandboxedModule with common options, including some globals that are required in Node 12. --- services/contacts/.mocharc.json | 3 +++ services/contacts/test/setup.js | 9 +++++++++ services/contacts/test/unit/js/ContactsManagerTests.js | 4 +--- services/contacts/test/unit/js/HttpControllerTests.js | 3 +-- 4 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 services/contacts/.mocharc.json create mode 100644 services/contacts/test/setup.js diff --git a/services/contacts/.mocharc.json b/services/contacts/.mocharc.json new file mode 100644 index 0000000000..dc3280aa96 --- /dev/null +++ b/services/contacts/.mocharc.json @@ -0,0 +1,3 @@ +{ + "require": "test/setup.js" +} diff --git a/services/contacts/test/setup.js b/services/contacts/test/setup.js new file mode 100644 index 0000000000..eb9883ffcc --- /dev/null +++ b/services/contacts/test/setup.js @@ -0,0 +1,9 @@ +const SandboxedModule = require('sandboxed-module') + +SandboxedModule.configure({ + requires: { + 'logger-sharelatex': { log() {} }, + '@overleaf/metrics': { timeAsyncMethod() {} } + }, + globals: { Buffer, console, process } +}) diff --git a/services/contacts/test/unit/js/ContactsManagerTests.js b/services/contacts/test/unit/js/ContactsManagerTests.js index 5d38f88540..aa4af08a66 100644 --- a/services/contacts/test/unit/js/ContactsManagerTests.js +++ b/services/contacts/test/unit/js/ContactsManagerTests.js @@ -26,9 +26,7 @@ describe('ContactManager', function () { './mongodb': { db: (this.db = { contacts: {} }), ObjectId - }, - 'logger-sharelatex': { log: sinon.stub() }, - '@overleaf/metrics': { timeAsyncMethod: sinon.stub() } + } } }) this.user_id = ObjectId().toString() diff --git a/services/contacts/test/unit/js/HttpControllerTests.js b/services/contacts/test/unit/js/HttpControllerTests.js index e136f4135b..e458acfb5c 100644 --- a/services/contacts/test/unit/js/HttpControllerTests.js +++ b/services/contacts/test/unit/js/HttpControllerTests.js @@ -21,8 +21,7 @@ describe('HttpController', function () { beforeEach(function () { this.HttpController = SandboxedModule.require(modulePath, { requires: { - './ContactManager': (this.ContactManager = {}), - 'logger-sharelatex': (this.logger = { log: sinon.stub() }) + './ContactManager': (this.ContactManager = {}) } }) this.user_id = 'mock-user-id'