Add a global test setup file

Set up generally useful stuff:

* chai.should()
* logger stubs
* globals in SandboxedModule, including Buffer and process, which are
  now required in Node 12
This commit is contained in:
Eric Mc Sween 2021-03-12 16:18:36 -05:00
parent bad5fd20a8
commit 9f2d219102
28 changed files with 28 additions and 79 deletions

View file

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

View file

@ -10,7 +10,6 @@
*/
const Client = require('./helpers/Client')
const request = require('request')
require('chai').should()
const ClsiApp = require('./helpers/ClsiApp')
describe('Broken LaTeX file', function () {

View file

@ -10,7 +10,6 @@
*/
const Client = require('./helpers/Client')
const request = require('request')
require('chai').should()
const ClsiApp = require('./helpers/ClsiApp')
describe('Deleting Old Files', function () {

View file

@ -17,7 +17,6 @@
*/
const Client = require('./helpers/Client')
const request = require('request')
require('chai').should()
const fs = require('fs')
const fsExtra = require('fs-extra')
const ChildProcess = require('child_process')

View file

@ -10,7 +10,6 @@
*/
const Client = require('./helpers/Client')
const request = require('request')
require('chai').should()
const ClsiApp = require('./helpers/ClsiApp')
describe('Simple LaTeX file', function () {

View file

@ -11,7 +11,6 @@
*/
const Client = require('./helpers/Client')
const request = require('request')
require('chai').should()
const { expect } = require('chai')
const ClsiApp = require('./helpers/ClsiApp')
const crypto = require('crypto')

View file

@ -10,7 +10,6 @@
*/
const Client = require('./helpers/Client')
const request = require('request')
require('chai').should()
const ClsiApp = require('./helpers/ClsiApp')
describe('Timed out compile', function () {

View file

@ -11,7 +11,6 @@
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const Client = require('./helpers/Client')
require('chai').should()
const sinon = require('sinon')
const ClsiApp = require('./helpers/ClsiApp')

View file

@ -11,7 +11,6 @@
*/
const Client = require('./helpers/Client')
const request = require('request')
require('chai').should()
const { expect } = require('chai')
const path = require('path')
const fs = require('fs')

View file

@ -0,0 +1,19 @@
const chai = require('chai')
const SandboxedModule = require('sandboxed-module')
// Setup should interface
chai.should()
// Global SandboxedModule settings
SandboxedModule.configure({
requires: {
'logger-sharelatex': {
log() {},
info() {},
warn() {},
error() {},
err() {}
}
},
globals: { Buffer, console, process }
})

View file

@ -11,7 +11,6 @@
*/
const SandboxedModule = require('sandboxed-module')
const sinon = require('sinon')
require('chai').should()
const { expect } = require('chai')
const modulePath = require('path').join(
__dirname,
@ -32,13 +31,7 @@ describe('CompileController', function () {
}
}
}),
'./ProjectPersistenceManager': (this.ProjectPersistenceManager = {}),
'logger-sharelatex': (this.logger = {
log: sinon.stub(),
error: sinon.stub(),
err: sinon.stub(),
warn: sinon.stub()
})
'./ProjectPersistenceManager': (this.ProjectPersistenceManager = {})
}
})
this.Settings.externalUrl = 'http://www.example.com'

View file

@ -15,7 +15,6 @@
*/
const SandboxedModule = require('sandboxed-module')
const sinon = require('sinon')
require('chai').should()
const modulePath = require('path').join(
__dirname,
'../../../app/js/CompileManager'
@ -47,7 +46,6 @@ describe('CompileManager', function () {
}
}),
'logger-sharelatex': (this.logger = { log: sinon.stub(), info() {} }),
child_process: (this.child_process = {}),
'./CommandRunner': (this.CommandRunner = {}),
'./DraftModeManager': (this.DraftModeManager = {}),

View file

@ -12,7 +12,6 @@
*/
const SandboxedModule = require('sandboxed-module')
const sinon = require('sinon')
require('chai').should()
const modulePath = require('path').join(
__dirname,
'../../../app/js/ContentTypeMapper'

View file

@ -11,7 +11,6 @@
*/
const SandboxedModule = require('sandboxed-module')
const sinon = require('sinon')
require('chai').should()
const modulePath = require('path').join(
__dirname,
'../../../app/js/DockerLockManager'
@ -21,11 +20,7 @@ describe('LockManager', function () {
beforeEach(function () {
return (this.LockManager = SandboxedModule.require(modulePath, {
requires: {
'settings-sharelatex': (this.Settings = { clsi: { docker: {} } }),
'logger-sharelatex': (this.logger = {
log: sinon.stub(),
error: sinon.stub()
})
'settings-sharelatex': (this.Settings = { clsi: { docker: {} } })
}
}))
})

View file

@ -15,7 +15,6 @@
*/
const SandboxedModule = require('sandboxed-module')
const sinon = require('sinon')
require('chai').should()
const { expect } = require('chai')
const modulePath = require('path').join(
__dirname,
@ -33,12 +32,6 @@ describe('DockerRunner', function () {
clsi: { docker: {} },
path: {}
}),
'logger-sharelatex': (this.logger = {
log: sinon.stub(),
error: sinon.stub(),
info: sinon.stub(),
warn: sinon.stub()
}),
dockerode: (Docker = (function () {
Docker = class Docker {
static initClass() {

View file

@ -10,7 +10,6 @@
*/
const SandboxedModule = require('sandboxed-module')
const sinon = require('sinon')
require('chai').should()
const modulePath = require('path').join(
__dirname,
'../../../app/js/DraftModeManager'
@ -20,8 +19,7 @@ describe('DraftModeManager', function () {
beforeEach(function () {
return (this.DraftModeManager = SandboxedModule.require(modulePath, {
requires: {
fs: (this.fs = {}),
'logger-sharelatex': (this.logger = { log() {} })
fs: (this.fs = {})
}
}))
})

View file

@ -11,7 +11,6 @@
*/
const SandboxedModule = require('sandboxed-module')
const sinon = require('sinon')
require('chai').should()
const modulePath = require('path').join(
__dirname,
'../../../app/js/LatexRunner'
@ -28,10 +27,6 @@ describe('LatexRunner', function () {
socketPath: '/var/run/docker.sock'
}
}),
'logger-sharelatex': (this.logger = {
log: sinon.stub(),
error: sinon.stub()
}),
'./Metrics': {
Timer: (Timer = class Timer {
done() {}

View file

@ -11,7 +11,6 @@
*/
const SandboxedModule = require('sandboxed-module')
const sinon = require('sinon')
require('chai').should()
const modulePath = require('path').join(
__dirname,
'../../../app/js/LockManager'
@ -24,11 +23,6 @@ describe('DockerLockManager', function () {
this.LockManager = SandboxedModule.require(modulePath, {
requires: {
'settings-sharelatex': {},
'logger-sharelatex': (this.logger = {
log: sinon.stub(),
error: sinon.stub(),
err() {}
}),
fs: {
lstat: sinon.stub().callsArgWith(1),
readdir: sinon.stub().callsArgWith(1)

View file

@ -12,7 +12,6 @@
*/
const SandboxedModule = require('sandboxed-module')
const sinon = require('sinon')
require('chai').should()
const modulePath = require('path').join(
__dirname,
'../../../app/js/OutputFileFinder'
@ -26,8 +25,7 @@ describe('OutputFileFinder', function () {
this.OutputFileFinder = SandboxedModule.require(modulePath, {
requires: {
fs: (this.fs = {}),
child_process: { spawn: (this.spawn = sinon.stub()) },
'logger-sharelatex': { log: sinon.stub(), warn: sinon.stub() }
child_process: { spawn: (this.spawn = sinon.stub()) }
},
globals: {
Math // used by lodash

View file

@ -12,7 +12,6 @@
*/
const SandboxedModule = require('sandboxed-module')
const sinon = require('sinon')
require('chai').should()
const modulePath = require('path').join(
__dirname,
'../../../app/js/OutputFileOptimiser'
@ -28,7 +27,6 @@ describe('OutputFileOptimiser', function () {
fs: (this.fs = {}),
path: (this.Path = {}),
child_process: { spawn: (this.spawn = sinon.stub()) },
'logger-sharelatex': { log: sinon.stub(), warn: sinon.stub() },
'./Metrics': {}
},
globals: { Math } // used by lodash

View file

@ -13,7 +13,6 @@
*/
const SandboxedModule = require('sandboxed-module')
const sinon = require('sinon')
require('chai').should()
const assert = require('chai').assert
const modulePath = require('path').join(
__dirname,
@ -28,11 +27,6 @@ describe('ProjectPersistenceManager', function () {
'./UrlCache': (this.UrlCache = {}),
'./CompileManager': (this.CompileManager = {}),
diskusage: (this.diskusage = { check: sinon.stub() }),
'logger-sharelatex': (this.logger = {
log: sinon.stub(),
warn: sinon.stub(),
err: sinon.stub()
}),
'settings-sharelatex': (this.settings = {
project_cache_length_ms: 1000
}),

View file

@ -11,7 +11,6 @@
*/
const SandboxedModule = require('sandboxed-module')
const sinon = require('sinon')
require('chai').should()
const { expect } = require('chai')
const modulePath = require('path').join(
__dirname,

View file

@ -12,7 +12,6 @@
const SandboxedModule = require('sandboxed-module')
const sinon = require('sinon')
const { expect } = require('chai')
const should = require('chai').should()
const modulePath = require('path').join(
__dirname,
'../../../app/js/ResourceStateManager'
@ -26,7 +25,6 @@ describe('ResourceStateManager', function () {
singleOnly: true,
requires: {
fs: (this.fs = {}),
'logger-sharelatex': { log: sinon.stub(), err: sinon.stub() },
'./SafeReader': (this.SafeReader = {})
}
})

View file

@ -13,7 +13,6 @@
const SandboxedModule = require('sandboxed-module')
const sinon = require('sinon')
const { expect } = require('chai')
const should = require('chai').should()
const modulePath = require('path').join(
__dirname,
'../../../app/js/ResourceWriter'
@ -34,7 +33,6 @@ describe('ResourceWriter', function () {
wrench: (this.wrench = {}),
'./UrlCache': (this.UrlCache = {}),
'./OutputFileFinder': (this.OutputFileFinder = {}),
'logger-sharelatex': { log: sinon.stub(), err: sinon.stub() },
'./Metrics': (this.Metrics = {
inc: sinon.stub(),
Timer: (Timer = (function () {
@ -407,7 +405,7 @@ describe('ResourceWriter', function () {
})
return it('should not return an error if the resource writer errored', function () {
return should.not.exist(this.callback.args[0][0])
return expect(this.callback.args[0][0]).not.to.exist
})
})

View file

@ -9,7 +9,6 @@
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const should = require('chai').should()
const SandboxedModule = require('sandboxed-module')
const assert = require('assert')
const path = require('path')
@ -32,11 +31,6 @@ describe('StaticServerForbidSymlinks', function () {
this.ForbidSymlinks = SandboxedModule.require(modulePath, {
requires: {
'settings-sharelatex': this.settings,
'logger-sharelatex': {
log() {},
warn() {},
error() {}
},
fs: this.fs
}
})

View file

@ -10,7 +10,6 @@
*/
const SandboxedModule = require('sandboxed-module')
const sinon = require('sinon')
require('chai').should()
const modulePath = require('path').join(
__dirname,
'../../../app/js/TikzManager'
@ -22,8 +21,7 @@ describe('TikzManager', function () {
requires: {
'./ResourceWriter': (this.ResourceWriter = {}),
'./SafeReader': (this.SafeReader = {}),
fs: (this.fs = {}),
'logger-sharelatex': (this.logger = { log() {} })
fs: (this.fs = {})
}
}))
})

View file

@ -12,7 +12,6 @@
*/
const SandboxedModule = require('sandboxed-module')
const sinon = require('sinon')
require('chai').should()
const modulePath = require('path').join(__dirname, '../../../app/js/UrlCache')
const { EventEmitter } = require('events')
@ -25,7 +24,6 @@ describe('UrlCache', function () {
requires: {
'./db': {},
'./UrlFetcher': (this.UrlFetcher = {}),
'logger-sharelatex': (this.logger = { log: sinon.stub() }),
'settings-sharelatex': (this.Settings = {
path: { clsiCacheDir: '/cache/dir' }
}),

View file

@ -11,7 +11,6 @@
const SandboxedModule = require('sandboxed-module')
const sinon = require('sinon')
const { expect } = require('chai')
require('chai').should()
const modulePath = require('path').join(__dirname, '../../../app/js/UrlFetcher')
const { EventEmitter } = require('events')
@ -25,10 +24,6 @@ describe('UrlFetcher', function () {
defaults: (this.defaults = sinon.stub().returns((this.request = {})))
},
fs: (this.fs = {}),
'logger-sharelatex': (this.logger = {
log: sinon.stub(),
error: sinon.stub()
}),
'settings-sharelatex': (this.settings = {})
}
}))