Skip to content

Commit 2fe2053

Browse files
authored
[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
1 parent ec87d52 commit 2fe2053

File tree

131 files changed

+352
-1195
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+352
-1195
lines changed

.changeset/three-hounds-rush.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
'@lit-labs/context': patch
3+
'@lit-labs/motion': patch
4+
'@lit-labs/observers': patch
5+
'@lit-labs/react': patch
6+
'@lit-labs/scoped-registry-mixin': patch
7+
'@lit-labs/task': patch
8+
'lit-element': patch
9+
'lit-html': patch
10+
'@lit/reactive-element': patch
11+
---
12+
13+
Added "types" entry to package exports. This tells newer versions of TypeScript where to look for typings for each module.

.eslintignore

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,6 @@ packages/reactive-element/reactive-controller.*
127127

128128
packages/tests/node_modules/
129129
packages/tests/utils/
130-
packages/tests/**/rollup-resolve-remap.js
131-
packages/tests/**/rollup-resolve-remap.js.map
132-
packages/tests/**/rollup-resolve-remap.d.ts
133-
packages/tests/**/rollup-resolve-remap.d.ts.map
134130
packages/tests/**/run-web-tests.js
135131
packages/tests/**/run-web-tests.js.map
136132
packages/tests/**/run-web-tests.d.ts
@@ -139,10 +135,6 @@ packages/tests/**/web-test-runner.config.js
139135
packages/tests/**/web-test-runner.config.js.map
140136
packages/tests/**/web-test-runner.config.d.ts
141137
packages/tests/**/web-test-runner.config.d.ts.map
142-
packages/tests/**/wtr-config.js
143-
packages/tests/**/wtr-config.js.map
144-
packages/tests/**/wtr-config.d.ts
145-
packages/tests/**/wtr-config.d.ts.map
146138

147139
packages/ts-transformers/*.js
148140
packages/ts-transformers/*.js.map

.prettierignore

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,6 @@ packages/reactive-element/reactive-controller.*
113113

114114
packages/tests/node_modules/
115115
packages/tests/utils/
116-
packages/tests/**/rollup-resolve-remap.js
117-
packages/tests/**/rollup-resolve-remap.js.map
118-
packages/tests/**/rollup-resolve-remap.d.ts
119-
packages/tests/**/rollup-resolve-remap.d.ts.map
120116
packages/tests/**/run-web-tests.js
121117
packages/tests/**/run-web-tests.js.map
122118
packages/tests/**/run-web-tests.d.ts
@@ -125,10 +121,6 @@ packages/tests/**/web-test-runner.config.js
125121
packages/tests/**/web-test-runner.config.js.map
126122
packages/tests/**/web-test-runner.config.d.ts
127123
packages/tests/**/web-test-runner.config.d.ts.map
128-
packages/tests/**/wtr-config.js
129-
packages/tests/**/wtr-config.js.map
130-
packages/tests/**/wtr-config.d.ts
131-
packages/tests/**/wtr-config.d.ts.map
132124

133125
packages/ts-transformers/*.js
134126
packages/ts-transformers/*.js.map

0 commit comments

Comments
 (0)