Browse Source

ci: test Companion with Node.js 16.x (#3273)

Antoine du Hamel 3 years ago
parent
commit
2eee086545

+ 1 - 1
.github/workflows/companion.yml

@@ -7,7 +7,7 @@ jobs:
     runs-on: ubuntu-latest
     strategy:
       matrix:
-        node-version: [10.20.1, 12.x, 14.x]
+        node-version: [10.20.1, 12.x, 14.x, 16.x]
     steps:
       - name: Checkout sources
         uses: actions/checkout@v2

+ 9 - 1
packages/@uppy/companion/src/server/Uploader.js

@@ -241,7 +241,15 @@ class Uploader {
    * @param {Function} callback
    */
   onSocketReady (callback) {
-    emitter().once(`connection:${this.token}`, () => callback())
+    /** @type {any} */ // WriteStream.pending was added in Node.js 11.2.0
+    const stream = this.writeStream
+    if (stream.pending) {
+      let connected = false
+      emitter().once(`connection:${this.token}`, () => { if (stream.pending) connected = true; else callback() })
+      this.writeStream.once('ready', () => connected && callback())
+    } else {
+      emitter().once(`connection:${this.token}`, () => callback())
+    }
     logger.debug('waiting for connection', 'uploader.socket.wait', this.shortToken)
   }
 

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

@@ -1,4 +1,4 @@
-/* global jest:false, test:false, expect:false, describe:false */
+'use strict'
 
 jest.mock('tus-js-client')