Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Murderlon committed Oct 27, 2021
1 parent c7a1137 commit e8f3198
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 16 deletions.
5 changes: 5 additions & 0 deletions packages/@uppy/companion/src/server/Uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,11 @@ class Uploader {
* start the tus upload
*/
uploadTus () {
if (!this.failed) {
this.failed = true
setTimeout(() => this.emitError(new Error('test')), 1000)
return
}
const file = fs.createReadStream(this.path)
const uploader = this

Expand Down
3 changes: 3 additions & 0 deletions packages/@uppy/tus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,8 @@
},
"peerDependencies": {
"@uppy/core": "^2.0.0"
},
"devDependencies": {
"nock": "^13.1.4"
}
}
2 changes: 1 addition & 1 deletion packages/@uppy/tus/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ module.exports = class Tus extends BasePlugin {
this.uppy.emit('upload-started', file)
this.uppy.log(file.remote.url)

if (file.serverToken) {
if (file.serverToken && file.response) {
return this.connectToServerSocket(file)
}

Expand Down
38 changes: 24 additions & 14 deletions packages/@uppy/tus/src/index.test.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,38 @@
const Core = require('@uppy/core')
const nock = require('nock')

const Tus = require('.')

const KB = 1024

describe('Tus', () => {
it('Throws errors if autoRetry option is true', () => {
it('Throws errors if autoRetry option is passed', () => {
const uppy = new Core()
const errorMsg = /The `autoRetry` option was deprecated and has been removed/

expect(() => {
uppy.use(Tus, { autoRetry: true })
}).toThrowError(/The `autoRetry` option was deprecated and has been removed/)
expect(() => uppy.use(Tus, { autoRetry: true })).toThrowError(errorMsg)
expect(() => uppy.use(Tus, { autoRetry: false })).toThrowError(errorMsg)
expect(() => uppy.use(Tus, { autoRetry: undefined })).toThrowError(errorMsg)
})

it('Throws errors if autoRetry option is false', () => {
it('should do POST request again when retrying', async () => {
const uppy = new Core()
const endpoint = 'https://tusd.tusdemo.net/files/'
const scope = nock(endpoint)

expect(() => {
uppy.use(Tus, { autoRetry: false })
}).toThrowError(/The `autoRetry` option was deprecated and has been removed/)
})
scope.post('/').reply(201)

it('Throws errors if autoRetry option is `undefined`', () => {
const uppy = new Core()
uppy.use(Tus, { endpoint })
uppy.addFile({
source: 'jest',
name: 'foo1.jpg',
type: 'image/jpeg',
data: new File([Buffer.alloc(KB)], { type: 'image/jpeg' }),
})
uppy.on('complete', (result) => expect(result.successful.length).toEqual(1))

await uppy.upload()

expect(() => {
uppy.use(Tus, { autoRetry: undefined })
}).toThrowError(/The `autoRetry` option was deprecated and has been removed/)
scope.done()
})
})
3 changes: 2 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9557,6 +9557,7 @@ __metadata:
dependencies:
"@uppy/companion-client": "workspace:*"
"@uppy/utils": "workspace:*"
nock: ^13.1.4
tus-js-client: ^2.1.1
peerDependencies:
"@uppy/core": ^2.0.0
Expand Down Expand Up @@ -30410,7 +30411,7 @@ hexo-filter-github-emojis@arturi/hexo-filter-github-emojis:
languageName: node
linkType: hard

"nock@npm:^13.1.0":
"nock@npm:^13.1.0, nock@npm:^13.1.4":
version: 13.1.4
resolution: "nock@npm:13.1.4"
dependencies:
Expand Down

0 comments on commit e8f3198

Please sign in to comment.