Skip to content

Commit

Permalink
Merge pull request #265 from test-results-reporter/optimize-helper-utils
Browse files Browse the repository at this point in the history
chore: optimise helpers extracting and processing ENV vars in config
  • Loading branch information
leelaprasadv authored Dec 19, 2024
2 parents 6d83302 + 4478d56 commit d88490a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
11 changes: 2 additions & 9 deletions src/helpers/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
29 changes: 29 additions & 0 deletions test/config.spec.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down

0 comments on commit d88490a

Please sign in to comment.