Vince365

  • SharePoint Framework 1.8.0 and unit testing: bad Karma

    Sorry, I had to make the pun…. When the SharePoint Framework originally shipped, the tooling included KarmaJS to write unit tests.

    KarmaJS received a lot of complaints about performance, capabilities, modern JavaScript support… This especially if you use is in combination with PhantomJS, a headless web browser project that has been abandoned a long time ago now which also shipped with SPFx.

    While some people have been arguing for a choice in unit testing framework with SPFx like we (almost) have choice in web frameworks, we saw little movement on that front over the last years.

    A couple of weeks ago, Microsoft release version 1.8.0 of SPFx, it’s a great release especially if we look at it from a tooling modernization perspective (flexibility on the typescript version, depreciation of old fabric stuff…).

    However, they also have removed karmaJS from the standard tooling, and they haven’t documented that change, I have reach out to them internally hoping this will get resolved soon.

    While you can perfectly bring karma back by installing a few packages and tweaking your project configuration, I’d recommend you move to Jest it’s not a big effort and you will get a much faster test cycle. If you want to see the work this represents on a sample webpart, you can look at this pull request, keep in mind it also includes the upgrade to SPFx 1.8.0.

    The PnP generator has included Jest configuration for a while now thanks to the work of Elio Struyf and Andrew Connell and I started the work to update the tooling and documentation around the Azure DevOps integration.

    • 29/3/2019