diff --git a/services/clsi/.dockerignore b/services/clsi/.dockerignore index 74fdc35e80..bcbd758418 100644 --- a/services/clsi/.dockerignore +++ b/services/clsi/.dockerignore @@ -8,3 +8,4 @@ nodemon.json cache/ compiles/ db/ +output/ diff --git a/services/clsi/.mocharc.json b/services/clsi/.mocharc.json new file mode 100644 index 0000000000..dc3280aa96 --- /dev/null +++ b/services/clsi/.mocharc.json @@ -0,0 +1,3 @@ +{ + "require": "test/setup.js" +} diff --git a/services/clsi/.nvmrc b/services/clsi/.nvmrc index 2baa2d433a..e68b860383 100644 --- a/services/clsi/.nvmrc +++ b/services/clsi/.nvmrc @@ -1 +1 @@ -10.23.1 +12.21.0 diff --git a/services/clsi/Dockerfile b/services/clsi/Dockerfile index 7eaa03f814..b02e828a4d 100644 --- a/services/clsi/Dockerfile +++ b/services/clsi/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 COPY install_deps.sh /app @@ -23,6 +23,6 @@ FROM base COPY --from=app /app /app RUN mkdir -p cache compiles db output \ - && chown node:node cache compiles db output +&& chown node:node cache compiles db output CMD ["node", "--expose-gc", "app.js"] diff --git a/services/clsi/Makefile b/services/clsi/Makefile index 040a9315e3..45a4bc0400 100644 --- a/services/clsi/Makefile +++ b/services/clsi/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/clsi/buildscript.txt b/services/clsi/buildscript.txt index b2093150c1..a86911dc61 100644 --- a/services/clsi/buildscript.txt +++ b/services/clsi/buildscript.txt @@ -1,9 +1,9 @@ clsi ---data-dirs=cache,compiles,db +--data-dirs=cache,compiles,db,output --dependencies= --docker-repos=gcr.io/overleaf-ops --env-add= --env-pass-through=TEXLIVE_IMAGE ---node-version=10.23.1 +--node-version=12.21.0 --public-repo=True ---script-version=3.4.0 +--script-version=3.7.0 diff --git a/services/clsi/test/acceptance/js/BrokenLatexFileTests.js b/services/clsi/test/acceptance/js/BrokenLatexFileTests.js index c26e0c4018..34d3b37c92 100644 --- a/services/clsi/test/acceptance/js/BrokenLatexFileTests.js +++ b/services/clsi/test/acceptance/js/BrokenLatexFileTests.js @@ -10,7 +10,6 @@ */ const Client = require('./helpers/Client') const request = require('request') -require('chai').should() const ClsiApp = require('./helpers/ClsiApp') describe('Broken LaTeX file', function () { diff --git a/services/clsi/test/acceptance/js/DeleteOldFilesTest.js b/services/clsi/test/acceptance/js/DeleteOldFilesTest.js index ae2d7c791e..064f6be67d 100644 --- a/services/clsi/test/acceptance/js/DeleteOldFilesTest.js +++ b/services/clsi/test/acceptance/js/DeleteOldFilesTest.js @@ -10,7 +10,6 @@ */ const Client = require('./helpers/Client') const request = require('request') -require('chai').should() const ClsiApp = require('./helpers/ClsiApp') describe('Deleting Old Files', function () { diff --git a/services/clsi/test/acceptance/js/ExampleDocumentTests.js b/services/clsi/test/acceptance/js/ExampleDocumentTests.js index 5a67a0febc..92bab4b6cc 100644 --- a/services/clsi/test/acceptance/js/ExampleDocumentTests.js +++ b/services/clsi/test/acceptance/js/ExampleDocumentTests.js @@ -17,7 +17,6 @@ */ const Client = require('./helpers/Client') const request = require('request') -require('chai').should() const fs = require('fs') const fsExtra = require('fs-extra') const ChildProcess = require('child_process') diff --git a/services/clsi/test/acceptance/js/SimpleLatexFileTests.js b/services/clsi/test/acceptance/js/SimpleLatexFileTests.js index dd45802692..7377afdaf1 100644 --- a/services/clsi/test/acceptance/js/SimpleLatexFileTests.js +++ b/services/clsi/test/acceptance/js/SimpleLatexFileTests.js @@ -10,7 +10,6 @@ */ const Client = require('./helpers/Client') const request = require('request') -require('chai').should() const ClsiApp = require('./helpers/ClsiApp') describe('Simple LaTeX file', function () { diff --git a/services/clsi/test/acceptance/js/SynctexTests.js b/services/clsi/test/acceptance/js/SynctexTests.js index afe6330df3..e636912bea 100644 --- a/services/clsi/test/acceptance/js/SynctexTests.js +++ b/services/clsi/test/acceptance/js/SynctexTests.js @@ -11,7 +11,6 @@ */ const Client = require('./helpers/Client') const request = require('request') -require('chai').should() const { expect } = require('chai') const ClsiApp = require('./helpers/ClsiApp') const crypto = require('crypto') diff --git a/services/clsi/test/acceptance/js/TimeoutTests.js b/services/clsi/test/acceptance/js/TimeoutTests.js index 36bcf9aa24..0d359bec0a 100644 --- a/services/clsi/test/acceptance/js/TimeoutTests.js +++ b/services/clsi/test/acceptance/js/TimeoutTests.js @@ -10,7 +10,6 @@ */ const Client = require('./helpers/Client') const request = require('request') -require('chai').should() const ClsiApp = require('./helpers/ClsiApp') describe('Timed out compile', function () { diff --git a/services/clsi/test/acceptance/js/UrlCachingTests.js b/services/clsi/test/acceptance/js/UrlCachingTests.js index 03927ea1ef..9528efba95 100644 --- a/services/clsi/test/acceptance/js/UrlCachingTests.js +++ b/services/clsi/test/acceptance/js/UrlCachingTests.js @@ -11,7 +11,6 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ const Client = require('./helpers/Client') -require('chai').should() const sinon = require('sinon') const ClsiApp = require('./helpers/ClsiApp') diff --git a/services/clsi/test/acceptance/js/WordcountTests.js b/services/clsi/test/acceptance/js/WordcountTests.js index 73a11f7693..837eb47a2a 100644 --- a/services/clsi/test/acceptance/js/WordcountTests.js +++ b/services/clsi/test/acceptance/js/WordcountTests.js @@ -11,7 +11,6 @@ */ const Client = require('./helpers/Client') const request = require('request') -require('chai').should() const { expect } = require('chai') const path = require('path') const fs = require('fs') diff --git a/services/clsi/test/setup.js b/services/clsi/test/setup.js new file mode 100644 index 0000000000..87532f0a26 --- /dev/null +++ b/services/clsi/test/setup.js @@ -0,0 +1,19 @@ +const chai = require('chai') +const SandboxedModule = require('sandboxed-module') + +// Setup should interface +chai.should() + +// Global SandboxedModule settings +SandboxedModule.configure({ + requires: { + 'logger-sharelatex': { + log() {}, + info() {}, + warn() {}, + error() {}, + err() {} + } + }, + globals: { Buffer, console, process } +}) diff --git a/services/clsi/test/unit/js/CompileControllerTests.js b/services/clsi/test/unit/js/CompileControllerTests.js index 70f67b602f..d8c7c12609 100644 --- a/services/clsi/test/unit/js/CompileControllerTests.js +++ b/services/clsi/test/unit/js/CompileControllerTests.js @@ -11,7 +11,6 @@ */ const SandboxedModule = require('sandboxed-module') const sinon = require('sinon') -require('chai').should() const { expect } = require('chai') const modulePath = require('path').join( __dirname, @@ -32,13 +31,7 @@ describe('CompileController', function () { } } }), - './ProjectPersistenceManager': (this.ProjectPersistenceManager = {}), - 'logger-sharelatex': (this.logger = { - log: sinon.stub(), - error: sinon.stub(), - err: sinon.stub(), - warn: sinon.stub() - }) + './ProjectPersistenceManager': (this.ProjectPersistenceManager = {}) } }) this.Settings.externalUrl = 'http://www.example.com' diff --git a/services/clsi/test/unit/js/CompileManagerTests.js b/services/clsi/test/unit/js/CompileManagerTests.js index 917dfe8cb7..e33783a185 100644 --- a/services/clsi/test/unit/js/CompileManagerTests.js +++ b/services/clsi/test/unit/js/CompileManagerTests.js @@ -15,7 +15,6 @@ */ const SandboxedModule = require('sandboxed-module') const sinon = require('sinon') -require('chai').should() const modulePath = require('path').join( __dirname, '../../../app/js/CompileManager' @@ -47,7 +46,6 @@ describe('CompileManager', function () { } }), - 'logger-sharelatex': (this.logger = { log: sinon.stub(), info() {} }), child_process: (this.child_process = {}), './CommandRunner': (this.CommandRunner = {}), './DraftModeManager': (this.DraftModeManager = {}), diff --git a/services/clsi/test/unit/js/ContentTypeMapperTests.js b/services/clsi/test/unit/js/ContentTypeMapperTests.js index 21173bc526..b6363623d2 100644 --- a/services/clsi/test/unit/js/ContentTypeMapperTests.js +++ b/services/clsi/test/unit/js/ContentTypeMapperTests.js @@ -12,7 +12,6 @@ */ const SandboxedModule = require('sandboxed-module') const sinon = require('sinon') -require('chai').should() const modulePath = require('path').join( __dirname, '../../../app/js/ContentTypeMapper' diff --git a/services/clsi/test/unit/js/DockerLockManagerTests.js b/services/clsi/test/unit/js/DockerLockManagerTests.js index 19c289a128..6adfa1231a 100644 --- a/services/clsi/test/unit/js/DockerLockManagerTests.js +++ b/services/clsi/test/unit/js/DockerLockManagerTests.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/DockerLockManager' @@ -21,11 +20,7 @@ describe('LockManager', function () { beforeEach(function () { return (this.LockManager = SandboxedModule.require(modulePath, { requires: { - 'settings-sharelatex': (this.Settings = { clsi: { docker: {} } }), - 'logger-sharelatex': (this.logger = { - log: sinon.stub(), - error: sinon.stub() - }) + 'settings-sharelatex': (this.Settings = { clsi: { docker: {} } }) } })) }) diff --git a/services/clsi/test/unit/js/DockerRunnerTests.js b/services/clsi/test/unit/js/DockerRunnerTests.js index 517179a962..67290e440d 100644 --- a/services/clsi/test/unit/js/DockerRunnerTests.js +++ b/services/clsi/test/unit/js/DockerRunnerTests.js @@ -15,7 +15,6 @@ */ const SandboxedModule = require('sandboxed-module') const sinon = require('sinon') -require('chai').should() const { expect } = require('chai') const modulePath = require('path').join( __dirname, @@ -33,12 +32,6 @@ describe('DockerRunner', function () { clsi: { docker: {} }, path: {} }), - 'logger-sharelatex': (this.logger = { - log: sinon.stub(), - error: sinon.stub(), - info: sinon.stub(), - warn: sinon.stub() - }), dockerode: (Docker = (function () { Docker = class Docker { static initClass() { diff --git a/services/clsi/test/unit/js/DraftModeManagerTests.js b/services/clsi/test/unit/js/DraftModeManagerTests.js index 937cde90d9..13291e0262 100644 --- a/services/clsi/test/unit/js/DraftModeManagerTests.js +++ b/services/clsi/test/unit/js/DraftModeManagerTests.js @@ -10,7 +10,6 @@ */ const SandboxedModule = require('sandboxed-module') const sinon = require('sinon') -require('chai').should() const modulePath = require('path').join( __dirname, '../../../app/js/DraftModeManager' @@ -20,8 +19,7 @@ describe('DraftModeManager', function () { beforeEach(function () { return (this.DraftModeManager = SandboxedModule.require(modulePath, { requires: { - fs: (this.fs = {}), - 'logger-sharelatex': (this.logger = { log() {} }) + fs: (this.fs = {}) } })) }) diff --git a/services/clsi/test/unit/js/LatexRunnerTests.js b/services/clsi/test/unit/js/LatexRunnerTests.js index 9cd0d0ac95..a9116d0fd7 100644 --- a/services/clsi/test/unit/js/LatexRunnerTests.js +++ b/services/clsi/test/unit/js/LatexRunnerTests.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/LatexRunner' @@ -28,10 +27,6 @@ describe('LatexRunner', function () { socketPath: '/var/run/docker.sock' } }), - 'logger-sharelatex': (this.logger = { - log: sinon.stub(), - error: sinon.stub() - }), './Metrics': { Timer: (Timer = class Timer { done() {} diff --git a/services/clsi/test/unit/js/LockManagerTests.js b/services/clsi/test/unit/js/LockManagerTests.js index 16a43ade48..58580583ca 100644 --- a/services/clsi/test/unit/js/LockManagerTests.js +++ b/services/clsi/test/unit/js/LockManagerTests.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/LockManager' @@ -24,11 +23,6 @@ describe('DockerLockManager', function () { this.LockManager = SandboxedModule.require(modulePath, { requires: { 'settings-sharelatex': {}, - 'logger-sharelatex': (this.logger = { - log: sinon.stub(), - error: sinon.stub(), - err() {} - }), fs: { lstat: sinon.stub().callsArgWith(1), readdir: sinon.stub().callsArgWith(1) diff --git a/services/clsi/test/unit/js/OutputFileFinderTests.js b/services/clsi/test/unit/js/OutputFileFinderTests.js index 8744c6e779..d094f7c66d 100644 --- a/services/clsi/test/unit/js/OutputFileFinderTests.js +++ b/services/clsi/test/unit/js/OutputFileFinderTests.js @@ -12,7 +12,6 @@ */ const SandboxedModule = require('sandboxed-module') const sinon = require('sinon') -require('chai').should() const modulePath = require('path').join( __dirname, '../../../app/js/OutputFileFinder' @@ -26,8 +25,7 @@ describe('OutputFileFinder', function () { this.OutputFileFinder = SandboxedModule.require(modulePath, { requires: { fs: (this.fs = {}), - child_process: { spawn: (this.spawn = sinon.stub()) }, - 'logger-sharelatex': { log: sinon.stub(), warn: sinon.stub() } + child_process: { spawn: (this.spawn = sinon.stub()) } }, globals: { Math // used by lodash diff --git a/services/clsi/test/unit/js/OutputFileOptimiserTests.js b/services/clsi/test/unit/js/OutputFileOptimiserTests.js index e7f7b8b0c8..4c78666084 100644 --- a/services/clsi/test/unit/js/OutputFileOptimiserTests.js +++ b/services/clsi/test/unit/js/OutputFileOptimiserTests.js @@ -12,7 +12,6 @@ */ const SandboxedModule = require('sandboxed-module') const sinon = require('sinon') -require('chai').should() const modulePath = require('path').join( __dirname, '../../../app/js/OutputFileOptimiser' @@ -28,7 +27,6 @@ describe('OutputFileOptimiser', function () { fs: (this.fs = {}), path: (this.Path = {}), child_process: { spawn: (this.spawn = sinon.stub()) }, - 'logger-sharelatex': { log: sinon.stub(), warn: sinon.stub() }, './Metrics': {} }, globals: { Math } // used by lodash diff --git a/services/clsi/test/unit/js/ProjectPersistenceManagerTests.js b/services/clsi/test/unit/js/ProjectPersistenceManagerTests.js index 5e4368fd40..5fb1827206 100644 --- a/services/clsi/test/unit/js/ProjectPersistenceManagerTests.js +++ b/services/clsi/test/unit/js/ProjectPersistenceManagerTests.js @@ -13,7 +13,6 @@ */ const SandboxedModule = require('sandboxed-module') const sinon = require('sinon') -require('chai').should() const assert = require('chai').assert const modulePath = require('path').join( __dirname, @@ -28,11 +27,6 @@ describe('ProjectPersistenceManager', function () { './UrlCache': (this.UrlCache = {}), './CompileManager': (this.CompileManager = {}), diskusage: (this.diskusage = { check: sinon.stub() }), - 'logger-sharelatex': (this.logger = { - log: sinon.stub(), - warn: sinon.stub(), - err: sinon.stub() - }), 'settings-sharelatex': (this.settings = { project_cache_length_ms: 1000 }), diff --git a/services/clsi/test/unit/js/RequestParserTests.js b/services/clsi/test/unit/js/RequestParserTests.js index 6e6c922571..ff2ef7a9d1 100644 --- a/services/clsi/test/unit/js/RequestParserTests.js +++ b/services/clsi/test/unit/js/RequestParserTests.js @@ -11,7 +11,6 @@ */ const SandboxedModule = require('sandboxed-module') const sinon = require('sinon') -require('chai').should() const { expect } = require('chai') const modulePath = require('path').join( __dirname, diff --git a/services/clsi/test/unit/js/ResourceStateManagerTests.js b/services/clsi/test/unit/js/ResourceStateManagerTests.js index e2bc073844..1536299c2d 100644 --- a/services/clsi/test/unit/js/ResourceStateManagerTests.js +++ b/services/clsi/test/unit/js/ResourceStateManagerTests.js @@ -12,7 +12,6 @@ const SandboxedModule = require('sandboxed-module') const sinon = require('sinon') const { expect } = require('chai') -const should = require('chai').should() const modulePath = require('path').join( __dirname, '../../../app/js/ResourceStateManager' @@ -26,7 +25,6 @@ describe('ResourceStateManager', function () { singleOnly: true, requires: { fs: (this.fs = {}), - 'logger-sharelatex': { log: sinon.stub(), err: sinon.stub() }, './SafeReader': (this.SafeReader = {}) } }) diff --git a/services/clsi/test/unit/js/ResourceWriterTests.js b/services/clsi/test/unit/js/ResourceWriterTests.js index 030fe70eb2..267fc2c3a8 100644 --- a/services/clsi/test/unit/js/ResourceWriterTests.js +++ b/services/clsi/test/unit/js/ResourceWriterTests.js @@ -13,7 +13,6 @@ const SandboxedModule = require('sandboxed-module') const sinon = require('sinon') const { expect } = require('chai') -const should = require('chai').should() const modulePath = require('path').join( __dirname, '../../../app/js/ResourceWriter' @@ -34,7 +33,6 @@ describe('ResourceWriter', function () { wrench: (this.wrench = {}), './UrlCache': (this.UrlCache = {}), './OutputFileFinder': (this.OutputFileFinder = {}), - 'logger-sharelatex': { log: sinon.stub(), err: sinon.stub() }, './Metrics': (this.Metrics = { inc: sinon.stub(), Timer: (Timer = (function () { @@ -407,7 +405,7 @@ describe('ResourceWriter', function () { }) return it('should not return an error if the resource writer errored', function () { - return should.not.exist(this.callback.args[0][0]) + return expect(this.callback.args[0][0]).not.to.exist }) }) diff --git a/services/clsi/test/unit/js/StaticServerForbidSymlinksTests.js b/services/clsi/test/unit/js/StaticServerForbidSymlinksTests.js index 9a72168f1f..65a66f3dc3 100644 --- a/services/clsi/test/unit/js/StaticServerForbidSymlinksTests.js +++ b/services/clsi/test/unit/js/StaticServerForbidSymlinksTests.js @@ -9,7 +9,6 @@ * DS102: Remove unnecessary code created because of implicit returns * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ -const should = require('chai').should() const SandboxedModule = require('sandboxed-module') const assert = require('assert') const path = require('path') @@ -32,11 +31,6 @@ describe('StaticServerForbidSymlinks', function () { this.ForbidSymlinks = SandboxedModule.require(modulePath, { requires: { 'settings-sharelatex': this.settings, - 'logger-sharelatex': { - log() {}, - warn() {}, - error() {} - }, fs: this.fs } }) diff --git a/services/clsi/test/unit/js/TikzManager.js b/services/clsi/test/unit/js/TikzManager.js index 4304edc028..30a3807552 100644 --- a/services/clsi/test/unit/js/TikzManager.js +++ b/services/clsi/test/unit/js/TikzManager.js @@ -10,7 +10,6 @@ */ const SandboxedModule = require('sandboxed-module') const sinon = require('sinon') -require('chai').should() const modulePath = require('path').join( __dirname, '../../../app/js/TikzManager' @@ -22,8 +21,7 @@ describe('TikzManager', function () { requires: { './ResourceWriter': (this.ResourceWriter = {}), './SafeReader': (this.SafeReader = {}), - fs: (this.fs = {}), - 'logger-sharelatex': (this.logger = { log() {} }) + fs: (this.fs = {}) } })) }) diff --git a/services/clsi/test/unit/js/UrlCacheTests.js b/services/clsi/test/unit/js/UrlCacheTests.js index 023b92de51..2b991245a9 100644 --- a/services/clsi/test/unit/js/UrlCacheTests.js +++ b/services/clsi/test/unit/js/UrlCacheTests.js @@ -12,7 +12,6 @@ */ const SandboxedModule = require('sandboxed-module') const sinon = require('sinon') -require('chai').should() const modulePath = require('path').join(__dirname, '../../../app/js/UrlCache') const { EventEmitter } = require('events') @@ -25,7 +24,6 @@ describe('UrlCache', function () { requires: { './db': {}, './UrlFetcher': (this.UrlFetcher = {}), - 'logger-sharelatex': (this.logger = { log: sinon.stub() }), 'settings-sharelatex': (this.Settings = { path: { clsiCacheDir: '/cache/dir' } }), diff --git a/services/clsi/test/unit/js/UrlFetcherTests.js b/services/clsi/test/unit/js/UrlFetcherTests.js index 96ef457433..238e5d8aa9 100644 --- a/services/clsi/test/unit/js/UrlFetcherTests.js +++ b/services/clsi/test/unit/js/UrlFetcherTests.js @@ -11,7 +11,6 @@ const SandboxedModule = require('sandboxed-module') const sinon = require('sinon') const { expect } = require('chai') -require('chai').should() const modulePath = require('path').join(__dirname, '../../../app/js/UrlFetcher') const { EventEmitter } = require('events') @@ -25,10 +24,6 @@ describe('UrlFetcher', function () { defaults: (this.defaults = sinon.stub().returns((this.request = {}))) }, fs: (this.fs = {}), - 'logger-sharelatex': (this.logger = { - log: sinon.stub(), - error: sinon.stub() - }), 'settings-sharelatex': (this.settings = {}) } }))