microsoft / sarif-vscode-extension

SARIF Microsoft Visual Studio Code extension
MIT License
110 stars 49 forks source link

Fixes unit tests #523

Closed aeisenberg closed 1 year ago

aeisenberg commented 1 year ago

With this change, running npm run tests will succeed.

It looks like the tests have not been run for a long time and the implementation has drifted, making the tests harder to run.

There are lots of small changes here:

  1. Change the launch.json to remove --inspect-brk=9229, which was preventing the tests from running.
  2. Add some exclusions to settings.json so that some unnecessary folders are removed from the file open dialog.
  3. Fix up the mock objects so that the tests correctly reflect the current implementation.
  4. Add await and async to setState in indexStore.ts so that the function correctly waits for the post message to complete. (Note this is the only change to non-test code in this PR.)
  5. Change the test assertions so that they test the right things.

A few comments here on future work:

  1. These tests all use stubs for the vscode API. This isn't ideal since it's complicated and we really should be testing the vscode API directly. Future work should be to run the unit tests from inside of a workbench so we don't need to stub out the vscode API.
  2. We should be running the tests on each PR. I'll fix this in a followup PR.

To validate this PR, please run npm run tests locally and ensure the tests pass for you.

aeisenberg commented 1 year ago

@EasyRhinoMSFT could you take a look at this? I'd like to eventually run the unit tests on every PR.

aeisenberg commented 1 year ago

Thanks for the review!