dgp1130 / rules_prerender

A Bazel rule set for prerending HTML pages.
13 stars 0 forks source link

Support testing `prerender_component()` #10

Closed dgp1130 closed 3 years ago

dgp1130 commented 3 years ago

The prerender_component() macro compiles a user prerender library with additional deps. Users should be able to test this library and verify that it does what they expect it to do.

I think testing the library itself is pretty straightforward. Since it is just a ts_library() which exports some functions that return templated HTML, this can be tested with a simple jasmine_node_test(). The actual tests could be done by parsing the output as HTML and asserting that its structure matches expectations. If you are using a templating library like lit-html, getting assertable HTML content might be a little trickier, but that's more of a templating problem than a prerendering problem that we need to be concerned with.

We actually have a few examples of this in the site example. I think this works well enough, although it requires a dependency on %{component}_prerender which is a little weird. That target is intended to be a private implementation detail.

In general, we don't want users to be able to depend directly on the ts_library(), because doing so could drop all the related targets that are required for it to run (like scripts, styles, and resources). Testing is a edge case where we just generally don't care about most of those resources.

We should consider documenting and exposing the prerender ts_library(), at least for testing purposes, in order to support this use case.

Alternatively, we could consider a more comprehensive implementation which allows users to test the prerendered HTML, scripts, styles, and resources all at once, but that seems like a much larger problem to handle.

dgp1130 commented 3 years ago

I also filed #36 to look into end-to-end tests for components, since unit tests like this leave a lot to be desired.