Azure function(javascript) - read local.settings.json property during testing #475
-
During the development time, i can use "process.env[propertyName]" to access the property value inside the local.settings.json file fine. Then i install Jest framework to do the unit testing, i just realised my function app failed to read any values from local.setting.json, or it actually running different environment during development and unit test(i print out the all the value from process.env object during unit testing and development and compared, they are quite different.) Q1 Cheers |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Transferring this issue to core tools for further insights. |
Beta Was this translation helpful? Give feedback.
-
Hi @jason-mwnz the "local.settings.json" file is only used when running locally with the func core tools cli. For any other scenario, including unit tests, it will not be used. One reason is that the file should not be tracked in git because it may contain secrets, meaning it will not be useable in CI. If you can describe how you run your tests locally (from VS Code, the CLI) and/or from CI (Azure Pipelines, GitHub Actions, etc.) I might be able to help give a solution We have #120 to track better docs on testing practices and otherwise I thought I'd try converting this to a "discussion" (never tried this before) since there won't be any action item on our side |
Beta Was this translation helpful? Give feedback.
Hi @jason-mwnz the "local.settings.json" file is only used when running locally with the func core tools cli. For any other scenario, including unit tests, it will not be used. One reason is that the file should not be tracked in git because it may contain secrets, meaning it will not be useable in CI. If you can describe how you run your tests locally (from VS Code, the CLI) and/or from CI (Azure Pipelines, GitHub Actions, etc.) I might be able to help give a solution
We have #120 to track better docs on testing practices and otherwise I thought I'd try converting this to a "discussion" (never tried this before) since there won't be any action item on our side