From c1b791840b49e54e2053149ee059fcb5d79944c4 Mon Sep 17 00:00:00 2001 From: Fernando Dodino Date: Mon, 2 Oct 2023 19:06:39 -0300 Subject: [PATCH] Remove chalk special characters for testing --- examples/avesConError.wlk | 11 ----------- examples/repl-examples/aves.wlk | 12 ++++++++++++ test/repl.test.ts | 34 +++++++++++++++++++-------------- 3 files changed, 32 insertions(+), 25 deletions(-) delete mode 100644 examples/avesConError.wlk diff --git a/examples/avesConError.wlk b/examples/avesConError.wlk deleted file mode 100644 index bb45d52..0000000 --- a/examples/avesConError.wlk +++ /dev/null @@ -1,11 +0,0 @@ -object pepita { - var energia = 100 - - method vola(distancia) { - energia = energia + 'papa' - } - - method energia() { - return energia - } -} \ No newline at end of file diff --git a/examples/repl-examples/aves.wlk b/examples/repl-examples/aves.wlk index 3b78a1a..518eb61 100644 --- a/examples/repl-examples/aves.wlk +++ b/examples/repl-examples/aves.wlk @@ -11,6 +11,18 @@ object pepita { energia = energia - 10 - distancia } + method energia() { + return energia + } +} + +object pepitaRota { + var energia = 100 + + method vola(distancia) { + energia = energia + 'papa' + } + method energia() { return energia } diff --git a/test/repl.test.ts b/test/repl.test.ts index 0a0ac94..e3d7aee 100644 --- a/test/repl.test.ts +++ b/test/repl.test.ts @@ -1,4 +1,3 @@ -import { red, bold } from 'chalk' import { should } from 'chai' import { join } from 'path' import { Interpreter } from 'wollok-ts/dist/interpreter/interpreter' @@ -142,6 +141,15 @@ describe('REPL', () => { result2.should.be.equal(successDescription('ash')) }) + it('should show only custom stack trace elements when an error occurs (with a file)', async () => { + const result = interprete(interpreter, 'pepitaRota.vola(10)') + const stackTrace = result.split('\n') + stackTrace.length.should.equal(4) + consoleCharacters(stackTrace[0]).should.be.equal('✗ Evaluation Error!') + consoleCharacters(stackTrace[1]).should.be.equal('wollok.lang.EvaluationError wrapping TypeScript TypeError: Expected an instance of wollok.lang.Number but got a wollok.lang.String instead') + consoleCharacters(stackTrace[2]).should.be.equal('at aves.pepitaRota.vola(distancia) [aves.wlk:22]') + consoleCharacters(stackTrace[3]).should.be.equal('') + }) describe('in a sub-folder', () => { @@ -167,15 +175,6 @@ describe('REPL', () => { result.should.be.equal(successDescription('ash')) }) - it('should show only custom stack trace elements when an error occurs', async () => { - interpreter = await initializeInterpreter(join(projectPath, 'avesConError.wlk'), options) - const result = interprete(interpreter, 'pepita.vola(10)') - const stackTrace = result.split('\n') - stackTrace[0].trim().should.be.equal(red(`${bold('✗')} Evaluation Error!`)) - stackTrace[1].trim().should.be.equal(red(' wollok.lang.EvaluationError wrapping TypeScript TypeError: Expected an instance of wollok.lang.Number but got a wollok.lang.String instead')) - stackTrace[2].trim().should.be.equal(red(' at avesConError.pepita.vola(distancia) [avesConError.wlk:4]')) - }) - }) }) @@ -193,12 +192,19 @@ describe('REPL', () => { result.should.be.equal(successDescription('assert')) }) - it('should show only custom stack trace elements when an error occurs', async () => { + it('should show only custom stack trace elements when an error occurs (without a file)', async () => { const result = interprete(interpreter, 'assert.equals(2, 1)') const stackTrace = result.split('\n') - stackTrace[0].trim().should.be.equal(red(`${bold('✗')} Evaluation Error!`)) - stackTrace[1].trim().should.be.equal(red(' wollok.lib.AssertionException: Expected <2> but found <1>')) + stackTrace.length.should.equal(4) + consoleCharacters(stackTrace[0]).should.be.equal('✗ Evaluation Error!') + consoleCharacters(stackTrace[1]).should.be.equal('wollok.lib.AssertionException: Expected <2> but found <1>') + consoleCharacters(stackTrace[2]).should.be.equal('') + consoleCharacters(stackTrace[3]).should.be.equal('') }) }) -}) \ No newline at end of file +}) + +const consoleCharacters = (value: string) => + // eslint-disable-next-line no-control-regex + value.replace(/\u001b\[.*?m/g, '').trim() \ No newline at end of file