From 2b0816713b1f6044ad4ea2fbb45ddfbb9507d0d7 Mon Sep 17 00:00:00 2001 From: cola119 Date: Mon, 14 Mar 2022 18:16:42 +0900 Subject: [PATCH 1/2] test: add test for exception handlings in debugger --- test/parallel/test-debugger-invalid-json.js | 47 +++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 test/parallel/test-debugger-invalid-json.js diff --git a/test/parallel/test-debugger-invalid-json.js b/test/parallel/test-debugger-invalid-json.js new file mode 100644 index 00000000000000..e17e589da398df --- /dev/null +++ b/test/parallel/test-debugger-invalid-json.js @@ -0,0 +1,47 @@ +'use strict'; +const common = require('../common'); +const startCLI = require('../common/debugger'); + +common.skipIfInspectorDisabled(); + +const assert = require('assert'); +const http = require('http'); + +const host = '127.0.0.1'; + +const testWhenBadRequest = () => { + const server = http.createServer((req, res) => { + res.statusCode = 400; + res.end('Bad Request'); + }); + server.listen(0, async () => { + try { + const port = server.address().port; + const cli = startCLI([`${host}:${port}`]); + const code = await cli.quit(); + assert.strictEqual(code, 1); + } finally { + server.close(); + } + }); +}; + +const testInvalidJson = () => { + const server = http.createServer((req, res) => { + res.statusCode = 200; + res.end('ok'); + }); + server.listen(0, host, async () => { + try { + const port = server.address().port; + const cli = startCLI([`${host}:${port}`]); + const code = await cli.quit(); + assert.strictEqual(code, 1); + } finally { + server.close(); + } + }); +}; + +testWhenBadRequest(); +testInvalidJson(); From dca80cd3d61cfe25888ee15cf5e242c0a9dca062 Mon Sep 17 00:00:00 2001 From: cola119 Date: Mon, 14 Mar 2022 22:55:42 +0900 Subject: [PATCH 2/2] fixup! test: add test for exception handlings in debugger --- test/parallel/test-debugger-invalid-json.js | 43 +++++++++------------ 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/test/parallel/test-debugger-invalid-json.js b/test/parallel/test-debugger-invalid-json.js index e17e589da398df..9bad8ed36949b2 100644 --- a/test/parallel/test-debugger-invalid-json.js +++ b/test/parallel/test-debugger-invalid-json.js @@ -9,39 +9,34 @@ const http = require('http'); const host = '127.0.0.1'; -const testWhenBadRequest = () => { +{ const server = http.createServer((req, res) => { res.statusCode = 400; res.end('Bad Request'); }); - server.listen(0, async () => { - try { - const port = server.address().port; - const cli = startCLI([`${host}:${port}`]); - const code = await cli.quit(); + server.listen(0, common.mustCall(() => { + const port = server.address().port; + const cli = startCLI([`${host}:${port}`]); + cli.quit().then(common.mustCall((code) => { assert.strictEqual(code, 1); - } finally { + })).finally(() => { server.close(); - } - }); -}; + }); + })); +} -const testInvalidJson = () => { +{ const server = http.createServer((req, res) => { res.statusCode = 200; - res.end('ok'); + res.end('some data that is invalid json'); }); - server.listen(0, host, async () => { - try { - const port = server.address().port; - const cli = startCLI([`${host}:${port}`]); - const code = await cli.quit(); + server.listen(0, host, common.mustCall(() => { + const port = server.address().port; + const cli = startCLI([`${host}:${port}`]); + cli.quit().then(common.mustCall((code) => { assert.strictEqual(code, 1); - } finally { + })).finally(() => { server.close(); - } - }); -}; - -testWhenBadRequest(); -testInvalidJson(); + }); + })); +}