Blame view

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