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

nconf values are undefined when a module is rewire #212

Open
chavan-gopal opened this issue Dec 29, 2023 · 0 comments
Open

nconf values are undefined when a module is rewire #212

chavan-gopal opened this issue Dec 29, 2023 · 0 comments

Comments

@chavan-gopal
Copy link

I have the following situation and wanted to understand what would be the best way to handle it.
So in my project I am using nconf for managing configuration settings in applications. and for running test-cases I set nconf with test.json file which have all configuration variables(like PORT, DB_HOST, S3_BUCKET_URL etc)

const nconf = require('nconf').argv().env()
nconf.file({file: path_to_test.json})

and following is the module which I wan to rewire in my test-case
module.js

const nconf = require('nconf')
...
// I have added below code for simplicity
if(!nconf.get('port')){
throw error('error')
}
...

in my test-case I am rewiring a module(this module also makes use of nconf)
test-case.js

const nconf = require('nconf') // here I could access all env vars PORT, DB_HOST etc
const rewire = require('rewire')
const myModule = rewire('path_to_module') // here I would get error and test-execution stop's here
// because nconf.get('port') is undefined

How can I resolve this issue, so nconf retains its value when rewiring the module

@chavan-gopal chavan-gopal changed the title nconf values are undefined when module is rewire nconf values are undefined when a module is rewire Dec 29, 2023
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

1 participant