Node.js Input/Output Testing Question

I wish I knew more about I/O testing and Jest. Trying to get input/output matching to work and the “actual output” looks like random characters when I use console.log(). I have also tried using alert().

Is there some other function that students should use for giving output? Here’s a screenshot:

Any help is appreciated.

Edit: I’ve also noticed that it seems to be including the “Hint: hit control+c anytime to enter REPL.” as part of a student’s output. Hence that last crazy line in the screenshot above.

Edit #2: It works if I print the numbers as a string.

  • Works: console.log(x.toString())
  • Fails: console.log(x)

Anyone?

bueller-ben-stein

Hey @MrBrash, sorry for the delay while I looked into this for you!

I have a short answer and a long answer for you:
Short answer is this is something we are remedying with our upcoming version of I/O tests.

Long explanation is that those funky characters are color codes for terminals, since node wants to print numbers in yellow. Since we run it the same way we normally would, node thinks its talking to a TTY (/ a person is looking at the results). Node’s console.log will add some color codes by default for some types of values (ie numbers and some other values).

I’m going to keep looking into this and see if there’s a workaround for our current version of I/O tests!

Can you try changing the run command to node index.js | cat in the .replit file?

Hey @lena ! Hope I didn’t sound impatient.

Piping the output to cat helped clean it up and the output is now clean as a whistle. Great idea, wish I’d thought of that. That fixes the issue and is an easy workaround for now!

Thanks!

1 Like

So glad to hear it!! And no worries, you can always ping me!