24 configuration - ranhs/soda-test GitHub Wiki

In some cases you need to defined at design time, to avoid from code to running when loaded, or to allow test to do actions that cannot be done after the files were loaded.
Soda-test allows you create a configuration file to define those settings.

configuration file location

The configuration files should be located at same folder as your package.json file. The same folder were the node_modles folder is created under it.
The name of the configuration file is .soda-test (with no suffix)

Configuration File Format

The soda-test configuration file is a JSON file that include a single object. The supported content of the object is described in the next sections. Note that if you don't define a configuration file a warning shall be issue at the start of the test execution, but execution shall continue without configuration. If you misplaced the configuration file you will see the warning that no configuration file was found, including the expected location and name of the configuration file.

Environment Variables

To define environment variables during the test execution (including the load of the test and code files) you can define in the configuration file a property named env that has a value of an object. Each property of that object has the key of a name of an environment variable, and a string value that is the value for that environment.

{
   "env": {
      "SODAENV": "GOOD"   
   }
}

In the above example an environment variable named SODAENV shall be defined with the value of GOOD during test runtime.

Rewire

To customize the behavior of the rewire feature, you may define in the configuration file a property named rewire that its value is an object with properties as follow:

files

To define spatial rewire behavior for specific files, define in the rewire property object a property named files that is value is an object. each property key of that object is the path + name of the file you want to customize its behavior. The property key name does not include the file suffix (js or ts). The value of such a property is an object with definitions about a rewire behavior of that specific file. Note that if such file does not exist, the setting shall be ignored. The following are the supported properties for a rewire file setting object:

insertVars

You may need to create variables inside a module file. To do that define a property named insertVars in the rewire file configuration object. The value of the insertVars property is an array, that each item represent a variable to add to the file. The value of an item in the array is an object with property name that is the name of the variable to add. Note that in current version that variable is not initialized and has the undefined value. You can use the rewire set method to change the value of that variable.

{
   "rewire": {
      "files": {
          "lib/config": {
             "insertVars': [
                {
                   "name": "kuku"
                },
                {
                   "name": "foo"
                }
             ]
          }
      }
   }
}

In the above example rewire shall add 2 varibles to the config.js (or config.ts) file that is under the lib folder. The added variables are kuku and foo.

⚠️ **GitHub.com Fallback** ⚠️