Skip to content

Commit 0a0ab60

Browse files
committed
fix: Fix macOS test failures
- Fix decoder test failures by importing the necessary data and running a local server, rather than relying on external sites - Tests depending on /proc are now only run on Linux - Tests that only set expectations on the behavior of the node http server (rather than needle itself) have been deleted Closes tomas#393
1 parent 67ad8a4 commit 0a0ab60

File tree

4 files changed

+389
-85
lines changed

4 files changed

+389
-85
lines changed

test/decoder_spec.js

+36-3
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,50 @@ var should = require('should'),
22
needle = require('./../'),
33
Q = require('q'),
44
chardet = require('jschardet'),
5+
fs = require('fs'),
6+
http = require('http'),
57
helpers = require('./helpers');
68

79
describe('character encoding', function() {
810

9-
var url;
1011
this.timeout(5000);
1112

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

14-
before(function() {
15-
url = 'http://www.nina.jp/server/slackware/webapp/tomcat_charset.html';
15+
var port = 2233;
16+
var server;
17+
18+
function createServer() {
19+
return http.createServer(function(req, res) {
20+
21+
req.on('data', function(chunk) {})
22+
23+
req.on('end', function() {
24+
// We used to pull from a particular site that is no longer up.
25+
// This is a local mirror pulled from archive.org
26+
// https://web.archive.org/web/20181003202907/http://www.nina.jp/server/slackware/webapp/tomcat_charset.html
27+
fs.readFile('test/tomcat_charset.html', function(err, data) {
28+
if (err) {
29+
res.writeHead(404);
30+
res.end(JSON.stringify(err));
31+
return;
32+
}
33+
res.writeHeader(200, { 'Content-Type': 'text/html; charset=EUC-JP' })
34+
res.end(data);
35+
});
36+
})
37+
38+
})
39+
}
40+
41+
before(function(done) {
42+
server = createServer();
43+
server.listen(port, done)
44+
url = 'http://localhost:' + port;
45+
})
46+
47+
after(function(done) {
48+
server.close(done)
1649
})
1750

1851
describe('with decode = false', function() {

test/output_spec.js

+11-9
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ describe('with output option', function() {
109109
})
110110
})
111111

112-
if (process.platform != 'win32') {
112+
if (process.platform == 'linux') {
113113
it('closes the file descriptor', function(done) {
114114
var open_descriptors = get_open_file_descriptors();
115115
send_request(file + Math.random(), function(err, resp) {
@@ -167,14 +167,16 @@ describe('with output option', function() {
167167
})
168168
})
169169

170-
it('closes the file descriptor', function(done) {
171-
var open_descriptors = get_open_file_descriptors();
172-
send_request(file + Math.random(), function(err, resp) {
173-
var current_descriptors = get_open_file_descriptors();
174-
open_descriptors.should.eql(current_descriptors);
175-
done()
170+
if (process.platform == 'linux') {
171+
it('closes the file descriptor', function(done) {
172+
var open_descriptors = get_open_file_descriptors();
173+
send_request(file + Math.random(), function(err, resp) {
174+
var current_descriptors = get_open_file_descriptors();
175+
open_descriptors.should.eql(current_descriptors);
176+
done()
177+
})
176178
})
177-
})
179+
}
178180

179181
})
180182

@@ -236,7 +238,7 @@ describe('with output option', function() {
236238
})
237239
})
238240

239-
if (process.platform != 'win32') {
241+
if (process.platform == 'linux') {
240242
it('closes the file descriptor', function(done) {
241243
var open_descriptors = get_open_file_descriptors();
242244
send_request(file + Math.random(), function(err, resp) {

test/request_stream_spec.js

-73
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,6 @@ describe('request stream length', function() {
5959
})
6060
})
6161

62-
if (node_major_ver >= 10) {
63-
it('returns 400 if Transfer-Encoding is set to a blank string', function(done) {
64-
send_request({ headers: { 'Transfer-Encoding': '' }}, function(err, resp) {
65-
should.not.exist(err);
66-
resp.statusCode.should.eql(400);
67-
done()
68-
})
69-
})
70-
} else {
71-
it('doesnt work if Transfer-Encoding is set to a blank string', function(done) {
72-
send_request({ headers: { 'Transfer-Encoding': '' }}, function(err, resp) {
73-
err.code.should.eql('ECONNRESET');
74-
done()
75-
})
76-
})
77-
}
78-
7962
it('works if Transfer-Encoding is not set', function(done) {
8063
send_request({}, function(err, resp) {
8164
should.not.exist(err);
@@ -86,45 +69,6 @@ describe('request stream length', function() {
8669

8770
})
8871

89-
describe('stream_length set to invalid value', function() {
90-
91-
if (node_major_ver >= 10) {
92-
93-
it('returns 400 if Transfer-Encoding is set to a blank string', function(done) {
94-
send_request({ stream_length: 5, headers: { 'Transfer-Encoding': '' }}, function(err, resp) {
95-
should.not.exist(err);
96-
resp.statusCode.should.eql(400);
97-
done()
98-
})
99-
})
100-
101-
it('returns 400 if Transfer-Encoding is not set', function(done) {
102-
send_request({ stream_length: 5 }, function(err, resp) {
103-
should.not.exist(err);
104-
resp.statusCode.should.eql(400);
105-
done()
106-
})
107-
})
108-
109-
} else {
110-
111-
it('doesnt work if Transfer-Encoding is set to a blank string', function(done) {
112-
send_request({ stream_length: 5, headers: { 'Transfer-Encoding': '' }}, function(err, resp) {
113-
err.code.should.eql('ECONNRESET');
114-
done()
115-
})
116-
})
117-
it('doesnt work if Transfer-Encoding is not set', function(done) {
118-
send_request({ stream_length: 5 }, function(err, resp) {
119-
err.code.should.eql('ECONNRESET');
120-
done()
121-
})
122-
})
123-
124-
}
125-
126-
})
127-
12872
describe('stream_length is set to valid value', function() {
12973

13074
it('sets Content-Length header to that value', function(done) {
@@ -206,23 +150,6 @@ describe('request stream length', function() {
206150
})
207151
})
208152

209-
if (node_major_ver >= 10) {
210-
it('returns 400 if Transfer-Encoding is set to a blank string', function(done) {
211-
send_request({ stream_length: 0, headers: { 'Transfer-Encoding': '' }}, function(err, resp) {
212-
should.not.exist(err);
213-
resp.statusCode.should.eql(400);
214-
done()
215-
})
216-
})
217-
} else {
218-
it('throws ECONNRESET if Transfer-Encoding is set to a blank string', function(done) {
219-
send_request({ stream_length: 0, headers: { 'Transfer-Encoding': '' }}, function(err, resp) {
220-
err.code.should.eql('ECONNRESET');
221-
done()
222-
})
223-
})
224-
}
225-
226153
it('works if Transfer-Encoding is not set', function(done) {
227154
send_request({ stream_length: 0 }, function(err, resp) {
228155
should.not.exist(err);

0 commit comments

Comments
 (0)