test.js 2.6 KB

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