Преглед изворни кода

Add a global test setup

Configure SandboxedModule with common options, including some globals
that are required in Node 12.
Eric Mc Sween пре 5 година
родитељ
комит
c68e1a2dfe

+ 3 - 0
services/contacts/.mocharc.json

@@ -0,0 +1,3 @@
+{
+  "require": "test/setup.js"
+}

+ 9 - 0
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 }
+})

+ 1 - 3
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()

+ 1 - 2
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'