From bfcc09a545aab9c58368455950ec5370725b9a1c Mon Sep 17 00:00:00 2001 From: Priyansh Garg Date: Sun, 5 May 2024 23:24:16 +0530 Subject: [PATCH] Fix command args showing as '[object Object]' in reporter. (#4195) --- lib/reporter/index.js | 12 +++++++++++- test/src/runner/testReporter.js | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/reporter/index.js b/lib/reporter/index.js index 2af49178f5..9cee00e78a 100644 --- a/lib/reporter/index.js +++ b/lib/reporter/index.js @@ -238,7 +238,17 @@ class Reporter extends SimplifiedReporter { static stringifyArgs(args) { if (Array.isArray(args)) { - return args.map((arg) => arg && arg.toString()); + return args.map((arg) => { + let stringifiedArg; + + try { + stringifiedArg = JSON.stringify(arg); + } catch { + stringifiedArg = arg && arg.toString(); + } + + return stringifiedArg; + }); } return args; diff --git a/test/src/runner/testReporter.js b/test/src/runner/testReporter.js index b75ba5d45f..269565ffaa 100644 --- a/test/src/runner/testReporter.js +++ b/test/src/runner/testReporter.js @@ -324,7 +324,7 @@ describe('testReporter', function() { assert.ok(Object.keys(command).includes('endTime')); assert.ok(Object.keys(command).includes('elapsedTime')); assert.ok(Object.keys(command).includes('result')); - assert.deepEqual(command.args, ['http://localhost']); + assert.deepEqual(command.args, ['"http://localhost"']); assert.strictEqual(command.status, 'pass'); } },