Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: optimise helpers extracting and processing ENV vars in config #265

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(dataRefMatches[i], 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
Loading