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: support Jest 29 #1901

Closed
wants to merge 1 commit into from
Closed

feat: support Jest 29 #1901

wants to merge 1 commit into from

Conversation

Tommy228
Copy link

@Tommy228 Tommy228 commented Jan 7, 2023

Summary

This PR is my attempt at addressing #1774 and supporting Jest 29.

This migrates all ts-jest configs under globals, which is deprecated, to transformers config.

It also exposes a new defaultTransformerOptions object to allow overriding the default transformer more easily.

const { defaultTransformerOptions } = require('jest-preset-angular/presets');

Test plan

I linked it to one of my biggest projects running Angular 15 with 3000+ unit tests. The tests have passed with no warning.

Does this PR introduce a breaking change?

  • Yes

Overriding the config via globals may not work:

module.exports = {
  globals: {
    'ts-jest': {
      tsconfig: '<rootDir>/src/tsconfig.spec.json',
    },
  },
};

Because the preset now provides the config via the transformer, the default configuration (like tsconfig) takes precedence over the globals configuration.

Instead, this needs to be done (unless there is a better solution?):

const { defaultTransformerOptions } = require('jest-preset-angular/presets');

module.exports = {
  ...defaultConf,
  transform: {
    '^.+\\.(ts|js|mjs|html|svg)$': [
      'jest-preset-angular',
      {
        ...defaultTransformerOptions,
        tsconfig: '<rootDir>/src/tsconfig.spec.json',
      },
    ],
  },
};

Other information

Not sure if I did this right. I'm struggling to get NgJestTransformer unit tests to work. They are working individually but they fail when ran together. I think it has to do with some caching stuff behind TsJestTransformer.

@angular-builders/jest needs to be updated as well because it passes the tsconfig via globals, which does not work anymore.

Todo

  • Investigate failing TsJestTransformer tests
  • Upgrade ts-jest to include this patch
  • Create 13.x documentation (remove changes done to 12.x)
  • Update examples

Copy link
Collaborator

@ahnpnl ahnpnl left a comment

Choose a reason for hiding this comment

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

so far it's in good direction. Using Jest transform option like this is the correct way

CHANGELOG.md Outdated Show resolved Hide resolved
@Tommy228
Copy link
Author

Tommy228 commented Jan 7, 2023

Thanks for having a look!

After some debugging, I think I found what's causing my tests to fail in sequence.

It was indeed a caching issue on ts-jest side. TsJestTransformer uses the globals config as cache key before it is merged with the transform config. So the tests use the cached configuration, even if transform options have changed. I'll create a PR to fix this.

@Tommy228
Copy link
Author

Small update about the current status: I won't have time to continue working on this before the end of the week. But what's left to do (cf. the tasks):

  • Upgrade ts-jest to include this patch (but this requires a release of ts-jest)
  • Create a 13.x documentation (remove changes done to 12.x)
  • Update the examples under /examples to use transform
  • And of course, test that this didn't break anything

Help is welcome

@viceice
Copy link

viceice commented Jan 12, 2023

Migrated from `ts-jest` config under `globals`, which is deprecated, to transformers config
@kbrilla
Copy link

kbrilla commented Jan 26, 2023

@Tommy228 hey any updates on this? Is it ready for the second round of review maybe?

@ahnpnl
Copy link
Collaborator

ahnpnl commented Jan 27, 2023

done in #1937

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

4 participants