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

Feature/fix node14 pipe #1716

Merged
merged 6 commits into from
Apr 18, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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_);
});
});