Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fixup: test
  • Loading branch information
ronag committed Mar 11, 2020
commit ed2dd714b999973c76ece4012623e0c7ce013b89
52 changes: 22 additions & 30 deletions test/parallel/test-http-outgoing-proto.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,41 +74,33 @@ assert.throws(() => {
);
}

assert(!OutgoingMessage.prototype.write.call({ _header: 'test' }));

{
const expectedError = {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "chunk" argument must be of type string or an instance of ' +
'Buffer or Uint8Array. Received undefined'
};
assert.throws(() => {
const outgoingMessage = new OutgoingMessage();
outgoingMessage.write.call({ _header: 'test', _hasBody: 'test' }, undefined,
common.expectsError(expectedError));
}
outgoingMessage.write.call({ _header: 'test', _hasBody: 'test' });
}, {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The first argument must be of type string or an instance of ' +
'Buffer. Received undefined'
});

{
const expectedError = {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "chunk" argument must be of type string or an instance of ' +
'Buffer or Uint8Array. Received type number (1)'
};
assert.throws(() => {
const outgoingMessage = new OutgoingMessage();
outgoingMessage.write.call({ _header: 'test', _hasBody: 'test' }, 1,
common.expectsError(expectedError));
}
outgoingMessage.write.call({ _header: 'test', _hasBody: 'test' }, 1);
}, {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The first argument must be of type string or an instance of ' +
'Buffer. Received type number (1)'
});

{
const expectedError = {
code: 'ERR_STREAM_NULL_VALUES',
name: 'TypeError',
};
assert.throws(() => {
const outgoingMessage = new OutgoingMessage();
outgoingMessage.write.call({ _header: 'test', _hasBody: 'test' }, null,
common.expectsError(expectedError));
}
outgoingMessage.write.call({ _header: 'test', _hasBody: 'test' }, null);
}, {
code: 'ERR_STREAM_NULL_VALUES',
name: 'TypeError'
});

// addTrailers()
// The `Error` comes from the JavaScript engine so confirm that it is a
Expand Down
108 changes: 38 additions & 70 deletions test/parallel/test-http-res-write-end-dont-take-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,85 +21,53 @@

'use strict';
const common = require('../common');
const assert = require('assert');
const http = require('http');

{
const server = http.createServer();
const server = http.createServer();

server.once('request', common.mustCall((req, res) => {
// `res.write()` should accept `string`.
res.write('string');
// `res.write()` should accept `buffer`.
res.write(Buffer.from('asdf'));

const expectedError = {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
};

// `res.write()` should not accept an Array.
res.write(['array'], common.expectsError(expectedError));
res.on('error', common.expectsError(expectedError));
res.on('error', () => {
res.destroy();
server.close();
});
server.once('request', common.mustCall((req, res) => {
server.on('request', common.mustCall((req, res) => {
res.end(Buffer.from('asdf'));
}));
// `res.write()` should accept `string`.
res.write('string');
// `res.write()` should accept `buffer`.
res.write(Buffer.from('asdf'));

server.listen(0, function() {
http.get({ port: this.address().port }, (res) => {
res.resume();
});
});
}

// TODO(ronag): end doesn't always call callback
// {
// const server = http.createServer();
const expectedError = {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
};

// server.once('request', common.mustCall((req, res) => {
// // `res.write()` should accept `string`.
// res.write('string');
// // `res.write()` should accept `buffer`.
// res.write(Buffer.from('asdf'));
// `res.write()` should not accept an Array.
assert.throws(
() => {
res.write(['array']);
},
expectedError
);

// const expectedError = {
// code: 'ERR_INVALID_ARG_TYPE',
// name: 'TypeError',
// };
// `res.end()` should not accept an Array.
assert.throws(
() => {
res.end(['moo']);
},
expectedError
);

// // `res.end()` should not accept an Array.
// res.end(['array'], common.expectsError(expectedError));
// res.on('error', common.expectsError(expectedError));
// res.on('error', () => {
// res.destroy();
// server.close();
// });
// }));
// `res.end()` should accept `string`.
res.end('string');
}));

// server.listen(0, function() {
// // Just make a request, other tests handle responses.
// http.get({ port: this.address().port }, (res) => {
// res.resume();
// });
// });
// }

{
const server = http.createServer();

server.once('request', common.mustCall((req, res) => {
// `res.end()` should accept `Buffer`.
res.end(Buffer.from('asdf'), () => {
res.destroy();
server.close();
});
}));

server.listen(0, function() {
// Just make a request, other tests handle responses.
http.get({ port: this.address().port }, (res) => {
server.listen(0, function() {
// Just make a request, other tests handle responses.
http.get({ port: this.address().port }, (res) => {
res.resume();
// Do it again to test .end(Buffer);
http.get({ port: server.address().port }, (res) => {
res.resume();
server.close();
});
});
}
});