diff --git a/test/decoder_spec.js b/test/decoder_spec.js index 35677aa7f..4100fba91 100644 --- a/test/decoder_spec.js +++ b/test/decoder_spec.js @@ -6,11 +6,10 @@ var should = require('should'), describe('character encoding', function() { var url; + this.timeout(5000); describe('test A', function() { - this.timeout(5000); - before(function() { url = 'http://www.huanqiukexue.com/html/newgc/2014/1215/25011.html'; }) @@ -40,7 +39,7 @@ describe('character encoding', function() { resp.body.indexOf('柳博米尔斯基').should.not.eql(-1); done(); }) - + }) }) diff --git a/test/errors_spec.js b/test/errors_spec.js index a8f0f1f20..fd1a8cc7f 100644 --- a/test/errors_spec.js +++ b/test/errors_spec.js @@ -107,31 +107,31 @@ describe('errors', function(){ }) it('emits end event once, with error', function(done) { - var called = 0, + var callcount = 0, stream = needle.get(url); stream.on('end', function(err) { - called++; + callcount++; }) setTimeout(function() { - called.should.equal(1); + callcount.should.equal(1); done(); - }, 50) + }, 200) }) - it('error should be ENOTFOUND or EADDRINFO', function(done){ - var error, + it('error should be ENOTFOUND or EADDRINFO', function(done) { + var errorific, stream = needle.get(url); stream.on('end', function(err) { - error = err; + errorific = err; }) setTimeout(function() { - error.code.should.match(/ENOTFOUND|EADDRINFO/) + errorific.code.should.match(/ENOTFOUND|EADDRINFO/) done(); - }, 50) + }, 200) }) it('does not emit a readable event', function(done){ diff --git a/test/redirect_spec.js b/test/redirect_spec.js index 42f562d9a..627f67b41 100644 --- a/test/redirect_spec.js +++ b/test/redirect_spec.js @@ -61,7 +61,8 @@ describe('redirects', function() { var other_protocol = protocol == 'http' ? 'https' : 'http'; var opts, // each test will modify this - url = protocol + '://localhost:' + ports[protocol] + '/hello'; + host = '127.0.0.1', + url = protocol + '://' + host + ':' + ports[protocol] + '/hello'; function send_request(opts, cb) { opts.rejectUnauthorized = false; @@ -161,14 +162,14 @@ describe('redirects', function() { describe('and redirected to same path on another host, same protocol', function() { before(function() { - location = url.replace('localhost', hostname); + location = url.replace(host, hostname); }) it('follows redirect', followed_same_protocol); }) describe('and redirected to same path on another host, different protocol', function() { before(function() { - location = url.replace('localhost', hostname).replace(protocol, other_protocol).replace(ports[protocol], ports[other_protocol]); + location = url.replace(host, hostname).replace(protocol, other_protocol).replace(ports[protocol], ports[other_protocol]); }) it('follows redirect', followed_other_protocol); }) @@ -277,7 +278,7 @@ describe('redirects', function() { it('sets Referer header when following redirect', function(done) { send_request(opts, function(err, resp) { - spies.http.args[0][0].headers['Referer'].should.eql("http://localhost:8888/hello"); + spies.http.args[0][0].headers['Referer'].should.eql("http://" + host + ":8888/hello"); // spies.http.args[0][3].should.eql({ foo: 'bar'}); done(); }) @@ -323,7 +324,7 @@ describe('redirects', function() { // by default it will follow other protocols describe('and redirected to same path on another domain, same protocol', function() { before(function() { - location = url.replace('localhost', hostname); + location = url.replace(host, hostname); }) it('follows redirect', followed_same_protocol); }) @@ -339,7 +340,7 @@ describe('redirects', function() { // by default it will follow other protocols describe('and redirected to same path on another domain, same protocol', function() { before(function() { - location = url.replace('localhost', hostname); + location = url.replace(host, hostname); }) it('does not follow redirect', not_followed); @@ -356,7 +357,7 @@ describe('redirects', function() { // by default it will follow other hosts describe('and redirected to same path on another domain, different protocol', function() { before(function() { - location = url.replace('localhost', hostname).replace(protocol, other_protocol).replace(ports[protocol], ports[other_protocol]); + location = url.replace(host, hostname).replace(protocol, other_protocol).replace(ports[protocol], ports[other_protocol]); }) it('follows redirect', followed_other_protocol); }) @@ -372,7 +373,7 @@ describe('redirects', function() { // by default it will follow other hosts describe('and redirected to same path on another domain, different protocol', function() { before(function() { - location = url.replace('localhost', hostname).replace(protocol, other_protocol).replace(ports[protocol], ports[other_protocol]); + location = url.replace(host, hostname).replace(protocol, other_protocol).replace(ports[protocol], ports[other_protocol]); }) it('does not follow redirect', not_followed); })