Przeglądaj źródła

Merge pull request #96 from overleaf/em-upgrade-node-12

Upgrade to Node 12
Eric Mc Sween 5 lat temu
rodzic
commit
ccf1f502e2

+ 3 - 0
services/docstore/.mocharc.json

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

+ 1 - 1
services/docstore/.nvmrc

@@ -1 +1 @@
-10.23.1
+12.21.0

+ 1 - 1
services/docstore/Dockerfile

@@ -2,7 +2,7 @@
 # Instead run bin/update_build_scripts from
 # https://github.com/sharelatex/sharelatex-dev-environment
 
-FROM node:10.23.1 as base
+FROM node:12.21.0 as base
 
 WORKDIR /app
 

+ 4 - 2
services/docstore/Makefile

@@ -21,8 +21,10 @@ DOCKER_COMPOSE_TEST_UNIT = \
 	COMPOSE_PROJECT_NAME=test_unit_$(BUILD_DIR_NAME) $(DOCKER_COMPOSE)
 
 clean:
-	docker rmi ci/$(PROJECT_NAME):$(BRANCH_NAME)-$(BUILD_NUMBER)
-	docker rmi gcr.io/overleaf-ops/$(PROJECT_NAME):$(BRANCH_NAME)-$(BUILD_NUMBER)
+	-docker rmi ci/$(PROJECT_NAME):$(BRANCH_NAME)-$(BUILD_NUMBER)
+	-docker rmi gcr.io/overleaf-ops/$(PROJECT_NAME):$(BRANCH_NAME)-$(BUILD_NUMBER)
+	-$(DOCKER_COMPOSE_TEST_UNIT) down --rmi local
+	-$(DOCKER_COMPOSE_TEST_ACCEPTANCE) down --rmi local
 
 format:
 	$(DOCKER_COMPOSE) run --rm test_unit npm run --silent format

+ 2 - 2
services/docstore/buildscript.txt

@@ -3,6 +3,6 @@ docstore
 --docker-repos=gcr.io/overleaf-ops
 --env-add=
 --env-pass-through=
---node-version=10.23.1
+--node-version=12.21.0
 --public-repo=True
---script-version=3.4.0
+--script-version=3.7.0

+ 2 - 2
services/docstore/docker-compose.yml

@@ -6,7 +6,7 @@ version: "2.3"
 
 services:
   test_unit:
-    image: node:10.23.1
+    image: node:12.21.0
     volumes:
       - .:/app
     working_dir: /app
@@ -18,7 +18,7 @@ services:
     user: node
 
   test_acceptance:
-    image: node:10.23.1
+    image: node:12.21.0
     volumes:
       - .:/app
     working_dir: /app

+ 22 - 24
services/docstore/test/acceptance/js/ArchiveDocsTests.js

@@ -14,9 +14,7 @@
  */
 process.env.BACKEND = 'gcs'
 const Settings = require('settings-sharelatex')
-const chai = require('chai')
-const { expect } = chai
-const should = chai.should()
+const { expect } = require('chai')
 const { db, ObjectId } = require('../../../app/js/mongodb')
 const async = require('async')
 const DocstoreApp = require('./helpers/DocstoreApp')
