mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Add global test setup
Configure chai and SandboxedModule in a central place. Configure SandboxedModule globals that are required in Node 12.
This commit is contained in:
parent
ccb8a022a9
commit
a793ecd41b
24 changed files with 47 additions and 102 deletions
3
services/track-changes/.mocharc.json
Normal file
3
services/track-changes/.mocharc.json
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"require": "test/setup.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')
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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')
|
||||
|
||||
|
|
|
@ -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')
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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')
|
||||
|
||||
|
|
|
@ -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')
|
||||
|
||||
|
|
21
services/track-changes/test/setup.js
Normal file
21
services/track-changes/test/setup.js
Normal file
|
@ -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 }
|
||||
})
|
|
@ -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'
|
||||
|
|
|
@ -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 = {})
|
||||
|
|
|
@ -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 = {}),
|
||||
|
|
|
@ -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' } }
|
||||
})
|
||||
|
|
|
@ -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 = {}),
|
||||
|
|
|
@ -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
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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': {
|
||||
|
|
|
@ -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')
|
||||
|
||||
|
|
|
@ -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 = {})
|
||||
}
|
||||
|
|
|
@ -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')
|
||||
|
||||
|
|
|
@ -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 = {})
|
||||
}
|
||||
|
|
|
@ -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: {
|
||||
|
|
|
@ -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: {
|
||||
|
|
Loading…
Reference in a new issue