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 support for Test / envVars

See original GitHub issue

This may be out of scope for an issue, as there may be a workaround that I’m not aware of.

I want to set environment variables in tests:

Test / envVars := Map(
  "MY_TEST" -> "true",
)

Which are then accessible via:

global.process.env.selectDynamic("MY_TEST").asInstanceOf[js.UndefOr[String]]

For the JVM this works in tandem with Test / fork := true, however it seems that this is an option that is banned on top of Scala.js:

[error] `test / test` tasks in a Scala.js project require `test / fork := false`.

I’m guessing this happens because Scala.js has to fork a process anyway, but it appears that the forking ignores the envVars setting. Would be great if it didn’t.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
gzm0commented, Sep 6, 2022

I have started on this, but likely will not have time any time soon. So feel free to take it over.

0reactions
sjrdcommented, Sep 5, 2022

@gzm0 Do you still want to do the sbt plugin side of this feature, now that the JSEnv side is done? Or would you prefer that I do it?

I still have a PR to actually (finally) separate the javalib in its own jar in progress, but otherwise I think we’ll be done for 1.11.0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Testing and Environment Variables - Thoughtbot
Learn how to test code using data in environment variables with Climate Control.
Read more >
How to test code dependent on environment variables using ...
We can set Environment Variables or System Properties through Maven POM file which I think best way to do Unit Testing for Maven...
Read more >
How to use environment variables in test scripts via the API?
You can use environment variables to: Decide which URL to use (when launching tests on heroku machines for example); Pick specific room id's...
Read more >
Can't access ENV vars defined in .env.test #16270 - GitHub
I have added an .env.test file to an app based on the environment variable starter, containing one variable TEST_ENV_VARIABLE.
Read more >
Dealing with Environment Variables while running Unit Tests
When you create a unit test, you are creating the first consumer of the code under development Environment variables in Cloud Functions is...
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