From 07463ee4746d3eb92d11127acf97f752b20bbcd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Kooi?= Date: Mon, 8 Jan 2018 10:06:11 +0100 Subject: [PATCH] Add test for XHRUpload `limit` option --- package-lock.json | 45 ++++++++++++++++++ package.json | 1 + test/.eslintrc.json | 6 +++ test/endtoend/specs/uppy.test.js | 81 ++++++++++++++++++++++++++++++++ test/endtoend/src/index.html | 5 ++ test/endtoend/src/main.js | 23 +++++++++ 6 files changed, 161 insertions(+) create mode 100644 test/.eslintrc.json diff --git a/package-lock.json b/package-lock.json index e02f7a456..19495a0f3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10555,6 +10555,23 @@ "vlq": "0.2.2" } }, + "make-dir": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-1.1.0.tgz", + "integrity": "sha512-0Pkui4wLJ7rxvmfUvs87skoEaxmu0hCUApF8nonzpl7q//FWp9zu8W61Scz4sd/kUiqDxvUhtoam2efDyiBzcA==", + "dev": true, + "requires": { + "pify": "3.0.0" + }, + "dependencies": { + "pify": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz", + "integrity": "sha1-5aSs0sEB/fPZpNB/DbxNtJ3SgXY=", + "dev": true + } + } + }, "makeerror": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/makeerror/-/makeerror-1.0.11.tgz", @@ -14943,6 +14960,34 @@ } } }, + "temp-dir": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/temp-dir/-/temp-dir-1.0.0.tgz", + "integrity": "sha1-CnwOom06Oa+n4OvqnB/AvE2qAR0=", + "dev": true + }, + "temp-write": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/temp-write/-/temp-write-3.4.0.tgz", + "integrity": "sha1-jP9jD7fp2gXwR8dM5M5NaFRX1JI=", + "dev": true, + "requires": { + "graceful-fs": "4.1.11", + "is-stream": "1.1.0", + "make-dir": "1.1.0", + "pify": "3.0.0", + "temp-dir": "1.0.0", + "uuid": "3.0.1" + }, + "dependencies": { + "pify": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz", + "integrity": "sha1-5aSs0sEB/fPZpNB/DbxNtJ3SgXY=", + "dev": true + } + } + }, "test-exclude": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-4.1.1.tgz", diff --git a/package.json b/package.json index e7e61e61b..bd2373edf 100644 --- a/package.json +++ b/package.json @@ -93,6 +93,7 @@ "redux": "^3.7.2", "sass": "0.5.0", "tape": "^4.8.0", + "temp-write": "^3.4.0", "tinyify": "^1.0.0", "uppy-server": "0.0.7", "watchify": "3.7.0", diff --git a/test/.eslintrc.json b/test/.eslintrc.json new file mode 100644 index 000000000..3078a5188 --- /dev/null +++ b/test/.eslintrc.json @@ -0,0 +1,6 @@ +{ + "extends": "../.eslintrc", + "env": { + "mocha": true + } +} diff --git a/test/endtoend/specs/uppy.test.js b/test/endtoend/specs/uppy.test.js index 4378376db..115f27fb9 100644 --- a/test/endtoend/specs/uppy.test.js +++ b/test/endtoend/specs/uppy.test.js @@ -1,5 +1,7 @@ /* global browser, expect, capabilities */ var path = require('path') +var http = require('http') +var tempWrite = require('temp-write') var testURL = 'http://localhost:4567' @@ -65,3 +67,82 @@ describe('File upload with DragDrop + Tus, DragDrop + XHRUpload, i18n translated // }) // }) // }) + +describe.only('XHRUpload with `limit`', () => { + let server = null + before(() => { + server = http.createServer((req, res) => { + res.writeHead(200, { + 'access-control-allow-origin': '*' + }) + req.pause() + setTimeout(() => { + req.resume() + }, 3000) + req.on('end', () => { + res.end('{"status":"ok"}') + }) + }).listen() + }) + after(() => { + server.close() + server = null + }) + + it('should start counting progress for all files', () => { + const files = [ + makeFile(1000), + makeFile(1000), + makeFile(1000), + makeFile(1000), + makeFile(1000), + makeFile(1000), + makeFile(1000), + makeFile(1000), + makeFile(1000), + makeFile(1000) + ] + + const endpoint = `http://localhost:${server.address().port}` + browser.execute((endpoint) => { + window.startXHRLimitTest(endpoint) + }, endpoint) + + if (browserSupportsChooseFile(capabilities)) { + files.forEach((file) => { + browser.chooseFile('#uppyXhrLimit .uppy-DragDrop-input', file.path) + }) + } else { + browser.execute((files) => { + files.forEach((data, i) => { + window.uppyXhrLimit.addFile({ + source: 'test', + name: `testfile${i}`, + type: 'text/plain', + data: new Blob([data], { type: 'text/plain' }) + }) + }) + }, files.map((file) => file.content.toString('hex'))) + } + + browser.execute(() => { + window.uppyXhrLimit.upload() + }) + browser.pause(5000) + const status = browser.execute(() => ({ + started: window.uppyXhrLimit.uploadsStarted, + complete: window.uppyXhrLimit.uploadsComplete + })).value + expect(status.started).to.be.equal(10) + expect(status.complete).to.be.equal(2) + }) +}) + +function makeFile (size) { + const content = Buffer.allocUnsafe(size) + for (let i = 0; i < size; i++) { + content[i] = Math.floor(Math.random() * 255) + } + + return { path: tempWrite.sync(content), content } +} diff --git a/test/endtoend/src/index.html b/test/endtoend/src/index.html index 8af0f3f9c..40a10bf3f 100644 --- a/test/endtoend/src/index.html +++ b/test/endtoend/src/index.html @@ -35,6 +35,11 @@
+ +

Uppy XHRUpload `limit`

+
+
+
diff --git a/test/endtoend/src/main.js b/test/endtoend/src/main.js index 042e2fffd..2da3b537c 100644 --- a/test/endtoend/src/main.js +++ b/test/endtoend/src/main.js @@ -45,4 +45,27 @@ const uppyDashboard = Uppy({ .use(Tus, { endpoint: 'https://master.tus.io/files/' }) .run() +function startXHRLimitTest (endpoint) { + const uppy = Uppy({ + id: 'uppyXhrLimit', + debug: true, + autoProceed: false + }) + .use(DragDrop, { target: '#uppyXhrLimit' }) + .use(XHRUpload, { endpoint, limit: 2 }) + .run() + + uppy.uploadsStarted = 0 + uppy.uploadsComplete = 0 + + uppy.on('upload-started', () => { + uppy.uploadsStarted++ + }) + uppy.on('upload-success', () => { + uppy.uploadsComplete++ + }) +} + +window.startXHRLimitTest = startXHRLimitTest + console.log(uppyDragDrop, uppyi18n, uppyDashboard)