Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support testing prerender_component() #10

Closed
dgp1130 opened this issue Jan 11, 2021 · 1 comment
Closed

Support testing prerender_component() #10

dgp1130 opened this issue Jan 11, 2021 · 1 comment
Labels
feature New feature or request
Milestone

Comments

@dgp1130
Copy link
Owner

dgp1130 commented Jan 11, 2021

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 dgp1130 added the feature New feature or request label Jan 11, 2021
@dgp1130 dgp1130 added this to the 1.0.0 milestone Jan 12, 2021
@dgp1130 dgp1130 closed this as completed in d32c0e8 Apr 8, 2021
@dgp1130
Copy link
Owner Author

dgp1130 commented Apr 8, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant