From 5c3fffbe802cd13edeed464cad9165ed8d72adae Mon Sep 17 00:00:00 2001 From: Frankie Bagnardi Date: Mon, 7 Sep 2020 10:30:50 -0700 Subject: [PATCH] =?UTF-8?q?fix(js-eval):=20remove=20=E2=AC=8A=20from=20out?= =?UTF-8?q?put;=20fix=20failing=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../js-eval/__tests__/jsEvalPlugin-test.js | 18 ++++++++++++------ src/plugins/js-eval/jsEvalPlugin.js | 10 +++++++--- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/plugins/js-eval/__tests__/jsEvalPlugin-test.js b/src/plugins/js-eval/__tests__/jsEvalPlugin-test.js index 3097201..ef3ddbc 100644 --- a/src/plugins/js-eval/__tests__/jsEvalPlugin-test.js +++ b/src/plugins/js-eval/__tests__/jsEvalPlugin-test.js @@ -26,7 +26,7 @@ describe('jsEvalPlugin', () => { expect(output2).toEqual('(okay) 12'); const output3 = await testEval('n> console.warn("test")'); - expect(output3).toEqual(`(okay) test\nundefined`); + expect(output3).toEqual(`(okay) test`); }); it(`errors when it should`, async () => { @@ -106,8 +106,16 @@ describe('jsEvalPlugin', () => { await testEval('b> var x = await Promise.resolve(2n); x'), await testEval('n> var x = await Promise.resolve(2n); if (x) {}'), await testEval('b> var x = await Promise.resolve(2n); if (x) {}'), - await testEval(`n> function foo(){}; let o={[await 'foo']: await eval('1')}; o`), - ]).toEqual(['(okay) 2n', '(okay) 2n', '(okay) undefined', '(okay) undefined', '(okay) { foo: 1 }']); + await testEval( + `n> function foo(){}; let o={[await 'foo']: await eval('1')}; o`, + ), + ]).toEqual([ + '(okay) 2n', + '(okay) 2n', + '(okay) undefined', + '(okay) undefined', + '(okay) { foo: 1 }', + ]); }); it('works with comments', async () => { @@ -132,9 +140,7 @@ describe('jsEvalPlugin', () => { it(`errors when it should`, async () => { const output = await testEval('e> 2++2'); - expect(output).toEqual( - `(fail) 2++2\n ^\nSyntaxError: Unexpected token`, - ); + expect(output).toEqual(`(fail) 2++2\n ^\nSyntaxError: Unexpected token`); const output2 = await testEval('e> throw 2'); expect(output2).toEqual(`(fail) 2`); diff --git a/src/plugins/js-eval/jsEvalPlugin.js b/src/plugins/js-eval/jsEvalPlugin.js index 556fcc6..66641f0 100644 --- a/src/plugins/js-eval/jsEvalPlugin.js +++ b/src/plugins/js-eval/jsEvalPlugin.js @@ -69,12 +69,16 @@ const jsEvalPlugin = async ({ mentionUser, respond, message, selfConfig = {} }) let clean = result.trim(); clean = clean.replace(/(\S)\s*⬊ (undefined|null)$/, '$1'); + clean = clean.replace(/⬊\s*/, ''); + clean = clean.trim(); respond((mentionUser ? `${mentionUser}, ` : '(okay) ') + clean); } catch (e) { - respond( - (mentionUser ? `${mentionUser}, ` : `(${e.reason || 'fail'}) `) + e.message, - ); // Error message always start with Error: + let clean = e.message.trim(); + clean = clean.replace(/⬊\s*/, ''); + clean = clean.trim(); + + respond((mentionUser ? `${mentionUser}, ` : `(${e.reason || 'fail'}) `) + clean); // Error message always start with Error: } };