Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(test): pass jest args correctly for v28/29 #5068

Merged
merged 1 commit into from
Nov 16, 2023

Conversation

rwaskiewicz
Copy link
Contributor

@rwaskiewicz rwaskiewicz commented Nov 13, 2023

Note: Depends on ##5069 - please review when this PR is moved out of draft state

What is the current behavior?

We use any to type our Jest Test Runner, which we'd like to narrow.

GitHub Issue Number: N/A

What is the new behavior?

the original goal of this effort was to remove the any type on jest-apt.ts's JestTestRunner type. doing so revealed a handful of subtle errors in the implementation of the jest runner for stencil.

  1. jest-facade.ts#getCreateJestTestRunner was incorrectly typed. technically this was correct in that it returned any, which can be a function. however, we were not explicit/clear that this was a function being returned in the JSDoc.
  2. jest-runner.ts#createTestRunner was incorrectly typed. Again, this was technically correct in that it used any, but it was unclear that an anonymous class was returned by this function.
  3. The anonymous class that is returned by createTestRunner for Jest 28/29 was incorrectly typed. the dynamic import of jest-runner from Jest was typed as any, which caused the overrides of runTests to be improperly typed. in fact, it revealed we were not passing arguments correctly to the parent class.

by removing the dynamic import within the jest-runner.ts implementations for each respective version of jest, stencil's bundler (for the compiler itself) began to pull in additional files to the bundle that it wasn't able to process. Jest's jest-runner module was already being dynamically imported, and was deemed to externalize in stencil's testing bundle.

Does this introduce a breaking change?

  • Yes
  • No

Testing

First, build the project with this branch:

./src/testing/jest/install-dependencies.sh && npm ci && npm run clean && npm run build && npm pack

Then install it in the output of creating a new stencil component library:

cd /tmp \
&& npm init stencil@latest component jest-test \
&& cd $_ \
&& npm i [PATH_TO_STENCIL]

Run tests for all versions of Jest:

npm i jest@24 jest-cli@24 @types/jest@24 && npm t -- --no-cache && \
npm i jest@25 jest-cli@25 @types/jest@25 && npm t -- --no-cache && \
npm i jest@26 jest-cli@26 @types/jest@26 && npm t -- --no-cache && \
npm i jest@27 jest-cli@27 @types/jest@27 && npm t -- --no-cache && \
npm i jest@28 jest-cli@28 @types/jest@28 && npm t -- --no-cache && \
npm i jest@29 jest-cli@29 @types/jest@29 && npm t -- --no-cache

Other information

STENCIL-960: Narrow Jest Runner Type

Copy link
Contributor

github-actions bot commented Nov 13, 2023

--strictNullChecks error report

Typechecking with --strictNullChecks resulted in 1368 errors on this branch.

That's the same number of errors on main, so at least we're not creating new ones!

reports and statistics

Our most error-prone files
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 23
src/compiler/style/test/optimize-css.spec.ts 23
src/testing/puppeteer/puppeteer-element.ts 23
src/compiler/output-targets/dist-lazy/generate-lazy-module.ts 22
src/compiler/prerender/prerender-main.ts 22
src/runtime/client-hydrate.ts 19
src/screenshot/connector-base.ts 19
src/runtime/vdom/vdom-render.ts 18
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 404
TS2322 384
TS18048 310
TS18047 100
TS2722 38
TS2532 34
TS2531 23
TS2454 14
TS2352 13
TS2769 10
TS2790 10
TS2538 8
TS2416 6
TS2344 5
TS2493 3
TS2488 2
TS18046 2
TS2684 1
TS2430 1

Unused exports report

There are 14 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 145 CUSTOM
src/utils/index.ts 269 normalize
src/utils/index.ts 7 escapeRegExpSpecialCharacters
src/compiler/app-core/app-data.ts 25 BUILD
src/compiler/app-core/app-data.ts 115 Env
src/compiler/app-core/app-data.ts 117 NAMESPACE
src/compiler/fs-watch/fs-watch-rebuild.ts 123 updateCacheFromRebuild
src/compiler/types/validate-primary-package-output-target.ts 61 satisfies
src/compiler/types/validate-primary-package-output-target.ts 61 Record
src/testing/puppeteer/puppeteer-declarations.ts 485 WaitForEventOptions
src/compiler/sys/fetch/write-fetch-success.ts 7 writeFetchSuccessSync

@rwaskiewicz
Copy link
Contributor Author

Ah - so CI (steps) pass locally for me, but not in the actual env. I know what the problem is - looks like I'll have to work on/land STENCIL-994 to ensure that node_modules/ are set up properly (currently, type checking is failing because jest-* specific node_modules aren't setup in CI, so the types are resolving to the root level node_modules, which only has Jest 27)

