Test environment variables depending on configuration mode

Issue

I have 5 environment files:

environment.common.ts
environment.a.ts
environment.b.ts
environment.c.ts
environment.ts

I have modified my angular.json to this:

...
"projects": {
   "app": {
     ...
     "architect": {
        "build": {
           ...
           "configurations": {
              "a": {
                 "fileReplacements": [
                    {
                       "replace": "src/environments/environment.ts",
                       "with": "src/environments/environment.a.ts"
                    }
                 ],
                 ...
              },
              // same for b and c
           }
        }
     }
   }
}
// plus all the other needed configurations which are irelevant with the question

When i run ionic cordova build android --configuration a the app uses the environment variables from environment.common.ts plus the ones from environment.a.ts

QUESTION

Is there any way to ng test if the corrent environment variables are called when I run ionic cordova build android --configuration a

Solution

If you want to check the environment variables being used when you run ng test with configuration flag, that’s not possible. But in case you want to run your test scripts with a particular environment variables then you could definitely do that. ng test --configuration is use to run spec files with particular set of environment variables. Hope it answers your query.

Answered By – Mir entafaz Ali

Leave a Comment