Merge pull request #17362 from overleaf/bg-chai-object-id-tests

fix for chai object id tests

GitOrigin-RevId: 98123dbc930c6ee57be3a118177426120482c5f4
This commit is contained in:
Brian Gough
2024-07-16 08:04:46 +00:00
committed by Copybot
parent 3083d8082f
commit 9babc70df7
24 changed files with 85 additions and 499 deletions
+3
View File
@@ -0,0 +1,3 @@
{
"require": "test/setup.js"
}
+34
View File
@@ -0,0 +1,34 @@
const sinon = require('sinon')
const SandboxedModule = require('sandboxed-module')
// ensure every ObjectId has the id string as a property for correct comparisons
require('mongodb').ObjectId.cacheHexString = true
const sandbox = sinon.createSandbox()
const stubs = {
logger: {
debug: sandbox.stub(),
log: sandbox.stub(),
info: sandbox.stub(),
warn: sandbox.stub(),
err: sandbox.stub(),
error: sandbox.stub(),
fatal: sandbox.stub(),
},
}
SandboxedModule.configure({
requires: {
'@overleaf/logger': stubs.logger,
},
})
exports.mochaHooks = {
beforeEach() {
this.logger = stubs.logger
},
afterEach() {
sandbox.reset()
},
}
@@ -6,20 +6,16 @@ const { FailedCommandError } = require('../../../app/js/Errors')
const SandboxedModule = require('sandboxed-module')
describe('ImageOptimiser', function () {
let ImageOptimiser, SafeExec, logger
let ImageOptimiser, SafeExec
const sourcePath = '/wombat/potato.eps'
beforeEach(function () {
SafeExec = {
promises: sinon.stub().resolves(),
}
logger = {
warn: sinon.stub(),
}
ImageOptimiser = SandboxedModule.require(modulePath, {
requires: {
'./SafeExec': SafeExec,
'@overleaf/logger': logger,
'@overleaf/metrics': {
Timer: sinon.stub().returns({ done: sinon.stub() }),
},
@@ -65,7 +61,7 @@ describe('ImageOptimiser', function () {
})
it('should log a warning', function () {
expect(logger.warn).to.have.been.calledOnce
expect(this.logger.warn).to.have.been.calledOnce
})
})
})