From 10b043287c3fe96f677e95a0229c520a57105316 Mon Sep 17 00:00:00 2001 From: Yoshiki Kurihara Date: Fri, 21 Jan 2022 07:41:45 +0900 Subject: [PATCH] test: improve test coverage of internal/worker/io PR-URL: https://github.com/nodejs/node/pull/41511 Refs: https://coverage.nodejs.org/coverage-74b9baa4265a8f0d/lib/internal/worker/io.js.html#L415 Reviewed-By: James M Snell Reviewed-By: Benjamin Gruenbaum --- .../test-broadcastchannel-custom-inspect.js | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 test/parallel/test-broadcastchannel-custom-inspect.js diff --git a/test/parallel/test-broadcastchannel-custom-inspect.js b/test/parallel/test-broadcastchannel-custom-inspect.js new file mode 100644 index 00000000000000..409501cb16571e --- /dev/null +++ b/test/parallel/test-broadcastchannel-custom-inspect.js @@ -0,0 +1,40 @@ +'use strict'; + +require('../common'); +const { BroadcastChannel } = require('worker_threads'); +const { inspect } = require('util'); +const assert = require('assert'); + +// This test checks BroadcastChannel custom inspect outputs + +{ + const bc = new BroadcastChannel('name'); + assert.throws(() => bc[inspect.custom].call(), { + code: 'ERR_INVALID_THIS', + }); + bc.close(); +} + +{ + const bc = new BroadcastChannel('name'); + assert.strictEqual(inspect(bc, { depth: -1 }), 'BroadcastChannel'); + bc.close(); +} + +{ + const bc = new BroadcastChannel('name'); + assert.strictEqual( + inspect(bc), + "BroadcastChannel { name: 'name', active: true }" + ); + bc.close(); +} + +{ + const bc = new BroadcastChannel('name'); + assert.strictEqual( + inspect(bc, { depth: null }), + "BroadcastChannel { name: 'name', active: true }" + ); + bc.close(); +}