mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Add global test setup
Configure SanboxedModule and chai in a central place. Configure SandboxedModule globals that are needed in Node 12.
This commit is contained in:
parent
f534ace5b3
commit
11261a0cb9
6 changed files with 30 additions and 30 deletions
3
services/spelling/.mocharc.json
Normal file
3
services/spelling/.mocharc.json
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"require": "test/setup.js"
|
||||||
|
}
|
21
services/spelling/test/setup.js
Normal file
21
services/spelling/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 }
|
||||||
|
})
|
|
@ -9,20 +9,13 @@
|
||||||
* DS102: Remove unnecessary code created because of implicit returns
|
* DS102: Remove unnecessary code created because of implicit returns
|
||||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||||
*/
|
*/
|
||||||
const chai = require('chai')
|
const { expect, assert } = require('chai')
|
||||||
const should = chai.should()
|
|
||||||
const SandboxedModule = require('sandboxed-module')
|
const SandboxedModule = require('sandboxed-module')
|
||||||
const { assert } = require('chai')
|
|
||||||
|
|
||||||
describe('ASpell', function () {
|
describe('ASpell', function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
return (this.ASpell = SandboxedModule.require('../../../app/js/ASpell', {
|
return (this.ASpell = SandboxedModule.require('../../../app/js/ASpell', {
|
||||||
requires: {
|
requires: {
|
||||||
'logger-sharelatex': {
|
|
||||||
log() {},
|
|
||||||
info() {},
|
|
||||||
err() {}
|
|
||||||
},
|
|
||||||
'@overleaf/metrics': {
|
'@overleaf/metrics': {
|
||||||
gauge() {},
|
gauge() {},
|
||||||
inc() {}
|
inc() {}
|
||||||
|
@ -93,7 +86,7 @@ describe('ASpell', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
return it('should return an error', function () {
|
return it('should return an error', function () {
|
||||||
return should.exist(this.error)
|
return expect(this.error).to.exist
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,7 @@
|
||||||
no-undef
|
no-undef
|
||||||
*/
|
*/
|
||||||
const sinon = require('sinon')
|
const sinon = require('sinon')
|
||||||
const chai = require('chai')
|
const { expect } = require('chai')
|
||||||
const { expect } = chai
|
|
||||||
const SandboxedModule = require('sandboxed-module')
|
const SandboxedModule = require('sandboxed-module')
|
||||||
const EventEmitter = require('events')
|
const EventEmitter = require('events')
|
||||||
|
|
||||||
|
@ -15,11 +14,6 @@ describe('ASpellWorker', function () {
|
||||||
'../../../app/js/ASpellWorker',
|
'../../../app/js/ASpellWorker',
|
||||||
{
|
{
|
||||||
requires: {
|
requires: {
|
||||||
'logger-sharelatex': {
|
|
||||||
log() {},
|
|
||||||
info() {},
|
|
||||||
err() {}
|
|
||||||
},
|
|
||||||
'@overleaf/metrics': {
|
'@overleaf/metrics': {
|
||||||
gauge() {},
|
gauge() {},
|
||||||
inc() {}
|
inc() {}
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
const sinon = require('sinon')
|
const sinon = require('sinon')
|
||||||
const chai = require('chai')
|
const { assert, expect } = require('chai')
|
||||||
const { expect } = chai
|
|
||||||
const SandboxedModule = require('sandboxed-module')
|
const SandboxedModule = require('sandboxed-module')
|
||||||
const modulePath = require('path').join(
|
const modulePath = require('path').join(
|
||||||
__dirname,
|
__dirname,
|
||||||
'../../../app/js/LearnedWordsManager'
|
'../../../app/js/LearnedWordsManager'
|
||||||
)
|
)
|
||||||
const { assert } = require('chai')
|
|
||||||
describe('LearnedWordsManager', function () {
|
describe('LearnedWordsManager', function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
this.token = 'a6b3cd919ge'
|
this.token = 'a6b3cd919ge'
|
||||||
|
@ -22,17 +21,9 @@ describe('LearnedWordsManager', function () {
|
||||||
del: sinon.stub()
|
del: sinon.stub()
|
||||||
}
|
}
|
||||||
this.LearnedWordsManager = SandboxedModule.require(modulePath, {
|
this.LearnedWordsManager = SandboxedModule.require(modulePath, {
|
||||||
globals: {
|
|
||||||
console: console
|
|
||||||
},
|
|
||||||
requires: {
|
requires: {
|
||||||
'./mongodb': { db: this.db },
|
'./mongodb': { db: this.db },
|
||||||
'./MongoCache': this.cache,
|
'./MongoCache': this.cache,
|
||||||
'logger-sharelatex': {
|
|
||||||
log() {},
|
|
||||||
err() {},
|
|
||||||
info() {}
|
|
||||||
},
|
|
||||||
'@overleaf/metrics': {
|
'@overleaf/metrics': {
|
||||||
timeAsyncMethod: sinon.stub(),
|
timeAsyncMethod: sinon.stub(),
|
||||||
inc: sinon.stub()
|
inc: sinon.stub()
|
||||||
|
|
|
@ -2,9 +2,7 @@
|
||||||
handle-callback-err
|
handle-callback-err
|
||||||
*/
|
*/
|
||||||
const sinon = require('sinon')
|
const sinon = require('sinon')
|
||||||
const chai = require('chai')
|
const { expect } = require('chai')
|
||||||
const { expect } = chai
|
|
||||||
chai.should()
|
|
||||||
const SandboxedModule = require('sandboxed-module')
|
const SandboxedModule = require('sandboxed-module')
|
||||||
const modulePath = require('path').join(
|
const modulePath = require('path').join(
|
||||||
__dirname,
|
__dirname,
|
||||||
|
|
Loading…
Reference in a new issue