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

How to set the environment variable in test? #10

Open
xuniaoji opened this issue Jan 10, 2021 · 2 comments
Open

How to set the environment variable in test? #10

xuniaoji opened this issue Jan 10, 2021 · 2 comments

Comments

@xuniaoji
Copy link

I have an env variable APP_KEY which should come from Alfred workflow, but what should we do in the test? Could I set that in the test?

I tried:

  1. assign process.env.APP_KEY = '14444444' in test file, but when running test, the index.js couldn't recognize it.
  2. in package.json scripts: test: export APP_KEY='9840c89040f56003' && ava, still couldn't get it.

Thanks!

@xuniaoji
Copy link
Author

temporarily, I modify your package. In env.js file, I add the environment variable and it works.
image

@jcyamo
Copy link

jcyamo commented May 12, 2022

Since you're using https://github.com/avajs/ava you should be able to use the environmentVariables config option.

For example, in your package.json

"ava": {
	"environmentVariables": {
		"APP_KEY": "14444444"
	}
}

Then in your test you can simply reference that from process.env.APP_KEY.

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

No branches or pull requests

2 participants