From 82d5e57ac0db74d212d1c9ef3548b8ffc8d4c629 Mon Sep 17 00:00:00 2001 From: Kohei Ueno Date: Sun, 3 Apr 2022 07:50:37 +0900 Subject: [PATCH] test: add test for exception handlings in debugger PR-URL: https://github.com/nodejs/node/pull/42327 Reviewed-By: James M Snell Reviewed-By: Antoine du Hamel Reviewed-By: Rich Trott Reviewed-By: Daijiro Wachi Reviewed-By: Trivikram Kamat --- test/parallel/test-debugger-invalid-json.js | 42 +++++++++++++++++++++ 1 file changed, 42 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..9bad8ed36949b2 --- /dev/null +++ b/test/parallel/test-debugger-invalid-json.js @@ -0,0 +1,42 @@ +'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 server = http.createServer((req, res) => { + res.statusCode = 400; + res.end('Bad Request'); + }); + 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(() => { + server.close(); + }); + })); +} + +{ + const server = http.createServer((req, res) => { + res.statusCode = 200; + res.end('some data that is invalid json'); + }); + 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(() => { + server.close(); + }); + })); +}