Parcourir la source

#2920 fixed standalone server to initiate itself on explicit function… (#2924)

* #2920 fixed standalone server to initiate itself on explicit function call

* refactored standalone server module export

* fixed unit tests related to new companion standalone export, set the jest timeout slightly higher

Co-authored-by: Thomas Benndorf <thomas@br24.com>
Cruaier il y a 3 ans
Parent
commit
d0bde78ec6

+ 1 - 0
packages/@uppy/companion/package.json

@@ -93,6 +93,7 @@
   ],
   "jest": {
     "testEnvironment": "node",
+    "testTimeout": 10000,
     "automock": false,
     "collectCoverage": true,
     "collectCoverageFrom": [

+ 1 - 4
packages/@uppy/companion/src/standalone/index.js

@@ -18,7 +18,7 @@ const middlewares = require('../server/middlewares')
  *
  * @returns {object}
  */
-function server (inputCompanionOptions = {}) {
+module.exports = function server (inputCompanionOptions = {}) {
   const app = express()
 
   // Query string keys whose values should not end up in logging output.
@@ -203,6 +203,3 @@ function server (inputCompanionOptions = {}) {
 
   return { app, companionOptions }
 }
-
-const { app, companionOptions } = server()
-module.exports = { app, companionOptions, server }

+ 3 - 1
packages/@uppy/companion/src/standalone/start-server.js

@@ -2,10 +2,12 @@
 const companion = require('../companion')
 // @ts-ignore
 const { version } = require('../../package.json')
-const { app } = require('.')
+const standalone = require('.')
 
 const port = process.env.COMPANION_PORT || 3020
 
+const { app } = standalone()
+
 companion.socket(app.listen(port))
 
 console.log(`Welcome to Companion! v${version}`)

+ 2 - 1
packages/@uppy/companion/test/__tests__/uploader.js

@@ -5,11 +5,12 @@ jest.mock('tus-js-client')
 const fs = require('fs')
 const Uploader = require('../../src/server/Uploader')
 const socketClient = require('../mocksocket')
-const { companionOptions } = require('../../src/standalone')
+const standalone = require('../../src/standalone')
 
 describe('uploader with tus protocol', () => {
   test('upload functions with tus protocol', () => {
     const fileContent = Buffer.from('Some file content')
+    const { companionOptions } = standalone()
     const opts = {
       companionOptions,
       endpoint: 'http://url.myendpoint.com/files',

+ 2 - 1
packages/@uppy/companion/test/mockserver.js

@@ -11,7 +11,7 @@ module.exports.getServer = (env) => {
 
   // delete from cache to force the server to reload companionOptions from the new env vars
   jest.resetModules()
-  const { app } = require('../src/standalone')
+  const standalone = require('../src/standalone')
   const authServer = express()
 
   authServer.use(session({ secret: 'grant', resave: true, saveUninitialized: true }))
@@ -26,6 +26,7 @@ module.exports.getServer = (env) => {
     next()
   })
 
+  const { app } = standalone()
   authServer.use(app)
   return authServer
 }