Skip to content

Commit 8c32b4a

Browse files
mithunsasidharanMylesBorins
authored andcommitted
test: refactor code to use common.mustCall
PR-URL: #17437 Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 53ed055 commit 8c32b4a

File tree

1 file changed

+21
-26
lines changed

1 file changed

+21
-26
lines changed

test/parallel/test-http-res-write-end-dont-take-array.js

+21-26
Original file line numberDiff line numberDiff line change
@@ -20,44 +20,39 @@
2020
// USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

2222
'use strict';
23-
require('../common');
23+
const common = require('../common');
2424
const assert = require('assert');
2525
const http = require('http');
2626

27-
let test = 1;
27+
const server = http.createServer();
2828

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

37-
// write should not accept an Array
38-
assert.throws(function() {
39-
res.write(['array']);
40-
}, TypeError, 'first argument must be a string or Buffer');
38+
// write should not accept an Array
39+
assert.throws(function() {
40+
res.write(['array']);
41+
}, TypeError, 'first argument must be a string or Buffer');
4142

42-
// end should not accept an Array
43-
assert.throws(function() {
44-
res.end(['moo']);
45-
}, TypeError, 'first argument must be a string or Buffer');
43+
// end should not accept an Array
44+
assert.throws(function() {
45+
res.end(['moo']);
46+
}, TypeError, 'first argument must be a string or Buffer');
4647

47-
// end should accept string
48-
res.end('string');
49-
} else if (test === 2) {
50-
// end should accept Buffer
51-
res.end(Buffer.from('asdf'));
52-
}
53-
});
48+
// end should accept string
49+
res.end('string');
50+
}));
5451

5552
server.listen(0, function() {
5653
// just make a request, other tests handle responses
5754
http.get({ port: this.address().port }, function(res) {
5855
res.resume();
59-
// lazy serial test, because we can only call end once per request
60-
test += 1;
6156
// do it again to test .end(Buffer);
6257
http.get({ port: server.address().port }, function(res) {
6358
res.resume();

0 commit comments

Comments
 (0)