Skip to content

Commit

Permalink
Merge pull request #1716 from yunnysunny/feature/fix-node14-pipe
Browse files Browse the repository at this point in the history
Feature/fix node14 pipe
  • Loading branch information
titanism committed Apr 18, 2022
2 parents 633e467 + 16c88c5 commit 508b9fb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Makefile
Expand Up @@ -7,11 +7,12 @@ test:
@if [ "x$(BROWSER)" = "x" ]; then make test-node; else make test-browser; fi

test-node:
@NODE_ENV=test nyc ./node_modules/.bin/mocha \
@NODE_ENV=test ./node_modules/.bin/nyc ./node_modules/.bin/mocha \
--require should \
--trace-warnings \
--throw-deprecation \
--reporter $(REPORTER) \
--slow 2000 \
--timeout 5000 \
--exit \
$(NODETESTS)
Expand Down
19 changes: 14 additions & 5 deletions test/node/multipart.js
Expand Up @@ -2,14 +2,23 @@

const assert = require('assert');
const fs = require('fs');
const path = require('path');
const should = require('should');
const getPort = require('get-port');
const request = require('../support/client');
const getSetup = require('../support/setup');
const IS_WINDOWS = require('os').platform() === 'win32';

function read(file) {
return fs.readFileSync(file, 'utf8');
}
function getFullPath(filename) {
if (!IS_WINDOWS) {
return filename;
}
const fullPath = path.join(__dirname, '../../', filename);
return fullPath.charAt(0).toLowerCase() + fullPath.slice(1);
}

describe('Multipart', () => {
let setup;
Expand Down Expand Up @@ -86,14 +95,14 @@ describe('Multipart', () => {
const request_ = request.post(`${base}/echo`);

request_.attach('name', 'foo');
request_.attach('name2', 'bar');
request_.attach('name3', 'baz');
// request_.attach('name2', 'bar');
// request_.attach('name3', 'baz');

request_.end((error, res) => {
assert.ok(Boolean(error), 'Request should have failed.');
error.code.should.equal('ENOENT');
error.message.should.containEql('ENOENT');
error.path.should.equal('foo');
error.path.should.equal(getFullPath('foo'));
done();
});
});
Expand All @@ -107,7 +116,7 @@ describe('Multipart', () => {
(res) => assert.fail('It should not allow this'),
(err) => {
err.code.should.equal('ENOENT');
err.path.should.equal('does-not-exist.txt');
err.path.should.equal(getFullPath('does-not-exist.txt'));
}
);
});
Expand Down Expand Up @@ -179,7 +188,7 @@ describe('Multipart', () => {
.end((error, res) => {
assert.ok(Boolean(error), 'Request should have failed.');
error.code.should.equal('ENOENT');
error.path.should.equal('test/node/fixtures/non-existent-file.ext');
error.path.should.equal(getFullPath('test/node/fixtures/non-existent-file.ext'));
done();
});
});
Expand Down
9 changes: 8 additions & 1 deletion test/node/query.js
Expand Up @@ -200,15 +200,22 @@ describe('req.query(Object)', () => {
});
});

it('query-string should be sent on pipe', (done) => {
it('query-string should be sent on pipe', function(done) {
this.timeout(15_000);
const request_ = request.put(`${base}/?name=tobi`);
const stream = fs.createReadStream('test/node/fixtures/user.json');

request_.on('response', (res) => {
res.body.should.eql({ name: 'tobi' });
done();
});
request_.on('error', (err) => {
done(err);
});

stream.on('error', function(err) {
done(err);
});
stream.pipe(request_);
});
});

0 comments on commit 508b9fb

Please sign in to comment.