@@ -96,8 +94,8 @@ describe('Archiving', function () {
         ((doc) => {
           return (callback) => {
             return db.docs.findOne({ _id: doc._id }, (error, doc) => {
-              should.not.exist(doc.lines)
-              should.not.exist(doc.ranges)
+              expect(doc.lines).not.to.exist
+              expect(doc.ranges).not.to.exist
               doc.inS3.should.equal(true)
               return callback()
             })
@@ -155,7 +153,7 @@ describe('Archiving', function () {
               return db.docs.findOne({ _id: doc._id }, (error, doc) => {
                 doc.lines.should.deep.equal(this.docs[i].lines)
                 doc.ranges.should.deep.equal(this.docs[i].ranges)
-                should.not.exist(doc.inS3)
+                expect(doc.inS3).not.to.exist
                 return callback()
               })
             }
@@ -218,8 +216,8 @@ describe('Archiving', function () {
         if (error != null) {
           throw error
         }
-        should.not.exist(doc.lines)
-        should.not.exist(doc.ranges)
+        expect(doc.lines).not.to.exist
+        expect(doc.ranges).not.to.exist
         doc.inS3.should.equal(true)
         doc.deleted.should.equal(true)
         return done()
@@ -267,7 +265,7 @@ describe('Archiving', function () {
           }
           doc.lines.should.deep.equal(this.doc.lines)
           doc.ranges.should.deep.equal(this.doc.ranges)
-          should.not.exist(doc.inS3)
+          expect(doc.inS3).not.to.exist
           doc.deleted.should.equal(true)
           return done()
         })
@@ -365,8 +363,8 @@ describe('Archiving', function () {
         if (error) {
           return done(error)
         }
-        should.not.exist(doc.lines)
-        should.not.exist(doc.ranges)
+        expect(doc.lines).not.to.exist
+        expect(doc.ranges).not.to.exist
         doc.inS3.should.equal(true)
         done()
       })
@@ -433,8 +431,8 @@ describe('Archiving', function () {
         if (error != null) {
           throw error
         }
-        should.not.exist(doc.lines)
-        should.not.exist(doc.ranges)
+        expect(doc.lines).not.to.exist
+        expect(doc.ranges).not.to.exist
         doc.inS3.should.equal(true)
         return done()
       })
@@ -476,7 +474,7 @@ describe('Archiving', function () {
           }
           doc.lines.should.deep.equal(this.doc.lines)
           doc.ranges.should.deep.equal(this.doc.ranges)
-          should.not.exist(doc.inS3)
+          expect(doc.inS3).not.to.exist
           return done()
         })
       })
@@ -907,8 +905,8 @@ describe('Archiving', function () {
         if (error != null) {
           throw error
         }
-        should.not.exist(doc.lines)
-        should.not.exist(doc.ranges)
+        expect(doc.lines).not.to.exist
+        expect(doc.ranges).not.to.exist
         doc.inS3.should.equal(true)
         return done()
       })
@@ -950,7 +948,7 @@ describe('Archiving', function () {
           }
           doc.lines.should.deep.equal(this.doc.lines)
           doc.ranges.should.deep.equal(this.doc.ranges)
-          should.not.exist(doc.inS3)
+          expect(doc.inS3).not.to.exist
           return done()
         })
       })
@@ -1026,8 +1024,8 @@ describe('Archiving', function () {
         if (error != null) {
           throw error
         }
-        should.not.exist(doc.lines)
-        should.not.exist(doc.ranges)
+        expect(doc.lines).not.to.exist
+        expect(doc.ranges).not.to.exist
         doc.inS3.should.equal(true)
         return done()
       })
@@ -1070,7 +1068,7 @@ describe('Archiving', function () {
           }
           doc.lines.should.deep.equal(this.doc.lines)
           doc.ranges.should.deep.equal(this.doc.ranges)
-          should.not.exist(doc.inS3)
+          expect(doc.inS3).not.to.exist
           return done()
         })
       })
@@ -1123,8 +1121,8 @@ describe('Archiving', function () {
         if (error != null) {
           throw error
         }
-        should.not.exist(doc.lines)
-        should.not.exist(doc.ranges)
+        expect(doc.lines).not.to.exist
+        expect(doc.ranges).not.to.exist
         doc.inS3.should.equal(true)
         return done()
       })
@@ -1166,7 +1164,7 @@ describe('Archiving', function () {
           }
           doc.lines.should.deep.equal(this.doc.lines)
           doc.ranges.should.deep.equal(this.doc.ranges)
-          should.not.exist(doc.inS3)
+          expect(doc.inS3).not.to.exist
           return done()
         })
       })
@@ -1220,7 +1218,7 @@ describe('Archiving', function () {
           throw error
         }
         doc.lines.should.deep.equal(this.doc.lines)
-        should.not.exist(doc.inS3)
+        expect(doc.inS3).not.to.exist
         return done()
       })
     })

+ 1 - 3
services/docstore/test/acceptance/js/DeletingDocsTests.js

