single-spa / single-spa.js.org

Home Page:https://single-spa.js.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Document testing options for cross-microfrontend imports

filoxo opened this issue · comments

This has come up enough times that I'm thinking it could be added to the documentation so that people can find it for themselves. As of right now, I haven't found anywhere in the docs that talks about how to handle microfrontend imports in a testing scenario. Here is one example of what the core team usually recommends: https://single-spa.slack.com/archives/C8R6U7MT7/p1597759987468600?thread_ts=1597759216.468300&cid=C8R6U7MT7

To do unit tests with cross microfrontend imports, you have two options:

  1. Publish the shared dependency to NPM. and install it into your node_modules so that it works in Jest.
  2. Mock the shared dependency with jest’s moduleNameMapper

I think that's a great idea. Should we just add it to the FAQ?

Yeah I think the FAQ would be fine. And maybe link to the FAQ from https://single-spa.js.org/docs/recommended-setup#cross-microfrontend-imports

Another topic relating to testing that we might want to include is if for some reason SystemJS is being included/used in the test environment. Our current recommendation is to mock System. See: single-spa/create-single-spa#248 (reply in thread)