Skip to content

Commit

Permalink
Merge pull request #394 from joeyparrish/fix-macos-tests
Browse files Browse the repository at this point in the history
fix: Fix macOS + node v17 test failures
  • Loading branch information
tomas authored Apr 7, 2022
2 parents b5cf883 + 8ea8064 commit 0044513
Show file tree
Hide file tree
Showing 4 changed files with 389 additions and 85 deletions.
39 changes: 36 additions & 3 deletions test/decoder_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,50 @@ var should = require('should'),
needle = require('./../'),
Q = require('q'),
chardet = require('jschardet'),
fs = require('fs'),
http = require('http'),
helpers = require('./helpers');

describe('character encoding', function() {

var url;
this.timeout(5000);

describe('Given content-type: "text/html; charset=EUC-JP"', function() {

before(function() {
url = 'http://www.nina.jp/server/slackware/webapp/tomcat_charset.html';
var port = 2233;
var server;

function createServer() {
return http.createServer(function(req, res) {

req.on('data', function(chunk) {})

req.on('end', function() {
// We used to pull from a particular site that is no longer up.
// This is a local mirror pulled from archive.org
// https://web.archive.org/web/20181003202907/http://www.nina.jp/server/slackware/webapp/tomcat_charset.html
fs.readFile('test/tomcat_charset.html', function(err, data) {
if (err) {
res.writeHead(404);
res.end(JSON.stringify(err));
return;
}
res.writeHeader(200, { 'Content-Type': 'text/html; charset=EUC-JP' })
res.end(data);
});
})

})
}

before(function(done) {
server = createServer();
server.listen(port, done)
url = 'http://localhost:' + port;
})

after(function(done) {
server.close(done)
})

describe('with decode = false', function() {
Expand Down
20 changes: 11 additions & 9 deletions test/output_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describe('with output option', function() {
})
})

if (process.platform != 'win32') {
if (process.platform == 'linux') {
it('closes the file descriptor', function(done) {
var open_descriptors = get_open_file_descriptors();
send_request(file + Math.random(), function(err, resp) {
Expand Down Expand Up @@ -174,14 +174,16 @@ describe('with output option', function() {
})
})

it('closes the file descriptor', function(done) {
var open_descriptors = get_open_file_descriptors();
send_request(file + Math.random(), function(err, resp) {
var current_descriptors = get_open_file_descriptors();
open_descriptors.should.eql(current_descriptors);
done()
if (process.platform == 'linux') {
it('closes the file descriptor', function(done) {
var open_descriptors = get_open_file_descriptors();
send_request(file + Math.random(), function(err, resp) {
var current_descriptors = get_open_file_descriptors();
open_descriptors.should.eql(current_descriptors);
done()
})
})
})
}

})

Expand Down Expand Up @@ -243,7 +245,7 @@ describe('with output option', function() {
})
})

if (process.platform != 'win32') {
if (process.platform == 'linux') {
it('closes the file descriptor', function(done) {
var open_descriptors = get_open_file_descriptors();
send_request(file + Math.random(), function(err, resp) {
Expand Down
73 changes: 0 additions & 73 deletions test/request_stream_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,6 @@ describe('request stream length', function() {
})
})

if (node_major_ver >= 10) {
it('returns 400 if Transfer-Encoding is set to a blank string', function(done) {
send_request({ headers: { 'Transfer-Encoding': '' }}, function(err, resp) {
should.not.exist(err);
resp.statusCode.should.eql(400);
done()
})
})
} else {
it('doesnt work if Transfer-Encoding is set to a blank string', function(done) {
send_request({ headers: { 'Transfer-Encoding': '' }}, function(err, resp) {
err.code.should.eql('ECONNRESET');
done()
})
})
}

it('works if Transfer-Encoding is not set', function(done) {
send_request({}, function(err, resp) {
should.not.exist(err);
Expand All @@ -86,45 +69,6 @@ describe('request stream length', function() {

})

describe('stream_length set to invalid value', function() {

if (node_major_ver >= 10) {

it('returns 400 if Transfer-Encoding is set to a blank string', function(done) {
send_request({ stream_length: 5, headers: { 'Transfer-Encoding': '' }}, function(err, resp) {
should.not.exist(err);
resp.statusCode.should.eql(400);
done()
})
})

it('returns 400 if Transfer-Encoding is not set', function(done) {
send_request({ stream_length: 5 }, function(err, resp) {
should.not.exist(err);
resp.statusCode.should.eql(400);
done()
})
})

} else {

it('doesnt work if Transfer-Encoding is set to a blank string', function(done) {
send_request({ stream_length: 5, headers: { 'Transfer-Encoding': '' }}, function(err, resp) {
err.code.should.eql('ECONNRESET');
done()
})
})
it('doesnt work if Transfer-Encoding is not set', function(done) {
send_request({ stream_length: 5 }, function(err, resp) {
err.code.should.eql('ECONNRESET');
done()
})
})

}

})

describe('stream_length is set to valid value', function() {

it('sets Content-Length header to that value', function(done) {
Expand Down Expand Up @@ -206,23 +150,6 @@ describe('request stream length', function() {
})
})

if (node_major_ver >= 10) {
it('returns 400 if Transfer-Encoding is set to a blank string', function(done) {
send_request({ stream_length: 0, headers: { 'Transfer-Encoding': '' }}, function(err, resp) {
should.not.exist(err);
resp.statusCode.should.eql(400);
done()
})
})
} else {
it('throws ECONNRESET if Transfer-Encoding is set to a blank string', function(done) {
send_request({ stream_length: 0, headers: { 'Transfer-Encoding': '' }}, function(err, resp) {
err.code.should.eql('ECONNRESET');
done()
})
})
}

it('works if Transfer-Encoding is not set', function(done) {
send_request({ stream_length: 0 }, function(err, resp) {
should.not.exist(err);
Expand Down
Loading

0 comments on commit 0044513

Please sign in to comment.