long_string_spec.js 928 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. var needle = require('../'),
  2. should = require('should');
  3. describe('when posting a very long string', function() {
  4. this.timeout(20000);
  5. function get_string(length) {
  6. var str = '';
  7. for (var i = 0; i < length; i++) {
  8. str += 'x';
  9. }
  10. return str;
  11. }
  12. var major_version = process.version.split('.')[0];
  13. it("shouldn't throw an EPIPE error out of nowhere", function(done) {
  14. // for some reason this test fails in Github Actions with Node v8.x
  15. // although in my Linux box passes without issues
  16. if (process.env.CI && (major_version == 'v8' || major_version == 'v6')) {
  17. return done();
  18. }
  19. var error;
  20. function finished() {
  21. setTimeout(function() {
  22. should.not.exist(error);
  23. done();
  24. }, 300);
  25. }
  26. try {
  27. needle.post('https://google.com', { data: get_string(Math.pow(2, 20)) }, finished)
  28. } catch(e) {
  29. error = e;
  30. }
  31. })
  32. })