Skip to content

Commit

Permalink
fix(js-eval): remove ⬊ from output; fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brigand committed Sep 7, 2020
1 parent 715095a commit 5c3fffb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
18 changes: 12 additions & 6 deletions src/plugins/js-eval/__tests__/jsEvalPlugin-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand All @@ -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`);
Expand Down
10 changes: 7 additions & 3 deletions src/plugins/js-eval/jsEvalPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
}
};

Expand Down

0 comments on commit 5c3fffb

Please sign in to comment.