@rwaskiewicz rwaskiewicz force-pushed the rwaskiewicz/jest/test-runner-type-narrow branch 2 times, most recently from dcd44a6 to ae546ef Compare November 13, 2023 20:20
@rwaskiewicz rwaskiewicz changed the base branch from main to rwaskiewicz/jest/install-deps November 13, 2023 20:20
@rwaskiewicz rwaskiewicz marked this pull request as ready for review November 13, 2023 20:31
@rwaskiewicz rwaskiewicz requested a review from a team as a code owner November 13, 2023 20:31
@rwaskiewicz rwaskiewicz requested review from alicewriteswrongs and tanner-reits and removed request for a team November 13, 2023 20:31
Copy link
Contributor

@tanner-reits tanner-reits left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran through the test steps and things are working 👍 Not sure where it's saying the SNCs are coming from (didn't see any locally 🤷‍♂️ ).

Side note: thoughts on adding a script to the root package.json for running the jest deps script?

@rwaskiewicz rwaskiewicz force-pushed the rwaskiewicz/jest/install-deps branch from 4297a31 to e058d02 Compare November 15, 2023 15:27
Base automatically changed from rwaskiewicz/jest/install-deps to main November 15, 2023 15:55
the original goal of this effort was to remove the `any` type on
`jest-apt.ts`'s `JestTestRunner` type. doing so revealed a handful of
subtle errors in the implementation of the jest runner for stencil.

1. `jest-facade.ts#getCreateJestTestRunner` was incorrectly typed.
   _technically_ this was correct in that it returned `any`, which can
   be a function. however, we were not explicit/clear that this was a
   function being returned in the JSDoc.
2. `jest-runner.ts#createTestRunner` was incorrectly typed.
   Again, this was _technically_ correct in that it used `any`, but it
   was unclear that an anonymous class was returned by this function.
3. The anonymous class that is returned by `createTestRunner` for Jest
   28/29 was incorrectly typed. the dynamic import of `jest-runner`
   from Jest was typed as `any`, which caused the overrides of
   `runTests` to be improperly typed. in fact, it revealed we were not
   passing arguments correctly to the parent class.

by removing the dynamic import within the `jest-runner.ts`
implementations for each respective version of jest, stencil's bundler
(for the compiler itself) began to pull in additional files to the
bundle that it wasn't able to process. Jest's `jest-runner` module was
already being dynamically imported, and was deemed to externalize in
stencil's testing bundle.

STENCIL-960: Narrow Jest Runner Type
@rwaskiewicz rwaskiewicz force-pushed the rwaskiewicz/jest/test-runner-type-narrow branch from a605aec to 4119ddc Compare November 15, 2023 15:58
rwaskiewicz added a commit that referenced this pull request Nov 15, 2023
add an `install.jest` script to `package.json` to make it easier to
install jest dependencies within the project. the motivator for this
change is the following suggestion in a pull request that was a child PR
of the one that implemented this functionality -
#5068 (review)
@rwaskiewicz
Copy link
Contributor Author

@tanner-reits

Side note: thoughts on adding a script to the root package.json for running the jest deps script?

I'm gonna open a separate PR for this - I added the install-dependencies.sh script in the parent PR, and didn't see this comment until after I merged the parent. I want to keep that work separate from this type-based work, hence the separate PR

rwaskiewicz added a commit that referenced this pull request Nov 15, 2023
add an `install.jest` script to `package.json` to make it easier to
install jest dependencies within the project. the motivator for this
change is the following suggestion in a pull request that was a child PR
of the one that implemented this functionality -
#5068 (review)
rwaskiewicz added a commit that referenced this pull request Nov 15, 2023
add an `install.jest` script to `package.json` to make it easier to
install jest dependencies within the project. the motivator for this
change is the following suggestion in a pull request that was a child PR
of the one that implemented this functionality -
#5068 (review)
github-merge-queue bot pushed a commit that referenced this pull request Nov 15, 2023
add an `install.jest` script to `package.json` to make it easier to
install jest dependencies within the project. the motivator for this
change is the following suggestion in a pull request that was a child PR
of the one that implemented this functionality -
#5068 (review)
Copy link
Contributor

@alicewriteswrongs alicewriteswrongs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@rwaskiewicz rwaskiewicz added this pull request to the merge queue Nov 16, 2023
Merged via the queue into main with commit 5c4ac32 Nov 16, 2023
@rwaskiewicz rwaskiewicz deleted the rwaskiewicz/jest/test-runner-type-narrow branch November 16, 2023 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants