Просмотр исходного кода

Merge pull request #3183 from overleaf/jpa-add-missing-db-stub

[misc] unit tests: add missing module stubs for (transient) db imports

GitOrigin-RevId: 9a16f1ab9b42608d839922fb339189697bc9ed22
Jakob Ackermann 6 лет назад
Родитель
Сommit
9789a158a7

+ 10 - 0
services/web/app/src/infrastructure/mongojs.js

@@ -5,6 +5,16 @@
 // Fix any style issues and re-enable lint.
 const Settings = require('settings-sharelatex')
 const mongojs = require('mongojs')
+
+if (
+  typeof global.beforeEach === 'function' &&
+  process.argv.join(' ').match(/unit/)
+) {
+  throw new Error(
+    'It looks like unit tests are running, but you are connecting to Mongo. Missing a stub?'
+  )
+}
+
 const db = mongojs(Settings.mongo.url, [
   'projects',
   'users',

+ 1 - 0
services/web/test/unit/src/Subscription/SubscriptionUpdaterTests.js

@@ -110,6 +110,7 @@ describe('SubscriptionUpdater', function() {
           warn() {}
         },
         'settings-sharelatex': this.Settings,
+        '../../infrastructure/mongojs': { db: {}, ObjectId },
         './FeaturesUpdater': this.FeaturesUpdater,
         '../../models/DeletedSubscription': {
           DeletedSubscription: this.DeletedSubscription