@@ -11,10 +11,8 @@
  * DS207: Consider shorter variations of null checks
  * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  */
-const chai = require('chai')
-chai.should()
 const { db, ObjectId } = require('../../../app/js/mongodb')
-const { expect } = chai
+const { expect } = require('chai')
 const DocstoreApp = require('./helpers/DocstoreApp')
 const Errors = require('../../../app/js/Errors')
 const Settings = require('settings-sharelatex')

+ 0 - 2
services/docstore/test/acceptance/js/GettingAllDocsTests.js

@@ -12,8 +12,6 @@
  * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  */
 const sinon = require('sinon')
-const chai = require('chai')
-chai.should()
 const { ObjectId } = require('mongodb')
 const async = require('async')
 const DocstoreApp = require('./helpers/DocstoreApp')

+ 0 - 2
services/docstore/test/acceptance/js/GettingDocsTests.js

@@ -12,8 +12,6 @@
  * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  */
 const sinon = require('sinon')
-const chai = require('chai')
-chai.should()
 const { ObjectId } = require('mongodb')
 const DocstoreApp = require('./helpers/DocstoreApp')
 

+ 0 - 2
services/docstore/test/acceptance/js/UpdatingDocsTests.js

@@ -11,8 +11,6 @@
  * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  */
 const sinon = require('sinon')
-const chai = require('chai')
-chai.should()
 const { ObjectId } = require('mongodb')
 const DocstoreApp = require('./helpers/DocstoreApp')
 

+ 40 - 0
services/docstore/test/setup.js

@@ -0,0 +1,40 @@
+const chai = require('chai')
+const sinon = require('sinon')
+const sinonChai = require('sinon-chai')
+const chaiAsPromised = require('chai-as-promised')
+const SandboxedModule = require('sandboxed-module')
+
+// Chai configuration
+chai.should()
+chai.use(sinonChai)
+chai.use(chaiAsPromised)
+
+// Global stubs
+const sandbox = sinon.createSandbox()
+const stubs = {
+  logger: {
+    log: sandbox.stub(),
+    warn: sandbox.stub(),
+    err: sandbox.stub(),
+    error: sandbox.stub(),
+    fatal: sandbox.stub()
+  }
+}
+
+// SandboxedModule configuration
+SandboxedModule.configure({
+  requires: {
+    'logger-sharelatex': stubs.logger
+  },
+  globals: { Buffer, JSON, console, process }
+})
+
+exports.mochaHooks = {
+  beforeEach() {
+    this.logger = stubs.logger
+  },
+
+  afterEach() {
+    sandbox.reset()
+  }
+}

+ 1 - 15
services/docstore/test/unit/js/DocArchiveManagerTests.js

@@ -1,21 +1,16 @@
 const sinon = require('sinon')
-const chai = require('chai')
-const { expect } = chai
+const { expect } = require('chai')
 const modulePath = '../../../app/js/DocArchiveManager.js'
 const SandboxedModule = require('sandboxed-module')
 const { ObjectId } = require('mongodb')
 const Errors = require('../../../app/js/Errors')
 
