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

feat(test): jest 27 support #3189

Merged
merged 4 commits into from
Jan 4, 2022
Merged

feat(test): jest 27 support #3189

merged 4 commits into from
Jan 4, 2022

Conversation

rwaskiewicz
Copy link
Member

@rwaskiewicz rwaskiewicz commented Dec 15, 2021

Pull request checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)
  • Build (npm run build) was run locally and any changes were pushed
  • Unit tests (npm test) were run locally and passed
  • E2E Tests (npm run test.karma.prod) were run locally and passed
  • Prettier (npm run prettier) was run locally and passed

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

Jest 27 is not supported due to an issue when trying to reach into a private jest-cli package. This commit provides a fix for that aspect of Jest 27 support (and gets us most of the way there)

GitHub Issue Number: see 'other information' section below

What is the new behavior?

this commit restores running the npm test command as a part of the
root level package.json's test.end-to-end script (and readds it to
CI).

this commit provides support for jest 27 in stencil. this is
accomplished by no longer pulling default options from the jest-cli
package, which now encapsulates its contents through an exports field
in its package.json file. during the course of this work, it was
discovered the same fields/defaults were used with Jest 24, 25, & 26.
Those options have been pulled out into a helper function to be provided
for Jest v24 thru 27 to ensure a consistent experience. this helper will
be removed in a future version of Stencil.

the test runner for consumers is locked to jest-jasmine2 for backwards
compatibility in this commit.

jest-runner exposes its default export differently in jest 27. the
creation of a stencil test runner has been updated to handle the
differences between jest v27 and v26 (and under).

jest, jest-cli, jest-environment-node were all updated to the latest
patch version to test with the latest and greatest versions of the
libraries.

Does this introduce a breaking change?

  • Yes
  • No

Testing

With this branch, I ran:
npm clean && npm i -D jest@27 jest-cli@27 jest-environment-node@27 && npm ci && npm run build && npm run test.end-to-end to run the end to end tests, which simulate a small application running spec tests with the version of Jest installed (we pull from Stencil's installed version of Jest/that's why the end to end tests were temporarily removed).

I then ran that command above for each major version of Jest we support today [24, 25, 26].

I ran the karma tests locally as one last check before moving on.

Next, I ran git reset --hard && npm clean && npm ci && npm run build && pack to generate a tarball for this branch. With the Stencil CLI (npm init stencil -> choose 'component') I spun up a new component library, & installed the tarball. For each version of Jest [24, 25, 26, 27] I ran npm i -D jest@VER jest-cli@VER && npm t -- --no-cache to verify this worked in the real world (or at least on a small, sample representation)

Finally, I installed my tarball in a local copy of Ionic Framework Core, then updated Jest:

npm i -D jest@latest jest-cli@latest @types/jest@latest @jest/core@latest

And was able to run the tests to completion in Ionic Framework Core:

npm run clean && npm run build && npm t

Other information

This PR supersedes:

This PR fixes:

this commit restores running the `npm test` command as a part of the
root level package.json's `test.end-to-end` script (and readds it to
CI).

this commit provides support for jest 27 in stencil. this is
accomplished by no longer pulling default options from the jest-cli
package, which now encapsulates its contents through an `exports` field
in its package.json file. during the course of this work, it was
discovered the same fields/defaults were used with Jest 24, 25, & 26.
Those options have been pulled out into a helper function to be provided
for Jest v24 thru 27 to ensure a consistent experience. this helper will
be removed in a future version of Stencil.

the test runner for consumers is locked to jest-jasmine2 for backwards
compatability in this commit.

jest-runner exposes its default export differently in jest 27. the
creation of a stencil test runner has been updated to handle the
differences between jest v27 and v26 (and under).

jest, jest-cli, jest-environment-node were all updated to the latest
patch version to test with the latest and greatest versions of the
libraries.
update minimum required version for consumers to v27
@@ -6,12 +6,12 @@ import path from 'path';

describe('jest-config', () => {
it('pass --maxWorkers=2 arg when --max-workers=2', () => {
const args = ['test', '--ci', '--e2e', '--max-workers=2'];
const args = ['test', '--ci', '--max-workers=2'];
Copy link
Member Author

Choose a reason for hiding this comment

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

This test was exactly the same as the one below it. I'm guessing this is copy/pasta, but could be wrong. The test name differentiation suggests this shouldn't run with the --e2e flag. I can pull this into a separate commit if desired

@rwaskiewicz rwaskiewicz marked this pull request as ready for review December 16, 2021 19:09
@rwaskiewicz rwaskiewicz requested a review from a team December 16, 2021 19:09
This was referenced Dec 16, 2021
@igorlino
Copy link

Thank you !!!

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.

None yet

3 participants