sp-dev-docs icon indicating copy to clipboard operation
sp-dev-docs copied to clipboard

❓ Debug unit tests in VS code

Open ghost opened this issue 9 years ago • 6 comments

Category

  • [X] Question
  • [ ] Typo
  • [ ] Bug
  • [ ] Additional article idea

Expected or Desired Behavior

The Yeoman templates for SPFx WebParts include some unit tests with Mocha/Chai. I would expect some guidance on how to debug these tests with VS Code.

Observed Behavior

If I try to debug it, with my own launch.json configuration (running gulp test):

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "gulp test",
            "program": "${workspaceRoot}/node_modules/gulp/bin/gulp.js",
            "args": [
                "test"
            ],
            "cwd": "${workspaceRoot}",
            "sourceMaps": true
        }
    ]
}

The breakpoints are not hit in the test code (they are though in gulpfile.js).

My Thoughts

Perhaps I am missing only a small thing, or I haven't really grasped how the unit tests are run (maybe in another process with PhantomJS)? What am I missing? Any help is greatly appreciated.

Steps to Reproduce

  1. Generate a new HelloWorld WebPart
  2. Create .vscode/launch.json (see above)
  3. Set a breakpoint in *.test.ts file
  4. Start Debugging --> gulp test

ghost avatar Oct 05 '17 12:10 ghost

Hi @estruyf perhaps you have an idea?

ghost avatar Oct 09 '17 06:10 ghost

@michel-weber hopefully this article can help you out: https://www.eliostruyf.com/how-to-debug-your-sharepoint-framework-unit-tests/

estruyf avatar Oct 10 '17 15:10 estruyf

@estruyf This is absolutely amazing thank you very much for the detailed blog post :1st_place_medal: . Much more than I expected!

I will close this issue as soon as I have time to try it out.

ghost avatar Oct 11 '17 08:10 ghost

FYI we are experimenting with adding support for the Jest test runner, which has a much better debugging experience than karma/mocha. It is also more reliable, because instead of loading your tests inside the PhantomJS headless browser, it executes them inside the NodeJS environment. This means you can debug right inside VS Code, and the tests run faster. For browser scenarios, Jest relies on a DOM polyfill such as jsdom. It also includes a number of other interesting features such as snapshot-based assertions and built-in support for React-based tests.

octogonz avatar Oct 20 '17 17:10 octogonz

We closed this issue as it had not activity within last 180 days. This is a generic process we have decided to perform for issues, which have not been explicitly marked still to be "work in progress" based on tags. We are performing this cleaning to make sure that old issues that have already been solved (but not closed) or are no longer relevant are cleaned out and make the issues more manageable. If this issue still valid, we would ask you to open a new issue and follow the guidance in the issue template related on the recommended location. We do apologize any inconveniences this might cause. Please do remember that issues in the issue lists are also messages for others in the community, so you can also check if you can assist on any of them. “Sharing is caring!”

spdevdocs avatar Apr 29 '18 12:04 spdevdocs

Issues that have been closed & had no follow-up activity for at least 7 days are automatically locked. Please refer to our wiki for more details, including how to remediate this action if you feel this was done prematurely or in error: Issue List: Our approach to locked issues

msft-github-bot avatar Jan 29 '20 00:01 msft-github-bot