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.

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:closed
  • Created 3 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
SimenBcommented, Apr 27, 2020

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! 👍

1reaction
parzhitskycommented, Apr 27, 2020

@SimenB, @jeysal I’m impressed, how friendly and helpful you guys are! Thank you very much 👏

Read more comments on GitHub >

github_iconTop 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 >

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