BeaconCMS / beacon

Open-source content management system (CMS) built with Phoenix LiveView. Faster render times to boost SEO performance, even for the most content-heavy pages.
https://beaconcms.org
MIT License
885 stars 89 forks source link

[Proposal] `Beacon.Testing` #527

Open leandrocp opened 3 months ago

leandrocp commented 3 months ago

Add Beacon.Testing to solve some pain points with testing Beacon resources and pages:

Creating resources

Move Beacon.Fixtures to lib/beacon/testing/fixtures.ex and make it public as Beacon.Testing.Fixtures. That module should be imported on use Beacon.Testing

Creating and Reloading resources

Currently to test pages and any other resources we need to first create the resource in the database and then load that resource into memory (load the Elixir module), eg:

component_fixture(name: "sample")
Beacon.Loader.reload_components_module(:my_site)

If one tries to call that component without calling reload_components_module it fails since the module that provides that components has not been loaded. So at this point we have 2 options: call reload automatically after each fixture is executed (pages, layouts, components, live data, etc) or let users call reload manually as needed.

Calling automatically works for most cases but not always so we need to introduce a testing mode that is either :automatic or :manual that will call the respective reload functions or not.

Loading global required module

Routes and Components modules are global, ie: most of the other modules depend on it and thus should be eagerly loaded once before tests are executed.