diff --git a/src/helpers/helper.js b/src/helpers/helper.js index b632841..3b8bcfc 100644 --- a/src/helpers/helper.js +++ b/src/helpers/helper.js @@ -14,18 +14,11 @@ function getPercentage(x, y) { function processText(raw) { const dataRefMatches = raw.match(DATA_REF_PATTERN); if (dataRefMatches) { - const values = []; for (let i = 0; i < dataRefMatches.length; i++) { const dataRefMatch = dataRefMatches[i]; const content = dataRefMatch.slice(1, -1); - if (process.env[content]) { - values.push(process.env[content]); - } else { - values.push(content); - } - } - for (let i = 0; i < dataRefMatches.length; i++) { - raw = raw.replace(dataRefMatches[i], values[i]); + const envValue = process.env[content] || content; + raw = raw.replace(dataRefMatch, envValue); } } return raw; diff --git a/test/config.spec.js b/test/config.spec.js index 192cfcd..8ed25e4 100644 --- a/test/config.spec.js +++ b/test/config.spec.js @@ -1,8 +1,37 @@ const assert = require('assert'); +const { mock } = require('pactum'); const { publish } = require("../src"); describe('Config', () => { + it('should allow valid config with ENV vars - successful', async () => { + const id = mock.addInteraction('post test-summary to teams'); + process.env.TEST_URL='http://localhost:9393/message' + await publish({ + config: { + "targets": [ + { + "name": "teams", + "condition": "result.status === 'PASS'", + "inputs": { + "url": "{TEST_URL}" + } + } + ], + "results": [ + { + "type": "testng", + "files": [ + "test/data/testng/single-suite.xml" + ] + } + ] + } + }); + process.env.TEST_URL='' + assert.equal(mock.getInteraction(id).exercised, true); + }); + it('should not allow missing options', async () => { let e; try {