test.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* global browser, expect, capabilities */
  2. const http = require('http')
  3. const tempWrite = require('temp-write')
  4. const { Writable } = require('stream')
  5. const { supportsChooseFile } = require('../utils')
  6. const devNull = () => Writable({
  7. write (chunk, enc, cb) {
  8. cb()
  9. }
  10. })
  11. const testURL = 'http://localhost:4567/xhr-limit'
  12. describe.skip('XHRUpload with `limit`', () => {
  13. let server = null
  14. before(() => {
  15. server = http.createServer((req, res) => {
  16. res.writeHead(200, {
  17. 'content-type': 'application/json',
  18. 'access-control-allow-origin': '*'
  19. })
  20. req.pipe(devNull())
  21. req.on('end', () => {
  22. setTimeout(() => {
  23. res.end('{"status":"ok"}')
  24. }, 3000)
  25. })
  26. }).listen()
  27. })
  28. after(() => {
  29. server.close()
  30. server = null
  31. })
  32. beforeEach(async () => {
  33. await browser.url(testURL)
  34. })
  35. it('should start counting progress for all files', async () => {
  36. const files = [
  37. makeFile(1000),
  38. makeFile(1000),
  39. makeFile(1000),
  40. makeFile(1000),
  41. makeFile(1000),
  42. makeFile(1000),
  43. makeFile(1000),
  44. makeFile(1000),
  45. makeFile(1000),
  46. makeFile(1000)
  47. ]
  48. const endpoint = `http://localhost:${server.address().port}`
  49. await browser.execute((endpoint) => {
  50. window.startXHRLimitTest(endpoint)
  51. }, endpoint)
  52. if (supportsChooseFile(capabilities)) {
  53. const input = await browser.$('#uppyXhrLimit .uppy-FileInput-input')
  54. for (const file of files) {
  55. await input.setValue(file.path)
  56. }
  57. } else {
  58. await browser.execute((files) => {
  59. files.forEach((data, i) => {
  60. window.uppyXhrLimit.addFile({
  61. source: 'test',
  62. name: `testfile${i}`,
  63. type: 'text/plain',
  64. data: new Blob([data], { type: 'text/plain' })
  65. })
  66. })
  67. }, files.map((file) => file.content.toString('hex')))
  68. }
  69. await browser.execute(() => {
  70. window.uppyXhrLimit.upload()
  71. })
  72. await browser.pause(5000)
  73. const status = await browser.execute(() => ({
  74. started: window.uppyXhrLimit.uploadsStarted,
  75. complete: window.uppyXhrLimit.uploadsComplete
  76. }))
  77. console.log(status)
  78. expect(status.started).to.be.equal(files.length)
  79. expect(status.complete).to.be.equal(2)
  80. })
  81. })
  82. function makeFile (size) {
  83. const content = Buffer.allocUnsafe(size)
  84. for (let i = 0; i < size; i++) {
  85. content[i] = Math.floor(Math.random() * 255)
  86. }
  87. return { path: tempWrite.sync(content), content }
  88. }