Merge pull request #2333 from overleaf/em-unhandled-rejections

Fail tests on unhandled promise rejection

GitOrigin-RevId: 3cc53ce5b46c63c62374eb83f9442b8d6979272e
This commit is contained in:
Shane Kilkelly 2019-11-07 10:28:27 +00:00 committed by sharelatex
parent cfaab43b08
commit cbf08c599b
4 changed files with 22 additions and 3 deletions

View file

@ -1,3 +1,9 @@
const chai = require('chai') const chai = require('chai')
chai.use(require('chai-as-promised')) chai.use(require('chai-as-promised'))
chai.use(require('chaid')) chai.use(require('chaid'))
// Crash the process on an unhandled promise rejection
process.on('unhandledRejection', err => {
console.error('Unhandled promise rejection:', err)
process.exit(1)
})

View file

@ -15,3 +15,9 @@ chai.config.truncateThreshold = 0
require('sinon-as-promised') require('sinon-as-promised')
// add support for mongoose in sinon // add support for mongoose in sinon
require('sinon-mongoose') require('sinon-mongoose')
// Crash the process on an unhandled promise rejection
process.on('unhandledRejection', err => {
console.error('Unhandled promise rejection:', err)
process.exit(1)
})

View file

@ -72,8 +72,8 @@ describe('EmailSender', function() {
it('should return a non-specific error', async function() { it('should return a non-specific error', async function() {
this.sesClient.sendMail.rejects(new Error('boom')) this.sesClient.sendMail.rejects(new Error('boom'))
expect(this.EmailSender.promises.sendEmail({})).to.be.rejectedWith( await expect(this.EmailSender.promises.sendEmail({})).to.be.rejectedWith(
'Error: Cannot send email' 'error sending message'
) )
}) })

View file

@ -33,6 +33,12 @@ describe('SAMLIdentityManager', function() {
this.institution = { this.institution = {
name: 'Overleaf University' name: 'Overleaf University'
} }
this.InstitutionsAPI = {
promises: {
addEntitlement: sinon.stub().resolves(),
removeEntitlement: sinon.stub().resolves()
}
}
this.SAMLIdentityManager = SandboxedModule.require(modulePath, { this.SAMLIdentityManager = SandboxedModule.require(modulePath, {
requires: { requires: {
'../Email/EmailHandler': (this.EmailHandler = { '../Email/EmailHandler': (this.EmailHandler = {
@ -59,7 +65,8 @@ describe('SAMLIdentityManager', function() {
}), }),
'../User/UserUpdater': (this.UserUpdater = { '../User/UserUpdater': (this.UserUpdater = {
addEmailAddress: sinon.stub() addEmailAddress: sinon.stub()
}) }),
'../Institutions/InstitutionsAPI': this.InstitutionsAPI
} }
}) })
}) })