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

Pass testEnvironmentOptions as part of globalConfig to globalSetup and globalTeardown. #9930

Closed
mctrafik opened this issue Apr 30, 2020 · 12 comments

Comments

@mctrafik
Copy link

🚀 Feature Proposal

I would like to be able to reference testEnvironmentOptions inside of scripts passed in to globalSetup (and teardown).

Motivation

I am writing a custom environment.

I have some global setup that I would like to do like:

  • Start chromedriver service that I want to run for ALL test suites.
  • Clear out the log directory from previous runs.

I want the parameters like

  • Which port to run the driver on
  • What the log directory is
    to be defined in the jest.config.js. They are already defined there for me as part of my testEnvironmentOptions for my webdriver test environment.
    But the scripts in globalSetup and globalTeardown don't have access to it.

Example

See motivation.

Pitch

This is the simplest change I can think of to accomplish what I need. I want to publish my jest-webdriver-environment, but right now I get around the limitation stated above by making fake projects that contain the flags I want to pass, since projects properties are considered part of the globalConfig.

Thank you for considering this.

@Rendez
Copy link

Rendez commented Mar 9, 2021

+1

@izaakschroeder
Copy link

+1

@github-actions
Copy link

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Apr 21, 2022
@mctrafik
Copy link
Author

+1. Would still like to have this feature. Need to write another environment soon and this is still an issue.

@github-actions github-actions bot removed the Stale label Apr 22, 2022
@SimenB
Copy link
Member

SimenB commented Apr 22, 2022

If you can send a PR I'd be happy to land it 👍

It doesn't always make sense though, and in Jest 28 people can add testEnvironmentOptions per test file, which the global setup would never know about

@mrazauskas
Copy link
Contributor

Hm... Do I miss something? Not a case with Jest 27, but as per docs jest@next is passing globalConfig and projectConfig to setup / teardown scripts. So:

// setup.js

module.exports = async function (globalConfig, projectConfig) {
  console.log(projectConfig.testEnvironmentOptions); // It is here? Or do I miss something?
};

@SimenB
Copy link
Member

SimenB commented Apr 22, 2022

Hah, might be! 😅 Jest 28 is stock full of features

@ahnpnl
Copy link
Contributor

ahnpnl commented May 2, 2022

Is there a way we can allow Jest eco adopters to add something to globalConfig? I need that to work on this POC thymikee/jest-preset-angular#1434

@SimenB
Copy link
Member

SimenB commented May 2, 2022

What is "something"? To add to global config, just use a preset. But you want to do something more?

@ahnpnl
Copy link
Contributor

ahnpnl commented May 2, 2022

For my case, there are a few options to use at root level which globalSetup can read. Currently in my POC I'm doing this

globalThis.ngJest = {
  skipNgcc: false,
  experimentalPrecompilation: true,
  tsconfig: 'tsconfig-esm.spec.json',
};

These options are only at root level which I can use to process stuffs before my custom transformer kicks in, see example at https://github.com/thymikee/jest-preset-angular/pull/1434/files#diff-362b3ce4fcd1ed90a581c4d383217c2aa6f5d88d6117a77d995becc239486b07R8

Currently, the option globals (project config) works but not 100% working because when using with projects, specifying globals don't give any effects.

@SimenB
Copy link
Member

SimenB commented May 2, 2022

I still don't fully understand, but it seems separate from what this PR asks for (which is already implemented). Could you open up a new feature request?


That said, we should have called globalSetup with an array of project configs, not just one. Might need to fix that in Jest 29.


Closing since projectConfig is available today

@SimenB SimenB closed this as completed May 2, 2022
@github-actions
Copy link

github-actions bot commented Jun 2, 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.

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

No branches or pull requests

6 participants