Skip to content

Commit

Permalink
[infra] Replace custom test module remapping with package exports (#3132
Browse files Browse the repository at this point in the history
)

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
aomarks committed Jul 15, 2022
1 parent ec87d52 commit 2fe2053
Show file tree
Hide file tree
Showing 131 changed files with 352 additions and 1,195 deletions.
13 changes: 13 additions & 0 deletions .changeset/three-hounds-rush.md
@@ -0,0 +1,13 @@
---
'@lit-labs/context': patch
'@lit-labs/motion': patch
'@lit-labs/observers': patch
'@lit-labs/react': patch
'@lit-labs/scoped-registry-mixin': patch
'@lit-labs/task': patch
'lit-element': patch
'lit-html': patch
'@lit/reactive-element': patch
---

Added "types" entry to package exports. This tells newer versions of TypeScript where to look for typings for each module.
8 changes: 0 additions & 8 deletions .eslintignore
Expand Up @@ -127,10 +127,6 @@ packages/reactive-element/reactive-controller.*

packages/tests/node_modules/
packages/tests/utils/
packages/tests/**/rollup-resolve-remap.js
packages/tests/**/rollup-resolve-remap.js.map
packages/tests/**/rollup-resolve-remap.d.ts
packages/tests/**/rollup-resolve-remap.d.ts.map
packages/tests/**/run-web-tests.js
packages/tests/**/run-web-tests.js.map
packages/tests/**/run-web-tests.d.ts
Expand All @@ -139,10 +135,6 @@ packages/tests/**/web-test-runner.config.js
packages/tests/**/web-test-runner.config.js.map
packages/tests/**/web-test-runner.config.d.ts
packages/tests/**/web-test-runner.config.d.ts.map
packages/tests/**/wtr-config.js
packages/tests/**/wtr-config.js.map
packages/tests/**/wtr-config.d.ts
packages/tests/**/wtr-config.d.ts.map

packages/ts-transformers/*.js
packages/ts-transformers/*.js.map
Expand Down
8 changes: 0 additions & 8 deletions .prettierignore
Expand Up @@ -113,10 +113,6 @@ packages/reactive-element/reactive-controller.*

packages/tests/node_modules/
packages/tests/utils/
packages/tests/**/rollup-resolve-remap.js
packages/tests/**/rollup-resolve-remap.js.map
packages/tests/**/rollup-resolve-remap.d.ts
packages/tests/**/rollup-resolve-remap.d.ts.map
packages/tests/**/run-web-tests.js
packages/tests/**/run-web-tests.js.map
packages/tests/**/run-web-tests.d.ts
Expand All @@ -125,10 +121,6 @@ packages/tests/**/web-test-runner.config.js
packages/tests/**/web-test-runner.config.js.map
packages/tests/**/web-test-runner.config.d.ts
packages/tests/**/web-test-runner.config.d.ts.map
packages/tests/**/wtr-config.js
packages/tests/**/wtr-config.js.map
packages/tests/**/wtr-config.d.ts
packages/tests/**/wtr-config.d.ts.map

packages/ts-transformers/*.js
packages/ts-transformers/*.js.map
Expand Down

0 comments on commit 2fe2053

Please sign in to comment.