diff --git a/services/track-changes/.mocharc.json b/services/track-changes/.mocharc.json new file mode 100644 index 0000000000..dc3280aa96 --- /dev/null +++ b/services/track-changes/.mocharc.json @@ -0,0 +1,3 @@ +{ + "require": "test/setup.js" +} diff --git a/services/track-changes/test/acceptance/js/AppendingUpdatesTests.js b/services/track-changes/test/acceptance/js/AppendingUpdatesTests.js index 4cf250cfac..def0bdfa1d 100644 --- a/services/track-changes/test/acceptance/js/AppendingUpdatesTests.js +++ b/services/track-changes/test/acceptance/js/AppendingUpdatesTests.js @@ -11,9 +11,7 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ const sinon = require('sinon') -const chai = require('chai') -chai.should() -const { expect } = chai +const { expect } = require('chai') const { ObjectId } = require('../../../app/js/mongodb') const Settings = require('settings-sharelatex') const request = require('request') diff --git a/services/track-changes/test/acceptance/js/ArchivingUpdatesTests.js b/services/track-changes/test/acceptance/js/ArchivingUpdatesTests.js index bb1024389c..a17ad6f1de 100644 --- a/services/track-changes/test/acceptance/js/ArchivingUpdatesTests.js +++ b/services/track-changes/test/acceptance/js/ArchivingUpdatesTests.js @@ -15,9 +15,7 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ const sinon = require('sinon') -const chai = require('chai') -chai.should() -const { expect } = chai +const { expect } = require('chai') const { db, ObjectId } = require('../../../app/js/mongodb') const Settings = require('settings-sharelatex') const request = require('request') diff --git a/services/track-changes/test/acceptance/js/FlushingUpdatesTests.js b/services/track-changes/test/acceptance/js/FlushingUpdatesTests.js index a48abcc976..c9adeb5fd8 100644 --- a/services/track-changes/test/acceptance/js/FlushingUpdatesTests.js +++ b/services/track-changes/test/acceptance/js/FlushingUpdatesTests.js @@ -11,9 +11,7 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ const sinon = require('sinon') -const chai = require('chai') -chai.should() -const { expect } = chai +const { expect } = require('chai') const { ObjectId } = require('../../../app/js/mongodb') const Settings = require('settings-sharelatex') const request = require('request') diff --git a/services/track-changes/test/acceptance/js/GettingADiffTests.js b/services/track-changes/test/acceptance/js/GettingADiffTests.js index 926d005164..9ccc2cca36 100644 --- a/services/track-changes/test/acceptance/js/GettingADiffTests.js +++ b/services/track-changes/test/acceptance/js/GettingADiffTests.js @@ -10,9 +10,7 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ const sinon = require('sinon') -const chai = require('chai') -chai.should() -const { expect } = chai +const { expect } = require('chai') const { ObjectId } = require('../../../app/js/mongodb') const Settings = require('settings-sharelatex') diff --git a/services/track-changes/test/acceptance/js/GettingUpdatesTests.js b/services/track-changes/test/acceptance/js/GettingUpdatesTests.js index 83bd985241..f216d987a4 100644 --- a/services/track-changes/test/acceptance/js/GettingUpdatesTests.js +++ b/services/track-changes/test/acceptance/js/GettingUpdatesTests.js @@ -11,9 +11,7 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ const sinon = require('sinon') -const chai = require('chai') -chai.should() -const { expect } = chai +const { expect } = require('chai') const { ObjectId } = require('../../../app/js/mongodb') const Settings = require('settings-sharelatex') diff --git a/services/track-changes/test/acceptance/js/LockManagerTests.js b/services/track-changes/test/acceptance/js/LockManagerTests.js index b6f8908554..7062a83237 100644 --- a/services/track-changes/test/acceptance/js/LockManagerTests.js +++ b/services/track-changes/test/acceptance/js/LockManagerTests.js @@ -10,9 +10,7 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ const sinon = require('sinon') -const chai = require('chai') -chai.should() -const { expect } = chai +const { expect } = require('chai') const Settings = require('settings-sharelatex') const LockManager = require('../../../app/js/LockManager') const rclient = require('redis').createClient(Settings.redis.history) // Only works locally for now diff --git a/services/track-changes/test/acceptance/js/RestoringVersions.js b/services/track-changes/test/acceptance/js/RestoringVersions.js index d4d5d60304..a947dc09df 100644 --- a/services/track-changes/test/acceptance/js/RestoringVersions.js +++ b/services/track-changes/test/acceptance/js/RestoringVersions.js @@ -10,9 +10,7 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ const sinon = require('sinon') -const chai = require('chai') -chai.should() -const { expect } = chai +const { expect } = require('chai') const { ObjectId } = require('../../../app/js/mongodb') const Settings = require('settings-sharelatex') diff --git a/services/track-changes/test/acceptance/js/helpers/TrackChangesApp.js b/services/track-changes/test/acceptance/js/helpers/TrackChangesApp.js index 6ef1127f06..861dcdde88 100644 --- a/services/track-changes/test/acceptance/js/helpers/TrackChangesApp.js +++ b/services/track-changes/test/acceptance/js/helpers/TrackChangesApp.js @@ -14,7 +14,6 @@ */ const app = require('../../../../app') const { waitForDb } = require('../../../../app/js/mongodb') -require('logger-sharelatex') const logger = require('logger-sharelatex') const Settings = require('settings-sharelatex') diff --git a/services/track-changes/test/setup.js b/services/track-changes/test/setup.js new file mode 100644 index 0000000000..9ebe599cea --- /dev/null +++ b/services/track-changes/test/setup.js @@ -0,0 +1,21 @@ +const chai = require('chai') +const SandboxedModule = require('sandboxed-module') + +// Chai configuration +chai.should() + +// SandboxedModule configuration +SandboxedModule.configure({ + requires: { + 'logger-sharelatex': { + debug() {}, + log() {}, + info() {}, + warn() {}, + err() {}, + error() {}, + fatal() {} + } + }, + globals: { Buffer, JSON, console, process } +}) diff --git a/services/track-changes/test/unit/js/DiffGenerator/DiffGeneratorTests.js b/services/track-changes/test/unit/js/DiffGenerator/DiffGeneratorTests.js index 6526c9445d..75a8ab2c0f 100644 --- a/services/track-changes/test/unit/js/DiffGenerator/DiffGeneratorTests.js +++ b/services/track-changes/test/unit/js/DiffGenerator/DiffGeneratorTests.js @@ -11,19 +11,13 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ const sinon = require('sinon') -const chai = require('chai') -const should = chai.should() -const { expect } = chai +const { expect } = require('chai') const modulePath = '../../../../app/js/DiffGenerator.js' const SandboxedModule = require('sandboxed-module') describe('DiffGenerator', function () { beforeEach(function () { - this.DiffGenerator = SandboxedModule.require(modulePath, { - requires: { - 'logger-sharelatex': { warn: sinon.stub() } - } - }) + this.DiffGenerator = SandboxedModule.require(modulePath, {}) this.ts = Date.now() this.user_id = 'mock-user-id' this.user_id_2 = 'mock-user-id-2' diff --git a/services/track-changes/test/unit/js/DiffManager/DiffManagerTests.js b/services/track-changes/test/unit/js/DiffManager/DiffManagerTests.js index 7b72f3a002..b2f4ec6a59 100644 --- a/services/track-changes/test/unit/js/DiffManager/DiffManagerTests.js +++ b/services/track-changes/test/unit/js/DiffManager/DiffManagerTests.js @@ -11,9 +11,7 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ const sinon = require('sinon') -const chai = require('chai') -const should = chai.should() -const { expect } = chai +const { expect } = require('chai') const modulePath = '../../../../app/js/DiffManager.js' const SandboxedModule = require('sandboxed-module') @@ -21,11 +19,6 @@ describe('DiffManager', function () { beforeEach(function () { this.DiffManager = SandboxedModule.require(modulePath, { requires: { - 'logger-sharelatex': (this.logger = { - log: sinon.stub(), - error: sinon.stub(), - warn: sinon.stub() - }), './UpdatesManager': (this.UpdatesManager = {}), './DocumentUpdaterManager': (this.DocumentUpdaterManager = {}), './DiffGenerator': (this.DiffGenerator = {}) diff --git a/services/track-changes/test/unit/js/DocArchive/MongoAWS.js b/services/track-changes/test/unit/js/DocArchive/MongoAWS.js index 55c53046a4..dd4374e965 100644 --- a/services/track-changes/test/unit/js/DocArchive/MongoAWS.js +++ b/services/track-changes/test/unit/js/DocArchive/MongoAWS.js @@ -9,8 +9,6 @@ * DS102: Remove unnecessary code created because of implicit returns * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ -const chai = require('chai') -chai.should() const sinon = require('sinon') const modulePath = '../../../../app/js/MongoAWS.js' const SandboxedModule = require('sandboxed-module') @@ -36,11 +34,6 @@ describe('MongoAWS', function () { }), child_process: (this.child_process = {}), 'mongo-uri': (this.mongouri = {}), - 'logger-sharelatex': (this.logger = { - log: sinon.stub(), - error: sinon.stub(), - err() {} - }), 'aws-sdk': (this.awssdk = {}), fs: (this.fs = {}), 's3-streams': (this.S3S = {}), diff --git a/services/track-changes/test/unit/js/DocumentUpdaterManager/DocumentUpdaterManagerTests.js b/services/track-changes/test/unit/js/DocumentUpdaterManager/DocumentUpdaterManagerTests.js index 83f4bf04ad..2825a10fb5 100644 --- a/services/track-changes/test/unit/js/DocumentUpdaterManager/DocumentUpdaterManagerTests.js +++ b/services/track-changes/test/unit/js/DocumentUpdaterManager/DocumentUpdaterManagerTests.js @@ -10,9 +10,7 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ const sinon = require('sinon') -const chai = require('chai') -const should = chai.should() -const { expect } = chai +const { expect } = require('chai') const modulePath = '../../../../app/js/DocumentUpdaterManager.js' const SandboxedModule = require('sandboxed-module') @@ -21,10 +19,6 @@ describe('DocumentUpdaterManager', function () { this.DocumentUpdaterManager = SandboxedModule.require(modulePath, { requires: { request: (this.request = {}), - 'logger-sharelatex': (this.logger = { - log: sinon.stub(), - error: sinon.stub() - }), 'settings-sharelatex': (this.settings = { apis: { documentupdater: { url: 'http://example.com' } } }) diff --git a/services/track-changes/test/unit/js/HttpController/HttpControllerTests.js b/services/track-changes/test/unit/js/HttpController/HttpControllerTests.js index 08509f6b28..9746213922 100644 --- a/services/track-changes/test/unit/js/HttpController/HttpControllerTests.js +++ b/services/track-changes/test/unit/js/HttpController/HttpControllerTests.js @@ -10,9 +10,7 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ const sinon = require('sinon') -const chai = require('chai') -const should = chai.should() -const { expect } = chai +const { expect } = require('chai') const modulePath = '../../../../app/js/HttpController.js' const SandboxedModule = require('sandboxed-module') @@ -21,7 +19,6 @@ describe('HttpController', function () { this.HttpController = SandboxedModule.require(modulePath, { singleOnly: true, requires: { - 'logger-sharelatex': { log: sinon.stub() }, './UpdatesManager': (this.UpdatesManager = {}), './DiffManager': (this.DiffManager = {}), './RestoreManager': (this.RestoreManager = {}), diff --git a/services/track-changes/test/unit/js/LockManager/LockManagerTests.js b/services/track-changes/test/unit/js/LockManager/LockManagerTests.js index 42ee6dcd62..fc26997574 100644 --- a/services/track-changes/test/unit/js/LockManager/LockManagerTests.js +++ b/services/track-changes/test/unit/js/LockManager/LockManagerTests.js @@ -16,9 +16,7 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ const sinon = require('sinon') -const chai = require('chai') -const should = chai.should() -const { expect } = chai +const { expect } = require('chai') const modulePath = '../../../../app/js/LockManager.js' const SandboxedModule = require('sandboxed-module') @@ -36,8 +34,7 @@ describe('LockManager', function () { return (this.rclient = { auth: sinon.stub() }) } }, - 'settings-sharelatex': this.Settings, - 'logger-sharelatex': { error() {} } + 'settings-sharelatex': this.Settings } }) diff --git a/services/track-changes/test/unit/js/MongoManager/MongoManagerTests.js b/services/track-changes/test/unit/js/MongoManager/MongoManagerTests.js index 70f3d6f4f5..d96b27d8d0 100644 --- a/services/track-changes/test/unit/js/MongoManager/MongoManagerTests.js +++ b/services/track-changes/test/unit/js/MongoManager/MongoManagerTests.js @@ -10,9 +10,7 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ const sinon = require('sinon') -const chai = require('chai') -const should = chai.should() -const { expect } = chai +const { expect } = require('chai') const modulePath = '../../../../app/js/MongoManager.js' const packModulePath = '../../../../app/js/PackManager.js' const SandboxedModule = require('sandboxed-module') @@ -26,8 +24,7 @@ describe('MongoManager', function () { requires: { './mongodb': { db: (this.db = {}), ObjectId }, './PackManager': (this.PackManager = {}), - '@overleaf/metrics': { timeAsyncMethod() {} }, - 'logger-sharelatex': { log() {} } + '@overleaf/metrics': { timeAsyncMethod() {} } } }) this.callback = sinon.stub() diff --git a/services/track-changes/test/unit/js/PackManager/PackManagerTests.js b/services/track-changes/test/unit/js/PackManager/PackManagerTests.js index b0092f8df7..957c22aac8 100644 --- a/services/track-changes/test/unit/js/PackManager/PackManagerTests.js +++ b/services/track-changes/test/unit/js/PackManager/PackManagerTests.js @@ -11,10 +11,7 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ const sinon = require('sinon') -const chai = require('chai') -const { assert } = require('chai') -const should = chai.should() -const { expect } = chai +const { assert, expect } = require('chai') const modulePath = '../../../../app/js/PackManager.js' const SandboxedModule = require('sandboxed-module') const { ObjectId } = require('mongodb') @@ -31,7 +28,6 @@ describe('PackManager', function () { './mongodb': { db: (this.db = {}), ObjectId }, './LockManager': {}, './MongoAWS': {}, - 'logger-sharelatex': { log: sinon.stub(), error: sinon.stub() }, '@overleaf/metrics': { inc() {} }, './ProjectIterator': require('../../../../app/js/ProjectIterator.js'), // Cache for speed 'settings-sharelatex': { diff --git a/services/track-changes/test/unit/js/RedisManager/RedisManagerTests.js b/services/track-changes/test/unit/js/RedisManager/RedisManagerTests.js index f3185daf08..13fa467570 100644 --- a/services/track-changes/test/unit/js/RedisManager/RedisManagerTests.js +++ b/services/track-changes/test/unit/js/RedisManager/RedisManagerTests.js @@ -12,9 +12,7 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ const sinon = require('sinon') -const chai = require('chai') -const should = chai.should() -const { expect } = chai +const { expect } = require('chai') const modulePath = '../../../../app/js/RedisManager.js' const SandboxedModule = require('sandboxed-module') diff --git a/services/track-changes/test/unit/js/RestoreManager/RestoreManagerTests.js b/services/track-changes/test/unit/js/RestoreManager/RestoreManagerTests.js index 7e9c6896b0..dd664a6003 100644 --- a/services/track-changes/test/unit/js/RestoreManager/RestoreManagerTests.js +++ b/services/track-changes/test/unit/js/RestoreManager/RestoreManagerTests.js @@ -10,9 +10,7 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ const sinon = require('sinon') -const chai = require('chai') -const should = chai.should() -const { expect } = chai +const { expect } = require('chai') const modulePath = '../../../../app/js/RestoreManager.js' const SandboxedModule = require('sandboxed-module') @@ -20,10 +18,6 @@ describe('RestoreManager', function () { beforeEach(function () { this.RestoreManager = SandboxedModule.require(modulePath, { requires: { - 'logger-sharelatex': (this.logger = { - log: sinon.stub(), - error: sinon.stub() - }), './DocumentUpdaterManager': (this.DocumentUpdaterManager = {}), './DiffManager': (this.DiffManager = {}) } diff --git a/services/track-changes/test/unit/js/UpdateCompressor/UpdateCompressorTests.js b/services/track-changes/test/unit/js/UpdateCompressor/UpdateCompressorTests.js index 110b8ed1c8..a703ae8084 100644 --- a/services/track-changes/test/unit/js/UpdateCompressor/UpdateCompressorTests.js +++ b/services/track-changes/test/unit/js/UpdateCompressor/UpdateCompressorTests.js @@ -10,9 +10,7 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ const sinon = require('sinon') -const chai = require('chai') -const should = chai.should() -const { expect } = chai +const { expect } = require('chai') const modulePath = '../../../../app/js/UpdateCompressor.js' const SandboxedModule = require('sandboxed-module') diff --git a/services/track-changes/test/unit/js/UpdateTrimmer/UpdateTrimmerTests.js b/services/track-changes/test/unit/js/UpdateTrimmer/UpdateTrimmerTests.js index 5623954230..2d89a3520d 100644 --- a/services/track-changes/test/unit/js/UpdateTrimmer/UpdateTrimmerTests.js +++ b/services/track-changes/test/unit/js/UpdateTrimmer/UpdateTrimmerTests.js @@ -10,9 +10,7 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ const sinon = require('sinon') -const chai = require('chai') -const should = chai.should() -const { expect } = chai +const { expect } = require('chai') const modulePath = '../../../../app/js/UpdateTrimmer.js' const SandboxedModule = require('sandboxed-module') const tk = require('timekeeper') @@ -24,10 +22,6 @@ describe('UpdateTrimmer', function () { this.UpdateTrimmer = SandboxedModule.require(modulePath, { requires: { - 'logger-sharelatex': (this.logger = { - log: sinon.stub(), - error: sinon.stub() - }), './WebApiManager': (this.WebApiManager = {}), './MongoManager': (this.MongoManager = {}) } diff --git a/services/track-changes/test/unit/js/UpdatesManager/UpdatesManagerTests.js b/services/track-changes/test/unit/js/UpdatesManager/UpdatesManagerTests.js index ed7c4b064e..b90d1567c8 100644 --- a/services/track-changes/test/unit/js/UpdatesManager/UpdatesManagerTests.js +++ b/services/track-changes/test/unit/js/UpdatesManager/UpdatesManagerTests.js @@ -14,9 +14,7 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ const sinon = require('sinon') -const chai = require('chai') -const should = chai.should() -const { expect } = chai +const { expect } = require('chai') const { ObjectId } = require('mongodb') const modulePath = '../../../../app/js/UpdatesManager.js' const SandboxedModule = require('sandboxed-module') @@ -34,7 +32,6 @@ describe('UpdatesManager', function () { './WebApiManager': (this.WebApiManager = {}), './UpdateTrimmer': (this.UpdateTrimmer = {}), './DocArchiveManager': (this.DocArchiveManager = {}), - 'logger-sharelatex': { log: sinon.stub(), error: sinon.stub() }, 'settings-sharelatex': { redis: { lock: { diff --git a/services/track-changes/test/unit/js/WebApiManager/WebApiManagerTests.js b/services/track-changes/test/unit/js/WebApiManager/WebApiManagerTests.js index 5aca308be2..7e23e72b0a 100644 --- a/services/track-changes/test/unit/js/WebApiManager/WebApiManagerTests.js +++ b/services/track-changes/test/unit/js/WebApiManager/WebApiManagerTests.js @@ -10,9 +10,7 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ const sinon = require('sinon') -const chai = require('chai') -const should = chai.should() -const { expect } = chai +const { expect } = require('chai') const modulePath = '../../../../app/js/WebApiManager.js' const SandboxedModule = require('sandboxed-module') @@ -21,10 +19,6 @@ describe('WebApiManager', function () { this.WebApiManager = SandboxedModule.require(modulePath, { requires: { requestretry: (this.request = {}), - 'logger-sharelatex': (this.logger = { - log: sinon.stub(), - error: sinon.stub() - }), 'settings-sharelatex': (this.settings = { apis: { web: {