oslabs-beta / SvelteSlicer

MIT License
20 stars 5 forks source link

Backend refactoring #40

Closed heatherbarney closed 2 years ago

heatherbarney commented 2 years ago

This PR includes a bunch of refactoring of the original index.js file to promote better security, readability, maintainability, and to allow for unit testing.

The injected script in index.js that was originally a very long string of code has been pulled out into its own file called "injected.js" so that it can be more easily read and edited during development. To account for that, index.js now accesses and converts injected.js into a string at runtime. The manifest.json file has been updated to give permissions for access to injected.js as a web-accessible resource.

To allow for unit testing of the backend code, Jest and Rewire have been added as packages, and a travis.yml file has been added to create a CI pipeline that will run the testing suite on all pushes and pull requests moving forward. An initial set of unit tests for the new injected.js file has also been added.

Finally, the original injected script has been heavily refactored. All previously global variables have been added to the "slicer" namespace to avoid polluting the global namespace. All previously top level code has been encapsulated into functions to promote unit testing and modularity. And a number of complex functions have been broken down into more discrete functions to promote reusability and hopefully create a more declarative and readable code base.

This is very much still a work in progress, but I think this is a significant improvement in a number of ways to the quality of the code, with no changes to existing functionality.