Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix macOS + node v17 test failures #394

Merged
merged 1 commit into from
Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -109,7 +109,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 @@ -167,14 +167,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 @@ -236,7 +238,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