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

test : updated test to use common.mustCall #17437

Closed
wants to merge 1 commit into from
Closed
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
47 changes: 21 additions & 26 deletions test/parallel/test-http-res-write-end-dont-take-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,44 +20,39 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.

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

let test = 1;
const server = http.createServer();

const server = http.createServer(function(req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
if (test === 1) {
// write should accept string
res.write('string');
// write should accept buffer
res.write(Buffer.from('asdf'));
server.once('request', common.mustCall((req, res) => {
server.on('request', common.mustCall((req, res) => {
res.end(Buffer.from('asdf'));
}));
// write should accept string
res.write('string');
// write should accept buffer
res.write(Buffer.from('asdf'));

// write should not accept an Array
assert.throws(function() {
res.write(['array']);
}, TypeError, 'first argument must be a string or Buffer');
// write should not accept an Array
assert.throws(function() {
res.write(['array']);
}, TypeError, 'first argument must be a string or Buffer');

// end should not accept an Array
assert.throws(function() {
res.end(['moo']);
}, TypeError, 'first argument must be a string or Buffer');
// end should not accept an Array
assert.throws(function() {
res.end(['moo']);
}, TypeError, 'first argument must be a string or Buffer');

// end should accept string
res.end('string');
} else if (test === 2) {
// end should accept Buffer
res.end(Buffer.from('asdf'));
}
});
// 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 }, function(res) {
res.resume();
// lazy serial test, because we can only call end once per request
test += 1;
// do it again to test .end(Buffer);
http.get({ port: server.address().port }, function(res) {
res.resume();
Expand Down