question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Debugging unit tests

See original GitHub issue
  • [x ] I’ve asked for help in the Truffle Gitter before filing this issue.

Issue

Debugging JS unit tests

Steps to Reproduce

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?

Expected Behavior

Be able to debug js unit tests

Actual Results

Not able to debug unit tests as artifacts, contracts and other JS objects injected by truffle are not present when running the debug session

Environment

  • Operating System: Mac OSX
  • Ethereum client: Ganache
  • Truffle version (truffle version): 4.0.7
  • node version (node --version): 7.7.3
  • npm version (npm --version): 4.0.3
  • IDE: VS Code

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

5reactions
serebrovcommented, Mar 23, 2018

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
  • Open chrome://inspect page and click the “Open dedicated DevTools for Node” link.
  • We should see the cli.js file with execution paused on the first line.
  • Add the test sources into the inspector: click the “Filesystem” on the left and then “Add folder to workspace”.
  • Browse to the folder with tests and add it.
  • Open the file with the test to debug and set the breakpoint, continue the execution until it reaches the breakpoint
  • Now you can step through your test, inspect variables, etc
4reactions
aleybovichcommented, Feb 27, 2018

Issue resolved, thanks to @lazaridiscom

Read more comments on GitHub >

github_iconTop Results From Across the Web

Debug unit tests with Test Explorer - Visual Studio (Windows)
In the Visual Studio editor, set a breakpoint in one or more test methods that you want to debug. Note · In Test...
Read more >
c# - Stepping through and debugging code in Unit tests
First locate the unit test that you want to debug · Double clicking on a unit test will open that unit test ·...
Read more >
Debugging Unit Tests - Developer Documentation
Within Visual Studio (debugging run method)¶ · Right-click the test project, e.g. DataObjectsTest. · Select Properties. Under Debugging -> Command Arguments, type ...
Read more >
Debugging tests - Angular
Click the DEBUG button to open a new browser tab and re-run the tests. Open the browser's Developer Tools. On Windows, press Ctrl-Shift-I...
Read more >
Debugging Your Unit Test Suite in Python | Capital One
Unit tests involving mocked-out components can be very hard to specify correctly. Pytest has many features that can help, but among the most ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found