-chai.use(require('chai-as-promised'))
-chai.use(require('sinon-chai'))
-
 describe('DocArchiveManager', function () {
   let DocArchiveManager,
     PersistorManager,
     MongoManager,
     RangeManager,
     Settings,
-    Logger,
     Crypto,
     Streamifier,
     HashDigest,
@@ -39,10 +34,6 @@ describe('DocArchiveManager', function () {
         bucket: 'wombat'
       }
     }
-    Logger = {
-      log: sinon.stub(),
-      err: sinon.stub()
-    }
     HashDigest = sinon.stub().returns(md5Sum)
     HashUpdate = sinon.stub().returns({ digest: HashDigest })
     Crypto = {
@@ -141,17 +132,12 @@ describe('DocArchiveManager', function () {
     DocArchiveManager = SandboxedModule.require(modulePath, {
       requires: {
         'settings-sharelatex': Settings,
-        'logger-sharelatex': Logger,
         crypto: Crypto,
         streamifier: Streamifier,
         './MongoManager': MongoManager,
         './RangeManager': RangeManager,
         './PersistorManager': PersistorManager,
         './Errors': Errors
-      },
-      globals: {
-        console,
-        JSON
       }
     })
   })

+ 1 - 12
services/docstore/test/unit/js/DocManagerTests.js

@@ -14,11 +14,7 @@
  */
 const SandboxedModule = require('sandboxed-module')
 const sinon = require('sinon')
-const chai = require('chai')
-chai.use(require('sinon-chai'))
-const { assert } = require('chai')
-chai.should()
-const { expect } = chai
+const { assert, expect } = require('chai')
 const modulePath = require('path').join(__dirname, '../../../app/js/DocManager')
 const { ObjectId } = require('mongodb')
 const Errors = require('../../../app/js/Errors')
@@ -36,11 +32,6 @@ describe('DocManager', function () {
           shouldUpdateRanges: sinon.stub().returns(false)
         }),
         'settings-sharelatex': (this.settings = { docstore: {} }),
-        'logger-sharelatex': (this.logger = {
-          log: sinon.stub(),
-          warn() {},
-          err() {}
-        }),
         './Errors': Errors
       }
     })
@@ -493,7 +484,6 @@ describe('DocManager', function () {
             this.DocArchiveManager.archiveDocById = sinon
               .stub()
               .yields(this.err)
-            this.logger.warn = sinon.stub()
             this.callback = sinon.stub().callsFake(done)
             this.DocManager.deleteDoc(
               this.project_id,
@@ -630,7 +620,6 @@ describe('DocManager', function () {
         beforeEach(function () {
           this.settings.docstore.archiveOnSoftDelete = true
           this.meta.deleted = true
-          this.logger.warn = sinon.stub()
         })
 
         describe('when the background flush succeeds', function () {

+ 2 - 11
services/docstore/test/unit/js/HttpControllerTests.js

@@ -10,11 +10,8 @@
  * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  */
 const SandboxedModule = require('sandboxed-module')
-const { assert } = require('chai')
 const sinon = require('sinon')
-const chai = require('chai')
-chai.should()
-const { expect } = chai
+const { assert, expect } = require('chai')
 const modulePath = require('path').join(
   __dirname,
   '../../../app/js/HttpController'
@@ -30,15 +27,9 @@ describe('HttpController', function () {
       requires: {
         './DocManager': (this.DocManager = {}),
         './DocArchiveManager': (this.DocArchiveManager = {}),
-        'logger-sharelatex': (this.logger = {
-          log: sinon.stub(),
-          error: sinon.stub(),
-          fatal: sinon.stub()
-        }),
         'settings-sharelatex': settings,
         './HealthChecker': {}
-      },
-      globals: { process }
+      }
     })
     this.res = {
       send: sinon.stub(),

+ 0 - 5
services/docstore/test/unit/js/MongoManagerTests.js

@@ -11,7 +11,6 @@
  */
 const SandboxedModule = require('sandboxed-module')
 const sinon = require('sinon')
-require('chai').should()
 const modulePath = require('path').join(
   __dirname,
   '../../../app/js/MongoManager'
@@ -28,11 +27,7 @@ describe('MongoManager', function () {
           ObjectId
         },
         '@overleaf/metrics': { timeAsyncMethod: sinon.stub() },
-        'logger-sharelatex': { log() {} },
         'settings-sharelatex': { max_deleted_docs: 42 }
-      },
-      globals: {
-        console
       }
     })
     this.project_id = ObjectId().toString()

+ 1 - 3
services/docstore/test/unit/js/RangeManagerTests.js

@@ -12,14 +12,12 @@
  */
 const SandboxedModule = require('sandboxed-module')
 const sinon = require('sinon')
-require('chai').should()
-const { expect } = require('chai')
+const { assert, expect } = require('chai')
 const modulePath = require('path').join(
   __dirname,
   '../../../app/js/RangeManager'
 )
 const { ObjectId } = require('mongodb')
-const { assert } = require('chai')
 const _ = require('underscore')
 
 describe('RangeManager', function () {