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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge preset globals with jest.config.js globals #9026

Closed
jdpearce opened this issue Oct 8, 2019 · 1 comment 路 Fixed by #9027
Closed

Merge preset globals with jest.config.js globals #9026

jdpearce opened this issue Oct 8, 2019 · 1 comment 路 Fixed by #9027

Comments

@jdpearce
Copy link
Contributor

jdpearce commented Oct 8, 2019

馃殌 Feature Proposal

Merge the globals property from any preset into the project configuration rather than overwriting it.

Motivation

Some third party libraries (e.g. ts-jest) use the globals property to provide configuration. It would be useful to be able to provide shared configuration and only override certain fields within the globals.

Example

The preset could look something like this :

module.exports = {
  globals: {
    'ts-jest': {
      stringifyContentPathRegex: '\\.html$',
      astTransformers: [
        require.resolve('jest-preset-angular/InlineHtmlStripStylesTransformer')
      ],
      isolatedModules: true
    }
  }
}

And the project config could simply contain the following :

module.exports = {
  globals: {
    'ts-jest': {
      tsConfig: './tsconfig.spec.json',
    }
  }
}

(Or similar)

This would result in an options object which contained :

  globals: {
    'ts-jest': {
      tsConfig: './tsconfig.spec.json',
      stringifyContentPathRegex: '\\.html$',
      astTransformers: [
        require.resolve('jest-preset-angular/InlineHtmlStripStylesTransformer')
      ],
      isolatedModules: true
    }
  }

This isn't limited to the configuration of third party libraries, but this may be the most obvious use case. A simple repro repo that illustrates how globals currently gets clobbered is available at https://github.com/jdpearce/jest-globals-test

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant