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 and add SandboxedModule globals that are required in Node 12.
This commit is contained in:
parent
c3a4cf692b
commit
821972b791
4 changed files with 29 additions and 17 deletions
3
services/notifications/.mocharc.json
Normal file
3
services/notifications/.mocharc.json
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"require": "test/setup.js"
|
||||
}
|
21
services/notifications/test/setup.js
Normal file
21
services/notifications/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,8 +11,6 @@
|
|||
* 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 modulePath = '../../../app/js/NotificationsController.js'
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
const assert = require('assert')
|
||||
|
@ -27,7 +25,6 @@ describe('Notifications Controller', function () {
|
|||
this.notifications = {}
|
||||
this.controller = SandboxedModule.require(modulePath, {
|
||||
requires: {
|
||||
'logger-sharelatex': { log() {} },
|
||||
'./Notifications': this.notifications,
|
||||
'@overleaf/metrics': {
|
||||
inc: sinon.stub()
|
||||
|
|
|
@ -13,9 +13,7 @@
|
|||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
const sinon = require('sinon')
|
||||
const chai = require('chai')
|
||||
const expect = chai.should
|
||||
const should = chai.should()
|
||||
const { expect } = require('chai')
|
||||
const modulePath = '../../../app/js/Notifications.js'
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
const assert = require('assert')
|
||||
|
@ -43,16 +41,9 @@ describe('Notifications Tests', function () {
|
|||
|
||||
this.notifications = SandboxedModule.require(modulePath, {
|
||||
requires: {
|
||||
'logger-sharelatex': {
|
||||
log() {},
|
||||
error() {}
|
||||
},
|
||||
'settings-sharelatex': {},
|
||||
'./mongodb': { db: this.db, ObjectId },
|
||||
'@overleaf/metrics': { timeAsyncMethod: sinon.stub() }
|
||||
},
|
||||
globals: {
|
||||
console
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -109,7 +100,7 @@ describe('Notifications Tests', function () {
|
|||
user_id,
|
||||
this.stubbedNotification,
|
||||
(err) => {
|
||||
expect(err).not.exists
|
||||
expect(err).not.to.exist
|
||||
sinon.assert.calledWith(
|
||||
this.updateOneStub,
|
||||
this.expectedQuery,
|
||||
|
@ -131,7 +122,7 @@ describe('Notifications Tests', function () {
|
|||
user_id,
|
||||
this.stubbedNotification,
|
||||
(err) => {
|
||||
expect(err).not.exists
|
||||
expect(err).not.to.exist
|
||||
sinon.assert.notCalled(this.updateOneStub)
|
||||
return done()
|
||||
}
|
||||
|
@ -144,7 +135,7 @@ describe('Notifications Tests', function () {
|
|||
user_id,
|
||||
this.stubbedNotification,
|
||||
(err) => {
|
||||
expect(err).not.exists
|
||||
expect(err).not.to.exist
|
||||
sinon.assert.calledWith(
|
||||
this.updateOneStub,
|
||||
this.expectedQuery,
|
||||
|
@ -184,7 +175,7 @@ describe('Notifications Tests', function () {
|
|||
user_id,
|
||||
this.stubbedNotification,
|
||||
(err) => {
|
||||
expect(err).not.exists
|
||||
expect(err).not.to.exist
|
||||
sinon.assert.calledWith(
|
||||
this.updateOneStub,
|
||||
this.expectedQuery,
|
||||
|
|
Loading…
Reference in a new issue