vite-plugin-single-spa
vite-plugin-single-spa copied to clipboard
Add unit testing for CSS mounting code
Is your feature request related to a problem?
CSS mounting code is not yet backed by unit testing. This has been like this historically because of the injected variables projectId and cssMap.
Please select the type of project this would be for: [ ] Root Config [x] Micro-frontend/parcel
Describe the solution you'd like
Refactor singleMife-css.ts and multiMife-css.ts so projectId and cssMap are injected as parameters through an internal version of cssLifecycleFactory.
Details
The idea is to create "internal-only" modules that are complete and don't depend on replaced values from a Vite build process so they can be imported and unit-tested. In a nutshell:
- Rename
singleMife-css.tsandmultiMife-css.tstosingleMifeImpl.tsandmultiMifeImpl.ts. - Add the extra
base,projectIdandcssMapparameters tocssLifecycleFactory(). - From
cssLifecycleFactory(), distributebase,projectIdandcssMapto wherever is needed. - Get rid of the module-level definitions of
base,projectIdandcssMap. - Create new files with the original names for
singleMifeandmultiMife. - Place the original definitions of
base,projectIdandcssMapin these files or move to a common file and import. - From the new files, import the modified
cssLifecycleFactory()function and export a modified version withbase,projectIdandcssMappre-filled usingbind().