|
1 | 1 | var fs = require('fs'),
|
2 | 2 | expect = require('chai').expect,
|
3 | 3 | sinon = require('sinon'),
|
4 |
| - IS_BROWSER = typeof window !== 'undefined'; |
| 4 | + IS_BROWSER = typeof window !== 'undefined', |
| 5 | + {Readable} = require('stream'); |
5 | 6 |
|
6 | 7 | describe('file upload in request body', function () {
|
7 | 8 | var testrun;
|
@@ -645,4 +646,123 @@ describe('file upload in request body', function () {
|
645 | 646 | .to.equal('Binary file load error: file resolver interface mismatch');
|
646 | 647 | });
|
647 | 648 | });
|
| 649 | + |
| 650 | + (IS_BROWSER ? describe.skip : describe)('large file upload in request body', function () { |
| 651 | + const inStream = new Readable({ |
| 652 | + // eslint-disable-next-line no-empty-function |
| 653 | + read () {} |
| 654 | + }); |
| 655 | + |
| 656 | + // eslint-disable-next-line mocha/no-sibling-hooks |
| 657 | + before(function (done) { |
| 658 | + this.run({ |
| 659 | + // using a custom file-resolver since we don't want to create |
| 660 | + // actual file size of 50MB for testing large file uploads |
| 661 | + fileResolver: { |
| 662 | + stat: function (src, cb) { |
| 663 | + cb(null, {isFile: function () { return true; }, mode: 33188}); |
| 664 | + }, |
| 665 | + createReadStream: function () { |
| 666 | + // creating buffer of size 52428800 bytes corresponds to 50 MB |
| 667 | + inStream.push(Buffer.alloc(50 * 1024 * 1024)); |
| 668 | + inStream.push(null); |
| 669 | + |
| 670 | + return inStream; |
| 671 | + } |
| 672 | + }, |
| 673 | + collection: { |
| 674 | + item: [{ |
| 675 | + request: { |
| 676 | + url: global.servers.http + '/upload', |
| 677 | + method: 'POST', |
| 678 | + body: { |
| 679 | + mode: 'file', |
| 680 | + file: {src: 'test/fixtures/upload-file-large-dummy'} |
| 681 | + } |
| 682 | + } |
| 683 | + }] |
| 684 | + } |
| 685 | + }, function (err, results) { |
| 686 | + testrun = results; |
| 687 | + done(err); |
| 688 | + }); |
| 689 | + }); |
| 690 | + |
| 691 | + // eslint-disable-next-line mocha/no-identical-title |
| 692 | + it('should complete the run', function () { |
| 693 | + expect(testrun).to.be.ok; |
| 694 | + sinon.assert.calledOnce(testrun.start); |
| 695 | + sinon.assert.calledOnce(testrun.done); |
| 696 | + sinon.assert.calledWith(testrun.done.getCall(0), null); |
| 697 | + sinon.assert.callCount(testrun.request, 1); |
| 698 | + }); |
| 699 | + |
| 700 | + it('should upload the large file correctly', function () { |
| 701 | + var response = testrun.request.getCall(0).args[2]; |
| 702 | + |
| 703 | + expect(response.reason()).to.eql('OK'); |
| 704 | + // 52428800 bytes corresponds to 50 MB |
| 705 | + expect(response.json()).to.nested.include({ |
| 706 | + 'received-content-length': 52428800 |
| 707 | + }); |
| 708 | + sinon.assert.calledWith(testrun.request.getCall(0), null); |
| 709 | + }); |
| 710 | + }); |
| 711 | + |
| 712 | + (IS_BROWSER ? describe.skip : describe)('large file upload in form-data mode', function () { |
| 713 | + // eslint-disable-next-line mocha/no-sibling-hooks |
| 714 | + before(function (done) { |
| 715 | + this.run({ |
| 716 | + // using a custom file-resolver since we don't want to create |
| 717 | + // actual file size of 50MB for testing large file uploads |
| 718 | + fileResolver: { |
| 719 | + stat: function (src, cb) { |
| 720 | + cb(null, {isFile: function () { return true; }, mode: 33188}); |
| 721 | + }, |
| 722 | + createReadStream: function () { |
| 723 | + // creating buffer of size 52428800 bytes corresponds to 50 MB |
| 724 | + return Buffer.alloc(50 * 1024 * 1024); |
| 725 | + } |
| 726 | + }, |
| 727 | + collection: { |
| 728 | + item: [{ |
| 729 | + request: { |
| 730 | + url: global.servers.http + '/upload', |
| 731 | + method: 'POST', |
| 732 | + body: { |
| 733 | + mode: 'formdata', |
| 734 | + formdata: [{ |
| 735 | + key: 'file', |
| 736 | + src: 'test/fixtures/upload-file-large-dummy', |
| 737 | + type: 'file' |
| 738 | + }] |
| 739 | + } |
| 740 | + } |
| 741 | + }] |
| 742 | + } |
| 743 | + }, function (err, results) { |
| 744 | + testrun = results; |
| 745 | + done(err); |
| 746 | + }); |
| 747 | + }); |
| 748 | + |
| 749 | + // eslint-disable-next-line mocha/no-identical-title |
| 750 | + it('should complete the run', function () { |
| 751 | + expect(testrun).to.be.ok; |
| 752 | + sinon.assert.calledOnce(testrun.start); |
| 753 | + sinon.assert.calledOnce(testrun.done); |
| 754 | + sinon.assert.calledWith(testrun.done.getCall(0), null); |
| 755 | + sinon.assert.callCount(testrun.request, 1); |
| 756 | + }); |
| 757 | + |
| 758 | + it('should upload the file in formdata mode correctly', function () { |
| 759 | + var response = testrun.request.getCall(0).args[2]; |
| 760 | + |
| 761 | + sinon.assert.calledWith(testrun.request.getCall(0), null); |
| 762 | + expect(response.reason()).to.eql('OK'); |
| 763 | + expect(response.json()).to.nested.include({ |
| 764 | + 'received-content-length': 52428999 |
| 765 | + }); |
| 766 | + }); |
| 767 | + }); |
648 | 768 | });
|
0 commit comments