Skip to content

Commit

Permalink
feat: Enable environment variable injection through configuration file
Browse files Browse the repository at this point in the history
  • Loading branch information
olivierodo committed Mar 22, 2023
1 parent 7c65cc7 commit 437485a
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/getting-started/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ tests:
port: 8887
command: npm run dev
coverage: ./coverage/index.html
envs:
FOO: 'BAR'
integrations:
- name: 'uat'
url: http://uat.example.com
Expand Down
3 changes: 3 additions & 0 deletions docs/local-testing/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Depending on the technology that you use, you can refer to our documentation:
| `tests.local.port` | number | The port exposing the microservice server | Yes | |
| `tests.local.command` | string | The command used to run the microservice | Yes | |
| `tests.local.coverage` | string | The path of the test generated coverage page (for custom coverage reporter ) | No | ./restqa/coverage/index.html |
| `tests.local.envs` | object | The environment variable that need be injected in the microservice | No | |

#### Example

Expand All @@ -57,4 +58,6 @@ tests:
local:
port: 8887
command: npm run dev
envs:
FOO: BAR
```
8 changes: 8 additions & 0 deletions packages/cli/src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,14 @@ class LocalTest {
this._config.command = command;
}

getEnvs() {
return this._config.envs || {};
}

setEnvs(value) {
this._config.envs = value;
}

getCoverage() {
return this._config.coverage;
}
Expand Down
3 changes: 3 additions & 0 deletions packages/cli/src/config/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ tests:
local:
port: 8080
command: npm run dev
envs:
FOO: BAR
integrations:
- name: UAT
url: !env-var URL
Expand Down Expand Up @@ -325,6 +327,7 @@ settings:
// local test
expect(Instance.getLocalTest().getPort()).toEqual(8080);
expect(Instance.getLocalTest().getCommand()).toEqual("npm run dev");
expect(Instance.getLocalTest().getEnvs()).toEqual({FOO: "BAR"});

// integration test
expect(Instance.getIntegrationTests()[0].getName()).toEqual("UAT");
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/config/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ function validate(config) {
port: Joi.number().port().required(),
command: Joi.string().required(),
coverage: Joi.string(),
data
data,
envs: Joi.object({}).unknown()
},
integrations: Joi.array().items(integration),
performance: {
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/core/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ module.exports = function ({env, report, config}, processor = {}) {
if (!env) {
processor.BeforeAll(async function () {
this.restqa = this.restqa || {};
const {envs} = this.restqa.mock || {};
let {envs} = this.restqa.mock || {};
envs = Object.assign(envs || {}, config.getLocalTest().getEnvs());
const options = {
port: config.getLocalTest().getPort(),
command: config.getLocalTest().getCommand(),
Expand Down

0 comments on commit 437485a

Please sign in to comment.