From c68e1a2dfe9b944161fed802908fbd6f273e535b Mon Sep 17 00:00:00 2001 From: Eric Mc Sween Date: Fri, 12 Mar 2021 16:39:45 -0500 Subject: [PATCH 1/2] Add a global test setup Configure SandboxedModule with common options, including some globals that are required in Node 12. --- services/contacts/.mocharc.json | 3 +++ services/contacts/test/setup.js | 9 +++++++++ services/contacts/test/unit/js/ContactsManagerTests.js | 4 +--- services/contacts/test/unit/js/HttpControllerTests.js | 3 +-- 4 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 services/contacts/.mocharc.json create mode 100644 services/contacts/test/setup.js diff --git a/services/contacts/.mocharc.json b/services/contacts/.mocharc.json new file mode 100644 index 0000000000..dc3280aa96 --- /dev/null +++ b/services/contacts/.mocharc.json @@ -0,0 +1,3 @@ +{ + "require": "test/setup.js" +} diff --git a/services/contacts/test/setup.js b/services/contacts/test/setup.js new file mode 100644 index 0000000000..eb9883ffcc --- /dev/null +++ b/services/contacts/test/setup.js @@ -0,0 +1,9 @@ +const SandboxedModule = require('sandboxed-module') + +SandboxedModule.configure({ + requires: { + 'logger-sharelatex': { log() {} }, + '@overleaf/metrics': { timeAsyncMethod() {} } + }, + globals: { Buffer, console, process } +}) diff --git a/services/contacts/test/unit/js/ContactsManagerTests.js b/services/contacts/test/unit/js/ContactsManagerTests.js index 5d38f88540..aa4af08a66 100644 --- a/services/contacts/test/unit/js/ContactsManagerTests.js +++ b/services/contacts/test/unit/js/ContactsManagerTests.js @@ -26,9 +26,7 @@ describe('ContactManager', function () { './mongodb': { db: (this.db = { contacts: {} }), ObjectId - }, - 'logger-sharelatex': { log: sinon.stub() }, - '@overleaf/metrics': { timeAsyncMethod: sinon.stub() } + } } }) this.user_id = ObjectId().toString() diff --git a/services/contacts/test/unit/js/HttpControllerTests.js b/services/contacts/test/unit/js/HttpControllerTests.js index e136f4135b..e458acfb5c 100644 --- a/services/contacts/test/unit/js/HttpControllerTests.js +++ b/services/contacts/test/unit/js/HttpControllerTests.js @@ -21,8 +21,7 @@ describe('HttpController', function () { beforeEach(function () { this.HttpController = SandboxedModule.require(modulePath, { requires: { - './ContactManager': (this.ContactManager = {}), - 'logger-sharelatex': (this.logger = { log: sinon.stub() }) + './ContactManager': (this.ContactManager = {}) } }) this.user_id = 'mock-user-id' From 2f9b9951e6f41f1968dea5f7b59cfed7e5d41cc8 Mon Sep 17 00:00:00 2001 From: Eric Mc Sween Date: Fri, 12 Mar 2021 16:40:30 -0500 Subject: [PATCH 2/2] Upgrade to Node 12 --- services/contacts/.nvmrc | 2 +- services/contacts/Dockerfile | 2 +- services/contacts/Makefile | 6 ++++-- services/contacts/buildscript.txt | 4 ++-- services/contacts/docker-compose.yml | 4 ++-- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/services/contacts/.nvmrc b/services/contacts/.nvmrc index 2baa2d433a..e68b860383 100644 --- a/services/contacts/.nvmrc +++ b/services/contacts/.nvmrc @@ -1 +1 @@ -10.23.1 +12.21.0 diff --git a/services/contacts/Dockerfile b/services/contacts/Dockerfile index 2da67d2436..4f417a2a4b 100644 --- a/services/contacts/Dockerfile +++ b/services/contacts/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 diff --git a/services/contacts/Makefile b/services/contacts/Makefile index a78011b961..e7367ddd7a 100644 --- a/services/contacts/Makefile +++ b/services/contacts/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 diff --git a/services/contacts/buildscript.txt b/services/contacts/buildscript.txt index 333bcf22db..bee1260ccf 100644 --- a/services/contacts/buildscript.txt +++ b/services/contacts/buildscript.txt @@ -3,6 +3,6 @@ contacts --docker-repos=gcr.io/overleaf-ops --env-add= --env-pass-through= ---node-version=10.23.1 +--node-version=12.21.0 --public-repo=False ---script-version=3.4.0 +--script-version=3.7.0 diff --git a/services/contacts/docker-compose.yml b/services/contacts/docker-compose.yml index 8be027dba1..1a8d6095ee 100644 --- a/services/contacts/docker-compose.yml +++ b/services/contacts/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