Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[infra] Replace custom test module remapping with package exports (#3132
) Switches from a custom web test runner plugin to the now built-in export conditions configuration, in order to switch between dev and prod builds in our browser tests. ### Background Some of our packages contain 2 separate builds: dev and prod. Dev is the raw output from TypeScript and includes extra debugging features. Prod is the minified build that users will get in production, and excludes those debugging features. The two modes are described in our `package.json` files using [export conditions](https://nodejs.org/api/packages.html#conditional-exports). By default, users get the prod build. If they set the `development` export condition in tools like rollup, webpack, node, they will get the dev build. We run all of our tests against both builds to get full coverage. Previously, we did this with a custom plugin for web test runner which rewrote `development/` paths to production paths when needed. We did this because web test runner did not, at the time, have support for export conditions. Now, web test runner does have support for export conditions. ### Changes - Switches all tests to import their respective libraries using *package self-references*, instead of relative paths. This allows export conditions to take effect *even from within the same package*. - Switches to the `NodeNext` mode for the `module` and `moduleResolution` settings in our `tsconfig.json` files. This is needed for package self-references. - Adds `types` entries to the export conditions in our `package.json` files. This is needed when using `NodeNext`, and is how TypeScript discovers the typings for each specific package export. (Side note, in the future, this feature will allow us to remove the `.d.ts` files that we currently duplicate into the top-level of the package, but we can't do that until our users are also using `NodeNext`). - Added a new web test runner middleware that enforces that we only import dev sources in dev mode, and prod sources in prod mode. It serves a 403 forbidden when this is violated, which fails the test. This should prevent us from accidentally using relative imports in tests in the future. - Deleted the old path-rewriting web test runner plugin, which is no longer needed. - Upgraded all `@web/test-runner` and `@web/dev-server` packages, and consolidated them where possible into the top-level `package.json` for easier upgrades. Fixes #2844 Fixes #3091
- Loading branch information