Răsfoiți Sursa

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

Fail tests on unhandled promise rejection

GitOrigin-RevId: 3cc53ce5b46c63c62374eb83f9442b8d6979272e
Shane Kilkelly 6 ani în urmă
părinte
comite
cbf08c599b

+ 6 - 0
services/web/test/acceptance/bootstrap.js

@@ -1,3 +1,9 @@
 const chai = require('chai')
 chai.use(require('chai-as-promised'))
 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)
+})

+ 6 - 0
services/web/test/unit/bootstrap.js

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

+ 2 - 2
services/web/test/unit/src/Email/EmailSenderTests.js

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

+ 8 - 1
services/web/test/unit/src/User/SAMLIdentityManagerTests.js

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