Add current test file path in process.env
See original GitHub issue🚀 Feature Proposal
Absolute path to currently running test file in process.env
Motivation
When there are different “groups” of test files (e.g., usage in different environments or module systems), sometimes the difference between the groups is too minor to have an entirely separate Jest configuration file, separate run command etc. In this case, when having a simple if..else
clause in setup files would be ideal, there is nothing to distinguish one setup from another.
Example
{
"setupFiles": [
"<rootDir>/test/setup.js"
]
}
// test/setup.js
console.log(process.env.JEST_TEST_FILE_PATH); // identifier is up to dispute
$ jest
● Console
console.log test/setup.js:1
/path/to/project/test/my-entity.spec.ts
Pitch
Not sure what’s that
Issue Analytics
- State:
- Created 3 years ago
- Comments:9
Top Results From Across the Web
Test process.env with Jest - node.js - Stack Overflow
Another option is to add it to the jest.config.js file after the module.exports ... test("Some test name", () => { expect(process.env.
Read more >Working with Environment Variables in Node.js - Twilio
Environment variables are a great way to configure parts of your Node.js application. Learn how to work with them using helpful tools such ......
Read more >Node Environment Variables: Process env Node
Node environment variables are strategies to define and consume environment-specific configurations and process env node. Learn how.
Read more >process.env: What it is and why/when/how to use it effectively
The process.env global variable is injected by the Node at runtime for your application to use and it represents the state of the...
Read more >Customizing Node.js .env files - LogRocket Blog
Customizing Node.js .env files · The following code shows a simple Node. · Start by importing the http module: · We can attempt...
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
Ah right, missed that part of your use case.
Yeah, we ship a browser like (backed by JSDOM) and a node like environment, so if that’s all you need you should be good. in a setup file you can do something like
if (typeof window !== 'undefined') {
.Thanks for the PR regardless, even if it wasn’t merged! 👍
@SimenB, @jeysal I’m impressed, how friendly and helpful you guys are! Thank you very much 👏