test.js 2.4 KB

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