Debugging JS unit tests
Do you know if there is a way to debug JS unit tests for smart contracts? I use VS Code for development, and when I try to run a Mocha debugger it complains that artifacts is not defined. I briefly looked at truffle code, it looks like it adds artifacts, contract and some other global js variables when it runs the unit tests. Is there a way for me to add those explicitly in the JS unit test file so I could debug that unit test file?
Be able to debug js unit tests
Not able to debug unit tests as artifacts, contracts and other JS objects injected by truffle are not present when running the debug session
truffle version): 4.0.7node --version): 7.7.3npm --version): 4.0.3 @lazaridiscom You are my hero - this is gonna save me hours of pulling my hair! I am going to post this question on ethereum.stackexchange.com and if you are on there you can post this answer and get points, or if you don't use it I will post the answer, so the community can use it. I know several people who were looking for this as well.
@lazaridiscom sure, go ahead and answer this: https://ethereum.stackexchange.com/questions/41094/debugging-js-unit-tests-with-truffle-framework-in-vs-code
I'll accept your answer
Issue resolved, thanks to @lazaridiscom
Just for reference - the same solution above can be used to start the debugger from command line and debug in node inspector (in Chrome dev tools):
npm install truffle-core
node --inspect-brk ./node_modules/truffle-core/cli.js test test/test_to_debug.js
chrome://inspect page and click the "Open dedicated DevTools for Node" link.cli.js file with execution paused on the first line.I鈥檓 not sure if Truffle鈥檚 folder / project structure changed, but in any case the CLI runner is present at this path now: node_modules/truffle/build/cli.bundled.js. No need to install truffle-core.
Most helpful comment
Just for reference - the same solution above can be used to start the debugger from command line and debug in node inspector (in Chrome dev tools):
chrome://inspectpage and click the "Open dedicated DevTools for Node" link.cli.jsfile with execution paused on the first line.