From eec8b6dcfa8b0f433e58de370ff2441ee1791d35 Mon Sep 17 00:00:00 2001 From: Steve Herzog Date: Fri, 3 Feb 2023 10:08:57 -0600 Subject: [PATCH] minor test refactor --- ...http-early-hints-invalid-argument-value.js | 35 --------- .../test-http-early-hints-invalid-argument.js | 74 ++++++++++++------- 2 files changed, 49 insertions(+), 60 deletions(-) delete mode 100644 test/parallel/test-http-early-hints-invalid-argument-value.js diff --git a/test/parallel/test-http-early-hints-invalid-argument-value.js b/test/parallel/test-http-early-hints-invalid-argument-value.js deleted file mode 100644 index aafc4e7ccfe277..00000000000000 --- a/test/parallel/test-http-early-hints-invalid-argument-value.js +++ /dev/null @@ -1,35 +0,0 @@ -'use strict'; -const common = require('../common'); -const assert = require('node:assert'); -const http = require('node:http'); -const debug = require('node:util').debuglog('test'); - -const testResBody = 'response content\n'; - -const server = http.createServer(common.mustCall((req, res) => { - debug('Server sending early hints...'); - res.writeEarlyHints({ - link: '; ' - }); - - debug('Server sending full response...'); - res.end(testResBody); -})); - -server.listen(0, common.mustCall(() => { - const req = http.request({ - port: server.address().port, path: '/' - }); - - req.end(); - debug('Client sending request...'); - - req.on('information', common.mustNotCall()); - - process.on('uncaughtException', (err) => { - debug(`Caught an exception: ${JSON.stringify(err)}`); - if (err.name === 'AssertionError') throw err; - assert.strictEqual(err.code, 'ERR_INVALID_ARG_VALUE'); - process.exit(); - }); -})); diff --git a/test/parallel/test-http-early-hints-invalid-argument.js b/test/parallel/test-http-early-hints-invalid-argument.js index 2cf29666bef11d..81fbf02820ff67 100644 --- a/test/parallel/test-http-early-hints-invalid-argument.js +++ b/test/parallel/test-http-early-hints-invalid-argument.js @@ -6,28 +6,52 @@ const debug = require('node:util').debuglog('test'); const testResBody = 'response content\n'; -const server = http.createServer(common.mustCall((req, res) => { - debug('Server sending early hints...'); - res.writeEarlyHints('bad argument type'); - - debug('Server sending full response...'); - res.end(testResBody); -})); - -server.listen(0, common.mustCall(() => { - const req = http.request({ - port: server.address().port, path: '/' - }); - - req.end(); - debug('Client sending request...'); - - req.on('information', common.mustNotCall()); - - process.on('uncaughtException', (err) => { - debug(`Caught an exception: ${JSON.stringify(err)}`); - if (err.name === 'AssertionError') throw err; - assert.strictEqual(err.code, 'ERR_INVALID_ARG_TYPE'); - process.exit(0); - }); -})); +{ + const server = http.createServer(common.mustCall((req, res) => { + debug('Server sending early hints...'); + assert.throws(() => { + res.writeEarlyHints('bad argument type'); + }, (err) => err.code === 'ERR_INVALID_ARG_TYPE'); + + debug('Server sending full response...'); + res.end(testResBody); + server.close(); + })); + + server.listen(0, common.mustCall(() => { + const req = http.request({ + port: server.address().port, path: '/' + }); + + req.end(); + debug('Client sending request...'); + + req.on('information', common.mustNotCall()); + })); +} + +{ + const server = http.createServer(common.mustCall((req, res) => { + debug('Server sending early hints...'); + assert.throws(() => { + res.writeEarlyHints({ + link: '; ' + }); + }, (err) => err.code === 'ERR_INVALID_ARG_VALUE'); + + debug('Server sending full response...'); + res.end(testResBody); + server.close(); + })); + + server.listen(0, common.mustCall(() => { + const req = http.request({ + port: server.address().port, path: '/' + }); + + req.end(); + debug('Client sending request...'); + + req.on('information', common.mustNotCall()); + })); +}