refactor(jest): move jest 27 and under support to separate directory#4847
refactor(jest): move jest 27 and under support to separate directory#4847rwaskiewicz merged 1 commit intomainfrom
Conversation
|
| Path | Error Count |
|---|---|
| src/dev-server/index.ts | 37 |
| src/mock-doc/serialize-node.ts | 36 |
| src/dev-server/server-process.ts | 32 |
| src/compiler/build/build-stats.ts | 27 |
| src/compiler/output-targets/dist-lazy/generate-lazy-module.ts | 25 |
| src/compiler/style/test/optimize-css.spec.ts | 23 |
| src/runtime/vdom/vdom-render.ts | 23 |
| src/testing/puppeteer/puppeteer-element.ts | 23 |
| src/compiler/prerender/prerender-main.ts | 22 |
| src/runtime/client-hydrate.ts | 19 |
| src/screenshot/connector-base.ts | 19 |
| src/compiler/config/test/validate-paths.spec.ts | 16 |
| src/dev-server/request-handler.ts | 15 |
| src/compiler/prerender/prerender-optimize.ts | 14 |
| src/compiler/sys/stencil-sys.ts | 14 |
| src/compiler/transpile/transpile-module.ts | 14 |
| src/runtime/vdom/vdom-annotations.ts | 14 |
| src/sys/node/node-sys.ts | 14 |
| src/compiler/build/build-finish.ts | 13 |
| src/compiler/prerender/prerender-queue.ts | 13 |
Our most common errors
| Typescript Error Code | Count |
|---|---|
| TS2345 | 435 |
| TS2322 | 412 |
| TS18048 | 321 |
| TS18047 | 99 |
| TS2722 | 38 |
| TS2532 | 36 |
| TS2531 | 25 |
| TS2454 | 15 |
| TS2352 | 13 |
| TS2769 | 10 |
| TS2790 | 10 |
| TS2538 | 8 |
| TS2344 | 5 |
| TS2416 | 4 |
| TS2493 | 3 |
| TS18046 | 2 |
| TS2684 | 1 |
| TS2488 | 1 |
| TS2464 | 1 |
| TS2430 | 1 |
Unused exports report
There are 12 unused exports on this PR. That's the same number of errors on main, so at least we're not creating new ones!
Unused exports
| File | Line | Identifier |
|---|---|---|
| src/runtime/bootstrap-lazy.ts | 21 | setNonce |
| src/screenshot/screenshot-fs.ts | 18 | readScreenshotData |
| src/testing/testing-utils.ts | 198 | withSilentWarn |
| src/utils/index.ts | 140 | CUSTOM |
| src/compiler/app-core/app-data.ts | 25 | BUILD |
| src/compiler/app-core/app-data.ts | 114 | Env |
| src/compiler/app-core/app-data.ts | 116 | NAMESPACE |
| src/compiler/fs-watch/fs-watch-rebuild.ts | 110 | updateCacheFromRebuild |
| src/compiler/types/validate-primary-package-output-target.ts | 62 | satisfies |
| src/compiler/types/validate-primary-package-output-target.ts | 62 | Record |
| src/testing/puppeteer/puppeteer-declarations.ts | 485 | WaitForEventOptions |
| src/compiler/sys/fetch/write-fetch-success.ts | 7 | writeFetchSuccessSync |
| @@ -0,0 +1,14 @@ | |||
| { | |||
There was a problem hiding this comment.
See the commit body where I added this file for details behind some of the decisions. Happy to answer questions about this one
| @@ -1,3 +0,0 @@ | |||
| { | |||
| "extends": "../../tsconfig.internal.json" | |||
There was a problem hiding this comment.
This was git mv'ed, but then when I updated the value for 'extends' here, the GH diff algo thinks they're entirely different files
christian-bromann
left a comment
There was a problem hiding this comment.
Codewise LGTM 👍
The only question I have reading this is whether this has an impact for users updating to the latest Stencil version. If the decoupling requires adding @types/jest to the user dependencies, we might want to have a migration plan. I don't know enough yet to be sure about this.
Good point! Stencil actually does this for folks already (assuming they're using Stencil testing infrastructure via Then try to run the tests, which gives us get the following error: |
| "author": "Ionic Team", | ||
| "homepage": "https://stenciljs.com/", | ||
| "volta": { | ||
| "extends": "../../../../package.json" |
There was a problem hiding this comment.
Oh cool, didn't know you could extend Volta configs
Existing Jest 27 code is moved to a new directory. In this directory, a new "internal" package is created that declares its own support for `@types/jest`, breaking the coupling of type dependencies between Stencil's internal tests and the infrastructure that we build for end users. Prior to this commit, the typings for Jest are declared in Stencil's root-level `package.json` and propagate to the `testing` submodule: ``` ├── src/testing <- Testing submodule │ │ index.ts │ ├── jest <- Files in this directory type check against @types/jest@27 in Stencil's root-level node_modules/ │ │ ├── jest-config.ts │ │ ├── jest-environment.ts │ │ ├── jest-preprocessor.ts │ │ ├── jest-runner.ts │ │ ├── jest-screenshot.ts │ │ ├── jest-serializer.ts │ │ ├── jest-setup-test-framework.ts │ │ └── test/ └── package.json <- Root-level package.json - A dependency on @types/jest@27 is declared here ``` Upon applying this commit, that `@types/jest` coupling is broken with the introduction of a new directory with a separate `package.json` that declares its own `@types/jest` dependency: ``` ├── src/testing/jest/ │ └── jest-27-and-under │ ├── jest-config.ts <- All 'jest-*.ts' files type check against @types/jest@27 from the local node_modules/ │ ├── jest-environment.ts │ ├── jest-preprocessor.ts │ ├── jest-runner.ts │ ├── jest-screenshot.ts │ ├── jest-serializer.ts │ ├── jest-setup-test-framework.ts │ ├── node_modules/ │ ├── package.json <- A dependency on @types/jest@27 is defined here │ ├── test │ └── tsconfig.json └── package.json <- Root-level package.json - A dependency on @types/jest@27 is declared here ``` when creating this commit, `git mv` was run on existing jest infrastructure to preserve history wherever possible. in some cases, paths were updated to account for the directory structure change. this can cause the git diff to appear as a deletion + creation of a new file in some cases. an initial package.json to jest-27-and-under/ was added as a part of this commit. the package name is intentionally using the `@stencil` scope, in the event we ever want to spin this out in the future. the version was defaulted to v1.0.0. the level of effort for it to be kept in sync with the root level package.json is probably not worth the effort at this time. although not strictly needed, volta is added to ensure the same versions of npm/node (moreso the former) are used to update dependencies. STENCIL-951
2b189d7 to
cbebfd0
Compare
add a new abstraction layer to stencil's jest testing configuration/running such that the version of jest is detected when jest is run. based on the version that is detected, defer to the correct piece of versioned infrastructure to setup and run tests. in #4847, the directory structure of the testing submodule was updated to look something like: ``` ├── src/testing/jest/ │ └── jest-27-and-under │ ├── jest-config.ts <- All 'jest-*.ts' files type check against @types/jest@27 from the local node_modules/ │ ├── jest-environment.ts │ ├── jest-preprocessor.ts │ ├── jest-runner.ts │ ├── jest-screenshot.ts │ ├── jest-serializer.ts │ ├── jest-setup-test-framework.ts │ ├── node_modules/ │ ├── package.json <- A dependency on @types/jest@27 is defined here │ ├── test │ └── tsconfig.json └── package.json <- Root-level package.json - A dependency on @types/jest@27 is declared here ``` this commit introduces the following infrastructue to dispatch to jest-27-and-under at runtime: - `jest-adapter` - a file containing a base class to define the API by which version-specific implementations can be loaded. a jest v27-specific implemnetation is included as well - `jest-stencil-connector` - performs the: - detection of the current version of jest - dispatching to the correct infrastructure - `jest-apis` - a file containing typings specific to ambiguous jest typings the end result of this commit should be nothing to the end user (for now). this work shall be used to help support jest v28+ in the near future (dispatching the the correct version)
add a new abstraction layer to stencil's jest testing configuration/running such that the version of jest is detected when jest is run. based on the version that is detected, defer to the correct piece of versioned infrastructure to setup and run tests. in #4847, the directory structure of the testing submodule was updated to look something like: ``` ├── src/testing/jest/ │ └── jest-27-and-under │ ├── jest-config.ts <- All 'jest-*.ts' files type check against @types/jest@27 from the local node_modules/ │ ├── jest-environment.ts │ ├── jest-preprocessor.ts │ ├── jest-runner.ts │ ├── jest-screenshot.ts │ ├── jest-serializer.ts │ ├── jest-setup-test-framework.ts │ ├── node_modules/ │ ├── package.json <- A dependency on @types/jest@27 is defined here │ ├── test │ └── tsconfig.json └── package.json <- Root-level package.json - A dependency on @types/jest@27 is declared here ``` this commit introduces the following infrastructue to dispatch to jest-27-and-under at runtime: - `jest-adapter` - a file containing a base class to define the API by which version-specific implementations can be loaded. a jest v27-specific implemnetation is included as well - `jest-stencil-connector` - performs the: - detection of the current version of jest - dispatching to the correct infrastructure - `jest-apis` - a file containing typings specific to ambiguous jest typings the end result of this commit should be nothing to the end user (for now). this work shall be used to help support jest v28+ in the near future (dispatching the the correct version)
add a new abstraction layer to stencil's jest testing configuration/running such that the version of jest is detected when jest is run. based on the version that is detected, defer to the correct piece of versioned infrastructure to setup and run tests. in #4847, the directory structure of the testing submodule was updated to look something like: ``` ├── src/testing/jest/ │ └── jest-27-and-under │ ├── jest-config.ts │ ├── jest-environment.ts │ ├── jest-preprocessor.ts │ ├── jest-runner.ts │ ├── jest-screenshot.ts │ ├── jest-serializer.ts │ ├── jest-setup-test-framework.ts │ ├── node_modules/ │ ├── package.json │ └── test └── package.json ``` this commit introduces the following infrastructue to dispatch to jest-27-and-under at runtime: ```diff ├── src/testing/jest/ │ └── jest-27-and-under │ ├── jest-config.ts │ ├── jest-environment.ts + │ ├── jest-facade.ts <- Implements base class in `jest-adapter.ts` │ ├── jest-preprocessor.ts │ ├── jest-runner.ts │ ├── jest-screenshot.ts │ ├── jest-serializer.ts │ ├── jest-setup-test-framework.ts │ ├── node_modules/ │ ├── package.json │ └── test + ├── jest-adapter.ts <- Base class all `jest-facade` implementations should follow + ├── jest-apis.ts <- Interactions with Jest prior to knowing the version + ├── jest-stencil-connector.ts <- Routes Jest logic through the correct `jest-facade` implementation └── package.json ``` Where: - `jest-adapter` - a file containing a base class to define the API by which version-specific implementations can be loaded. a jest v27-specific implementation is included as well in `jest-27-and-under/` - `jest-stencil-connector` - performs the detection of the current version of jest - dispatching to the correct infrastructure via `jest-facade` implementations - `jest-apis` - a file containing typings for cases where the jest typings are ambiguous, particularly for when we do not know what the current version of jest is (yet) the end result of this commit should be nothing to the end user (for now). this work shall be used to help support jest v28+ in the near future (dispatching the the correct version)
update the cspell configuration to ignore all node_modules directories. when we introduced new `jest`-version subdirectories in #4847, we failed to update cspell's configuration. as a result, cspell would run against the `node_modules` directory in `src/testing/jest/jest-27-and-under` (e.g. `npm run spellcheck`). this change excludes _all_ `node_modules` cspell's eyes
one consequence of moving to the design laid out in #4847 is that there are now `package.json` file(s) that: - define jest dependencies that are not used by stencil's own internal testing - do not have their dependencies installed when we run `npm ci` (or equivalent) this commit introduces a small shell script that iterates over all jest subdirectories (currently just one, `jest-27-and-under`) and runs `npm ci`. this ensures that these dependencies are installed/up to date when working with stencil
update the cspell configuration to ignore all node_modules directories. when we introduced new `jest`-version subdirectories in #4847, we failed to update cspell's configuration. as a result, cspell would run against the `node_modules` directory in `src/testing/jest/jest-27-and-under` (e.g. `npm run spellcheck`). this change excludes _all_ `node_modules` cspell's eyes
add a new abstraction layer to stencil's jest testing configuration/running such that the version of jest is detected when jest is run. based on the version that is detected, defer to the correct piece of versioned infrastructure to setup and run tests. in #4847, the directory structure of the testing submodule was updated to look something like: ``` ├── src/testing/jest/ │ └── jest-27-and-under │ ├── jest-config.ts │ ├── jest-environment.ts │ ├── jest-preprocessor.ts │ ├── jest-runner.ts │ ├── jest-screenshot.ts │ ├── jest-serializer.ts │ ├── jest-setup-test-framework.ts │ ├── node_modules/ │ ├── package.json │ └── test └── package.json ``` this commit introduces the following infrastructue to dispatch to jest-27-and-under at runtime: ```diff ├── src/testing/jest/ │ └── jest-27-and-under │ ├── jest-config.ts │ ├── jest-environment.ts + │ ├── jest-facade.ts <- Implements base class in `jest-adapter.ts` │ ├── jest-preprocessor.ts │ ├── jest-runner.ts │ ├── jest-screenshot.ts │ ├── jest-serializer.ts │ ├── jest-setup-test-framework.ts │ ├── node_modules/ │ ├── package.json │ └── test + ├── jest-adapter.ts <- Base class all `jest-facade` implementations should follow + ├── jest-apis.ts <- Interactions with Jest prior to knowing the version + ├── jest-stencil-connector.ts <- Routes Jest logic through the correct `jest-facade` implementation └── package.json ``` Where: - `jest-adapter` - a file containing a base class to define the API by which version-specific implementations can be loaded. a jest v27-specific implementation is included as well in `jest-27-and-under/` - `jest-stencil-connector` - performs the detection of the current version of jest - dispatching to the correct infrastructure via `jest-facade` implementations - `jest-apis` - a file containing typings for cases where the jest typings are ambiguous, particularly for when we do not know what the current version of jest is (yet) the end result of this commit should be nothing to the end user (for now). this work shall be used to help support jest v28+ in the near future (dispatching the the correct version)
one consequence of moving to the design laid out in #4847 is that there are now `package.json` file(s) that: - define jest dependencies that are not used by stencil's own internal testing - do not have their dependencies installed when we run `npm ci` (or equivalent) this commit introduces a small shell script that iterates over all jest subdirectories (currently just one, `jest-27-and-under`) and runs `npm ci`. this ensures that these dependencies are installed/up to date when working with stencil
add a new abstraction layer to stencil's jest testing configuration/running such that the version of jest is detected when jest is run. based on the version that is detected, defer to the correct piece of versioned infrastructure to setup and run tests. in #4847, the directory structure of the testing submodule was updated to look something like: ``` ├── src/testing/jest/ │ └── jest-27-and-under │ ├── jest-config.ts │ ├── jest-environment.ts │ ├── jest-preprocessor.ts │ ├── jest-runner.ts │ ├── jest-screenshot.ts │ ├── jest-serializer.ts │ ├── jest-setup-test-framework.ts │ ├── node_modules/ │ ├── package.json │ └── test └── package.json ``` this commit introduces the following infrastructue to dispatch to jest-27-and-under at runtime: ```diff ├── src/testing/jest/ │ └── jest-27-and-under │ ├── jest-config.ts │ ├── jest-environment.ts + │ ├── jest-facade.ts <- Implements base class in `jest-adapter.ts` │ ├── jest-preprocessor.ts │ ├── jest-runner.ts │ ├── jest-screenshot.ts │ ├── jest-serializer.ts │ ├── jest-setup-test-framework.ts │ ├── node_modules/ │ ├── package.json │ └── test + ├── jest-adapter.ts <- Base class all `jest-facade` implementations should follow + ├── jest-apis.ts <- Interactions with Jest prior to knowing the version + ├── jest-stencil-connector.ts <- Routes Jest logic through the correct `jest-facade` implementation └── package.json ``` Where: - `jest-adapter` - a file containing a base class to define the API by which version-specific implementations can be loaded. a jest v27-specific implementation is included as well in `jest-27-and-under/` - `jest-stencil-connector` - performs the detection of the current version of jest - dispatching to the correct infrastructure via `jest-facade` implementations - `jest-apis` - a file containing typings for cases where the jest typings are ambiguous, particularly for when we do not know what the current version of jest is (yet) the end result of this commit should be nothing to the end user (for now). this work shall be used to help support jest v28+ in the near future (dispatching the the correct version)
one consequence of moving to the design laid out in #4847 is that there are now `package.json` file(s) that: - define jest dependencies that are not used by stencil's own internal testing - do not have their dependencies installed when we run `npm ci` (or equivalent) this commit introduces a small shell script that iterates over all jest subdirectories (currently just one, `jest-27-and-under`) and runs `npm ci`. this ensures that these dependencies are installed/up to date when working with stencil
add a new abstraction layer to stencil's jest testing configuration/running such that the version of jest is detected when jest is run. based on the version that is detected, defer to the correct piece of versioned infrastructure to setup and run tests. in #4847, the directory structure of the testing submodule was updated to look something like: ``` ├── src/testing/jest/ │ └── jest-27-and-under │ ├── jest-config.ts │ ├── jest-environment.ts │ ├── jest-preprocessor.ts │ ├── jest-runner.ts │ ├── jest-screenshot.ts │ ├── jest-serializer.ts │ ├── jest-setup-test-framework.ts │ ├── node_modules/ │ ├── package.json │ └── test └── package.json ``` this commit introduces the following infrastructue to dispatch to jest-27-and-under at runtime: ```diff ├── src/testing/jest/ │ └── jest-27-and-under │ ├── jest-config.ts │ ├── jest-environment.ts + │ ├── jest-facade.ts <- Implements base class in `jest-adapter.ts` │ ├── jest-preprocessor.ts │ ├── jest-runner.ts │ ├── jest-screenshot.ts │ ├── jest-serializer.ts │ ├── jest-setup-test-framework.ts │ ├── node_modules/ │ ├── package.json │ └── test + ├── jest-adapter.ts <- Base class all `jest-facade` implementations should follow + ├── jest-apis.ts <- Interactions with Jest prior to knowing the version + ├── jest-stencil-connector.ts <- Routes Jest logic through the correct `jest-facade` implementation └── package.json ``` Where: - `jest-adapter` - a file containing a base class to define the API by which version-specific implementations can be loaded. a jest v27-specific implementation is included as well in `jest-27-and-under/` - `jest-stencil-connector` - performs the detection of the current version of jest - dispatching to the correct infrastructure via `jest-facade` implementations - `jest-apis` - a file containing typings for cases where the jest typings are ambiguous, particularly for when we do not know what the current version of jest is (yet) the end result of this commit should be nothing to the end user (for now). this work shall be used to help support jest v28+ in the near future (dispatching the the correct version)
add a new abstraction layer to stencil's jest testing configuration/running such that the version of jest is detected when jest is run. based on the version that is detected, defer to the correct piece of versioned infrastructure to setup and run tests. in #4847, the directory structure of the testing submodule was updated to look something like: ``` ├── src/testing/jest/ │ └── jest-27-and-under │ ├── jest-config.ts │ ├── jest-environment.ts │ ├── jest-preprocessor.ts │ ├── jest-runner.ts │ ├── jest-screenshot.ts │ ├── jest-serializer.ts │ ├── jest-setup-test-framework.ts │ ├── node_modules/ │ ├── package.json │ └── test └── package.json ``` this commit introduces the following infrastructue to dispatch to jest-27-and-under at runtime: ```diff ├── src/testing/jest/ │ └── jest-27-and-under │ ├── jest-config.ts │ ├── jest-environment.ts + │ ├── jest-facade.ts <- Implements interface in `../jest-adapter.ts` │ ├── jest-preprocessor.ts │ ├── jest-runner.ts │ ├── jest-screenshot.ts │ ├── jest-serializer.ts │ ├── jest-setup-test-framework.ts │ ├── node_modules/ │ ├── package.json │ └── test + ├── jest-apis.ts <- Interactions with Jest prior to knowing the version + ├── jest-facade.ts <- Interface all `jest-facade` implementations should follow + ├── jest-stencil-connector.ts <- Routes Jest logic through the correct `jest-facade` implementation └── package.json ``` Where: - `jest-stencil-connector` - performs the detection of the current version of jest - dispatching to the correct infrastructure via `jest-facade` implementations - `jest-facade.ts` - a file containing an interface to define the API by which version-specific implementation can be loaded. the first implementation for jest 27 and under is included in `jest-27-and-under/` - `jest-apis` - a file containing typings for cases where the jest typings are ambiguous, particularly for when we do not know what the current version of jest is (yet) the end result of this commit should be nothing to the end user (for now). this work shall be used to help support jest v28+ in the near future (dispatching the the correct version)
add a new abstraction layer to stencil's jest testing configuration/running such that the version of jest is detected when jest is run. based on the version that is detected, defer to the correct piece of versioned infrastructure to setup and run tests. in #4847, the directory structure of the testing submodule was updated to look something like: ``` ├── src/testing/jest/ │ └── jest-27-and-under │ ├── jest-config.ts │ ├── jest-environment.ts │ ├── jest-preprocessor.ts │ ├── jest-runner.ts │ ├── jest-screenshot.ts │ ├── jest-serializer.ts │ ├── jest-setup-test-framework.ts │ ├── node_modules/ │ ├── package.json │ └── test └── package.json ``` this commit introduces the following infrastructue to dispatch to jest-27-and-under at runtime: ```diff ├── src/testing/jest/ │ └── jest-27-and-under │ ├── jest-config.ts │ ├── jest-environment.ts + │ ├── jest-facade.ts <- Implements interface in `../jest-adapter.ts` │ ├── jest-preprocessor.ts │ ├── jest-runner.ts │ ├── jest-screenshot.ts │ ├── jest-serializer.ts │ ├── jest-setup-test-framework.ts │ ├── node_modules/ │ ├── package.json │ └── test + ├── jest-apis.ts <- Interactions with Jest prior to knowing the version + ├── jest-facade.ts <- Interface all `jest-facade` implementations should follow + ├── jest-stencil-connector.ts <- Routes Jest logic through the correct `jest-facade` implementation └── package.json ``` Where: - `jest-stencil-connector` - performs the detection of the current version of jest - dispatching to the correct infrastructure via `jest-facade` implementations - `jest-facade.ts` - a file containing an interface to define the API by which version-specific implementation can be loaded. the first implementation for jest 27 and under is included in `jest-27-and-under/` - `jest-apis` - a file containing typings for cases where the jest typings are ambiguous, particularly for when we do not know what the current version of jest is (yet) the end result of this commit should be nothing to the end user (for now). this work shall be used to help support jest v28+ in the near future (dispatching the the correct version)
What is the current behavior?
Stencil's Jest infrastructure assumes that the typings used by Stencil internally will match those
used by end-user's projects. This makes it rather difficult to upgrade Jest for both Stencil internally
and to support newer versions of Jest for users.
GitHub Issue Number: N/A
What is the new behavior?
Existing Jest 27 code is moved to a new directory. In this directory, a new "internal" package
is created that declares its own support for
@types/jest, breaking the coupling of typedependencies between Stencil's internal tests and the infrastructure that we build for end users.
Prior to this commit, the typings for Jest are declared in Stencil's root-level
package.jsonand propagate to thetestingsubmodule:Upon applying this commit, that
@types/jestcoupling is broken with the introduction of a new directory with a separatepackage.jsonthat declares its own@types/jestdependency:Does this introduce a breaking change?
Testing
This commit is largely a lift and shift operation of existing files. As such, I expect the existing unit tests to pass (especially those for the component starter).
I also manually tested this as follows:
npm run clean && npm ci && npm run build && npm packOther information
Jest 28+ Support
This is the first piece of the puzzle (well, technically the second if we count #4666) to support newer versions of Jest. In subsequent PRs, we'll add support for detecting the Jest version, supporting installs of
@types/jestfor Stencil engineers, and of course, infra for Jest 28+For Reviewers
It may be beneficial to review this pull request commit-by-commit. You'll notice that each commit has more detail as to what was done in it to give a little better context. In short:
git mv(to preserve history)git mv(to preserve history)package.jsonthat will declare@types/jest@types/jestto commit 5'spackage.jsonMerging
This commit can be merged upon passing all checks + PR approvals. I'll squash it with a more concise version of all the info presented in this PR summary + the commits themselves
Misc
JIRA: STENCIL-951