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.

[Feature]: Allow `globalSetup` to access things in `globals`

See original GitHub issue

🚀 Feature Proposal

Include globals in global config so that globalSetup or globalTeardown can use it.

Motivation

I notice that Jest has globals, but it isn’t included in global config. When I look at name globals, I was thinking about it would be included in global config. So it would match with things related to “global”.

I have a use case https://github.com/thymikee/jest-preset-angular/issues/1348 which if Jest allows globals to be in global config, it will look beautiful.

Example

Define in Jest config

// jest.config.js
//...
globals: {
      'ngcc': { project: 'tsconfig.spec.json' },
}

In a globalSetup script

import type { Config } from '@jest/types';

export = async (globalConfig: Config.GlobalConfig) => {
      console.log(globalConfig.globals);
}

Pitch

This would be a change in Jest config. I think it should be in core.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
SimenBcommented, Feb 20, 2022
0reactions
github-actions[bot]commented, Mar 24, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest Global Setup - Part 10 - YouTube
Learn how to create a global setup when testing with Jest.
Read more >
Globals - Jest
Globals. In your test files, Jest puts each of these methods and objects into the global environment. You don't have to require or...
Read more >
Getting Jest global setup and global teardown to work in a ...
I want to run a function that opens db connection before running tests (global setup) and another function that closes db connection after ......
Read more >
Jest Globals - w3resource
The only thing you need in a test file is the test method which will run a test. For instance, let's say there...
Read more >
Globals · Jest
This is often useful if you want to clean up some global setup state that ... let globalDatabase = makeGlobalDatabase(); function cleanUpDatabase(db) {...
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