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

Load jest-puppeteer.config.js from <rootDir> #160

Closed
donaldpipowitch opened this issue Nov 28, 2018 · 9 comments
Closed

Load jest-puppeteer.config.js from <rootDir> #160

donaldpipowitch opened this issue Nov 28, 2018 · 9 comments

Comments

@donaldpipowitch
Copy link

🚀 Feature Proposal

When I place my Jest config in a sub-directory my tests actually have a new <rootDir>, but the jest-puppeteer.config.js is still loaded from the root of my project.

- jest-puppeteer.config.js
- tests/jest.config.js

$ jest --config tests/jest.config.js

It would be nice however, if I could do this by default.

- tests/jest-puppeteer.config.js
- tests/jest.config.js

$ jest --config tests/jest.config.js

Motivation

IMHO it is more natural to respect the <rootDir> of Jest and easier to learn/to "do right". Currently I can set JEST_PUPPETEER_CONFIG, but this is something I need to look up and it is also less "shareable".

An alternative to get rid of JEST_PUPPETEER_CONFIG in the case you don't wan't to respect <rootDir> by default would be to make it configurable similar to how ts-jest handles the tsconfig.json:

module.exports = {
  globals: {
    'jest-puppeteer': {
      config: '<rootDir>/jest-puppeteer.config.js'
    }
  }
};

That is still something I need to look up, but at least it is easier to share and I can use <rootDir>.

Example

If you don't place your Jest configs in sub-directories everything still works like usual:

- jest-puppeteer.config.js
- jest.config.js

$ jest

If you do place your Jest configs in sub-directories, you can place the corresponding jest-puppeteer.config.js in the same directory without the need to add custom environment variables.

- tests/jest-puppeteer.config.js
- tests/jest.config.js

$ jest --config tests/jest.config.js

Pitch

Why does this feature belong in the SVGR ecosystem?

What is the SVGR ecosystem?

@gregberge
Copy link
Member

Hello @donaldpipowitch, originally I would like to get rid of jest-puppeteer.config.js (see #111).

It is actually blocked because a part of config is not avalaible in global hooks.

Maybe using globals entry could solve the problem, could you give a deeper look? If we could remove this file it would be great.

If we can’t I don’t want to invest more effort on it, I prefer to submit some changes in Jest to be able to get rid of it.

@donaldpipowitch
Copy link
Author

could you give a deeper look?

Do you have specific questions? :) I only know this from ts-jest to be honest.

@gregberge
Copy link
Member

I just gave a look, globals are not exposed in globalConfig, the only config available in globalSetup and globalTeardown. So actually it is not possible to use it (https://github.com/facebook/jest/blob/master/packages/jest-config/src/index.js#L102).

We are stuck :(

@donaldpipowitch
Copy link
Author

I see :(

@DavidBabel
Copy link

DavidBabel commented May 13, 2019

Any information of this proposal ? Or is there any way to include this config in jest config, or in package.json ?

I face the same problem.

@Macil
Copy link

Macil commented May 13, 2019

Right now, you can make jest-puppeteer load jest-puppeteer.config.js from the same directory as jest.config.js by putting this in your jest.config.js:

process.env.JEST_PUPPETEER_CONFIG = require.resolve('./jest-puppeteer.config.js');

(I'd love it if this wasn't necessary and was the default behavior.)

@DavidBabel
Copy link

Thanks @Macil , it's still a good workaround

@thernstig
Copy link

thernstig commented Nov 19, 2019

@gregberge https://github.com/smooth-code/jest-puppeteer#jest-puppeteerconfigjs specifically says:

You can specify a jest-puppeteer.config.js at the root of the project

Considering "root" is often used as "rootDir" in Jest config and also if you use the 'projects' property, it would be nice to at least use in the code where it is called.

I understand you might want to get rid of jest-puppeteer.config.js but as the issue was submitted a year ago, maybe this could be considered anyway as it makes it more natural than using the env var?

@gregberge
Copy link
Member

Stale, feel free to open a new issue if you have this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants