Introduction to Unit Testing

Hi @filip,

I’ve got the same problem on my Mac as many others have here:

I tried the “fix” of commenting out the lines in runner.js mocha file, that didn’t help.

I tried someone’s suggestion of modifying truffle-config.js to specify the development environment, that didn’t help.

I was thinking of reverting back to a prior version of Node, but when I download the 10.18 package it just unpacks to a directory structure rather than an installer, so I’m not sure what to do with that.

Rather than continuing to try every possible “fix”, can you tell me which one will definitely fix it?

Thanks,
Jeff

Unfortunately @Crypto_Jeff there is no “fix” which works for everybody because we are all running a different Os, with different version of node/truffle.
On you screenshot we can’t see which version of truffle you have installed.
I think the quicker fix will be the one @slavenR and @mawize are describing.

If you want to switch to an other version of node because you are still having an issue i’ll recommend you to use nvm .

https://www.codementor.io/@mercurial/how-to-install-node-js-on-macos-sierra-mphz41ekk

2 Likes

@filip

gabba,

Thanks for the suggestion, unfortunately the fix slavenR suggested didn’t work for me. Still getting the same error when testing.

I followed the directions to install nvm, to the best of my ability, but the installation doesn’t seem to have worked. “command -v nvm” doesn’t do anything on my system. I believe it’s supposed to return “nvm”, but it seems to be ignored (no error though).

Update: I tried another command to install nvm again, it seems to have worked.
This is the command:
touch ~/.bash_profile
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.1/install.sh | bash

NVM is now working. I’m getting “nvm” when I do a “command -v nvm”. I need to see which version to install… I installed version 10.20.1. Test is working now.

Thanks,
Jeff

You are on macOs right ?

if you type

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash

then
nvm -v
can you copy this output on of your terminal ?

Gabba,

I found that one and got it to work.

Thanks,
Jeff

1 Like

@filip

I’m getting an error on the 2nd Test, even though the first test worked, and I just copied and pasted your code for the 2nd Test. Any ideas?

Thanks,
Jeff

@Crypto_Jeff i have seen your test in the next section so i guess you solved it :slight_smile: right ?

Thank you, @slavenR! Works perfectly

1 Like

“TypeError: Error parsing C:/Users/User/desktop/eth/Helloworld/contracts/Migrations.sol: Cannot destructure property ‘body’ of ‘undefined’ as it is undefined.”

Got this error when i try to do the test to fail. I find online that it is known problem for the truffle 5.1.10 to any later version. Should i downgrade just to try it or?

EDIT: this error message stared to appear with any command that i type. I downgraded to version .10 and then i got the error which most of you got “ERR_INVALID_REPL_INPUT”.
I applied the fix that you guys wrote here and everything works perfectly. But soon as i try to test the contract to fail i got the same error as i mentioned above, and its appearing all the time for every command that i type?

Hi @Spartak
Can you share your Migrations.sol code ?

1 Like
pragma solidity >=0.4.21 <0.7.0;

contract Migrations {
  address public owner;
  uint public last_completed_migration;

  constructor() public {
    owner = msg.sender;
  }

  modifier restricted() {
    if (msg.sender == owner) _;
  }

  function setCompleted(uint completed) public restricted {
    last_completed_migration = completed;
  }
}

Edit @gabba use the Preformatted text tag when you link code @Spartak :wink:
prefromatted_text-animated

Ok, will do ,didnt know about that, thanks :slight_smile:

It seems to be an issue with your truffle version

What is your current version of node and truffle ?

Can you try this ?

Delete the build directory

npm uninstall -g truffle
npm install -g [email protected]
truffle compile

1 Like

I did and now it works, thanks :ok_hand:

1 Like

For me downgrading to v10.18.0 also worked.
Thanks a lot :slightly_smiling_face:

Hi, everyone, I’d like to share my experience with ERR_INVALID_REPL_INPUT in Windows.
This was a real HELL !!
For hours I would not find a solution. This error would not let me run my tests with Truffle and Mocha as Filip indicates.
I read this chat here, and also did a ton of research. As some classmates here indicated, it seems to be a BUG in recent version of NODE.JS!
I recommend anyone having this error to check your NODE version. Versions 11 and subsequent seem not to work for TESTS !!
I followed the next steps to uninstall my NODE.JS (v14) and downgrade to v10. After this, my problem disappeared.
+++ STEPS +++

  1. Take a deep breath.
  2. Clean all your cache of npm files: $ npm cache clean --force
  3. Uninstall NODE.JS from Programs. This will kill NPM and Truffle too.
  4. Download v10 NODE.JS from the official repository, here:
    https://nodejs.org/dist/latest-v10.x/
    (I downloaded this one --> node-v10.20.1-x64.msi)
  5. Check node version: $ node --version
  6. Install Truffle again: $ npm install truffle
    WITH THIS, YOU SHOULD BE READY TO TEST AGAIN !! GOOD LUCK <3
5 Likes

Thanks for sharing @Glenn_CostaRica
You can also consider to use nvm to install and switch from one version to an other.
Because if you are working on an other project using an other version of node you will spend your time installing new version of node :wink:

4 Likes

@gabba That was an amazing advice !! I just took an hour to study the NVM and installed !! I love it <3 I did not know much about the world of JavaScript until I took the course here. I had a vague idea, but, a wrong idea. I teach Math and Statistics. So, I had experience with very different languages, a little with Java and C++, and a lot with R. So, I was far away from JavaScript !! After the course with Ivan, I started loving JavaScript. It’s so powerful !!! And now, I am falling in love with it thanks to Node.js… My dream is to learn Solidity in depth. I’m pretty happy to see the integration !!

3 Likes

I had the same problem and use your solution - it worked! Thank you!

1 Like

Thanks! This worked, also I used Hyper terminal and messed around for a good day. Switched to Powershell and that bad boy is in the green.

2 Likes

It`s alive!

image

1 Like