dgp1130 / rules_prerender

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

Test `pkg_npm()` rule #11

Closed dgp1130 closed 1 year ago

dgp1130 commented 3 years ago

The pkg_npm() rule generated at //:pkg holds the package which is published to NPM. This contains pre-built artifacts and distinct build files from the normal repository, however it is completed untested by bazel test //... (aside from a simple build_test()). Whether or not it works required manual verification via the ref/external branch.

I want something which still works with bazel test in the main repository. I can imagine a process which looks something like:

  1. Author a custom Bazel workspace inside the main workspace (basically a subdirectory with a WORKSPACE file).
  2. Generate a custom NPM server (not sure if there are existing implementations we could use here).
  3. Write a test which builds //:pkg, then serves it (and all dependencies in the repo node_modules/) out of the custom NPM server.
  4. Run npm install with the custom registry to install all deps in the inner workspace.
  5. Run bazel test //... to build and execute all tests in the inner workspace.

We could then author a couple small but complete examples which prerender a few web pages and assert that they work as expected.

This would be a pretty heavyweight test and would require a custom NPM server, but I think it is worth the investment as without it there is no way to easily verify that the published NPM package actually works as expected without a lot of manual effort.

dgp1130 commented 1 year ago

After the migration to @aspect_rules_js, the new way packages are linked and published works directly through Bazel and doesn't require hacks like this. I already have //examples/external/... as a test case for external workspaces.