`--projects` flag uses process.env from top level dir, not each project.
See original GitHub issue🐛 Bug Report
--projects
flag uses process.env from top level dir, not each project. as a result, expected paths in process.env will not match runtime behavior of projects.
To Reproduce
Steps to reproduce the behavior:
Create a top level project with the following file:
module.exports = {
projects: [
'./child-project/jest.config.js'
],
};
Create a child project with the following file:
module.exports = {
name: 'child-project',
displayName: 'child-project,
rootDir: './',
testEnvironment: 'node',
modulePaths: [
'src',
'/node_modules/'
],
collectCoverageFrom : [
'src/**/*.js'
]
};
Expected behavior
process.env
should be recreated for each project with process.cwd()
set as rootDir
for that particular project.
Run npx envinfo --preset jest
npx: installed 1 in 2.154s
System:
OS: macOS High Sierra 10.13.2
CPU: x64 Intel(R) Core(TM) i7-7920HQ CPU @ 3.10GHz
Binaries:
Node: 9.11.1 - /usr/local/bin/node
npm: 5.6.0 - /usr/local/bin/npm
npmPackages:
jest: ^22.4.3 => 22.4.3
Issue Analytics
- State:
- Created 5 years ago
- Reactions:10
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Determine project root from a running node.js application
This returns the current working directory. Not reliable at all, as it's entirely dependent on what directory the process was launched from:
Read more >Using .env Files for Environment Variables in Python ...
env file is a text file containing key value pairs of all the environment variables required by your application. This file is included...
Read more >Configuring Jest
An alternative API to setting the NODE_PATH env variable, modulePaths is an array of absolute paths to additional locations to search when resolving...
Read more >Working with Environment Variables in Node.js - Twilio
With just a few lines of code, you can simply run a Node.js application straight from the terminal and use Twilio to send...
Read more >GitLab CI/CD variables
You can use the variables keyword in a job or at the top level of the ... To keep a CI/CD variable secret,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This has caught me off guard as well, I’ve prepared a simple repro showcasing the problem: https://github.com/Andarist/jest-projects-cwd-repro/blob/master/package.json#L12 This is basically the same thing which @unional describes.
I would expect projects to run independently of each other - each instance/project should be independent and run exactly~ the same way as it would when jest would be run inside a particular project.
IMHO this especially makes sense as the announcement post of this feature - https://jestjs.io/blog/2017/05/06/jest-20-delightful-testing-multi-project-runner#multi-project-runner-configuration-overhaul says something like:
This in my head implies that those listed projects (and their jest.config.js and relative paths in tests etc) don’t have to know at all about being possibly run through this feature and shouldn’t have to adjust their code to accommodate for this. It should “just work”.
Agree, usually when you start the tests inside a project, you do it at the project root, hence
process.cwd()
is set correctly.We were also caught off guard when we noticed that
process.cwd()
is not adjusted to match each project’s root.Would you consider merging a PR that addresses that? cc @cpojer