question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Change __TS_CONFIG__ from a global variable to a jest configuration

See original GitHub issue
  • Issue It seems silly TS_CONFIG should be a global variable, as the test code does not and should not care about it.

I suggest putting it into a jest configuration key instead e.g.

{
"jest" : {
"ts-jest": {
  "__TS_CONFIG__" : {
   
  },
}

This makes more sense, and will later streamline the process of adding more configurations as discussed in #213

This is however a breaking change, and will need deprecation warnings. I also think it would be prudent to support both ways of doing it for a few versions to make sure everyone is caught up. It will be very easy for the end users to migrate.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:32 (17 by maintainers)

github_iconTop GitHub Comments

3reactions
GeeWeecommented, May 30, 2017

Interesting. This is definitely something we should fix, but it doesn’t seem like it’s close enough to this issue to be discussed here. I’d love it if you started a new issue with a repo that reproduces the error.

2reactions
kulshekharcommented, Jul 6, 2017

@morajabi Thanks for picking this up 😃

or simply skip globals?

We can’t skip globals. Any non-standard jest configuration has to go in globals. The structure you’ve used looks fine. Although I’d like to split __TS_CONFIG into two distinct keys - tsconfigFile and tsConfig to make it clear. (this would require more changes, though) @GeeWee thoughts?

Sorry, What should I do with transpileIfTypescript function

There are two places that’ll need change to address this - util.ts and transpile-if-ts.ts

What I’d suggest is

  • create a function that retrieves the config setting
  • place a call to this function in the above two places

This function should:

  • currently, work with the present config format but display a warning on the console
  • work with the new config format

If you have any more questions at any stage feel free to post them here!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How use global variable in Jest and pass it through cmd
Use the global object (e.g global.value ) to access globals in the tests console.log(global.value);. Use the --globals parameter to override ...
Read more >
Configuring Jest
It is recommended to define the configuration in a dedicated JavaScript, TypeScript or JSON file. The file will be discovered automatically, ...
Read more >
Configuration | ts-jest - Huafu
ts-jest configuration is done within Jest configuration object. This latest can be in package.json under the jest property, or in its own jest.config.js...
Read more >
Configuring Jest - API Manual
A set of global variables that need to be available in all test environments. For example, the following would create a global __DEV__...
Read more >
Documentation - Global .d.ts - TypeScript
Many libraries simply expose one or more global variables for use. For example, if you were using jQuery, the $ variable can be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found