Repository: pactumjs/pactum
Pull request #234 (2022-11-06 04:30:21)

233 read environment variables via data management
closes: #233 


Patch:
diff --git a/package-lock.json b/package-lock.json
index 6472e31..e38b241 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -299,9 +299,9 @@
       }
     },
     "@exodus/schemasafe": {
-      "version": "1.0.0-rc.7",
-      "resolved": "https://registry.npmjs.org/@exodus/schemasafe/-/schemasafe-1.0.0-rc.7.tgz",
-      "integrity": "sha512-+1mBLsa+vvlV0lwEAP1hwgmOPkjMnoJ8hyCMfCCJga0sVDwDzrPJjnxZwdDaUmOh/vbFHQGBTk+FxsVjoI/CjQ=="
+      "version": "1.0.0-rc.9",
+      "resolved": "https://registry.npmjs.org/@exodus/schemasafe/-/schemasafe-1.0.0-rc.9.tgz",
+      "integrity": "sha512-dGGHpb61hLwifAu7sotuHFDBw6GTdpG8aKC0fsK17EuTzMRvUrH7lEAr6LTJ+sx3AZYed9yZ77rltVDHyg2hRg=="
     },
     "@istanbuljs/load-nyc-config": {
       "version": "1.1.0",
@@ -392,9 +392,9 @@
       "integrity": "sha512-oZLYFEAzUKyi3SKnXvj32ZCEGH6RDnao7COuCVhDydMS9NrCSVXhM79VaKyP5+Zc33m0QXEd2DN3UkU7OsHcfw=="
     },
     "@sinonjs/commons": {
-      "version": "1.8.3",
-      "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.3.tgz",
-      "integrity": "sha512-xkNcLAn/wZaX14RPlwizcKicDk9G3F8m2nU3L7Ukm5zBgTwiT0wsoFAHx9Jq56fJA1z/7uKGtCRu16sOUCLIHQ==",
+      "version": "1.8.4",
+      "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.4.tgz",
+      "integrity": "sha512-RpmQdHVo8hCEHDVpO39zToS9jOhR6nw+/lQAzRNq9ErrGV9IeHM71XCn68svVl/euFeVW6BWX4p35gkhbOcSIQ==",
       "dev": true,
       "requires": {
         "type-detect": "4.0.8"
@@ -410,9 +410,9 @@
       }
     },
     "@sinonjs/samsam": {
-      "version": "6.1.1",
-      "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-6.1.1.tgz",
-      "integrity": "sha512-cZ7rKJTLiE7u7Wi/v9Hc2fs3Ucc3jrWeMgPHbbTCeVAB2S0wOBbYlkJVeNSL04i7fdhT8wIbDq1zhC/PXTD2SA==",
+      "version": "6.1.3",
+      "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-6.1.3.tgz",
+      "integrity": "sha512-nhOb2dWPeb1sd3IQXL/dVPnKHDOAFfvichtBf4xV00/rU1QbPCQqKMbvIheIjqwVjh7qIgf2AHTHi391yMOMpQ==",
       "dev": true,
       "requires": {
         "@sinonjs/commons": "^1.6.0",
@@ -421,15 +421,9 @@
       }
     },
     "@sinonjs/text-encoding": {
-      "version": "0.7.1",
-      "resolved": "https://registry.npmjs.org/@sinonjs/text-encoding/-/text-encoding-0.7.1.tgz",
-      "integrity": "sha512-+iTbntw2IZPb/anVDbypzfQa+ay64MW0Zo8aJ8gZPWMMK6/OubMVb6lUPMagqjOPnmtauXnFCACVl3O7ogjeqQ==",
-      "dev": true
-    },
-    "@ungap/promise-all-settled": {
-      "version": "1.1.2",
-      "resolved": "https://registry.npmjs.org/@ungap/promise-all-settled/-/promise-all-settled-1.1.2.tgz",
-      "integrity": "sha512-sL/cEvJWAnClXw0wHk85/2L0G6Sj8UB0Ctc1TEMbKSsmpRosqhwj9gWgFRZSrBr2f9tiXISwNhCPmlfqUqyb9Q==",
+      "version": "0.7.2",
+      "resolved": "https://registry.npmjs.org/@sinonjs/text-encoding/-/text-encoding-0.7.2.tgz",
+      "integrity": "sha512-sXXKG+uL9IrKqViTtao2Ws6dy0znu9sOaP1di/jKGW1M6VssO8vlpXCQcpZ+jisQ1tTFAC5Jo/EOzFbggBagFQ==",
       "dev": true
     },
     "aggregate-error": {
@@ -1296,9 +1290,9 @@
       "integrity": "sha512-V85l97zJSTG8FEvmdTlmNYb0UMrVBwvRjw7bWTf/aT6KjFwtz3iTz8D2tuFIp7lwiaO2C5ecnrEmSkkMRCrqVw=="
     },
     "minimatch": {
-      "version": "3.0.4",
-      "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
-      "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
+      "version": "3.1.2",
+      "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz",
+      "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==",
       "dev": true,
       "requires": {
         "brace-expansion": "^1.1.7"
@@ -1311,12 +1305,11 @@
       "dev": true
     },
     "mocha": {
-      "version": "10.0.0",
-      "resolved": "https://registry.npmjs.org/mocha/-/mocha-10.0.0.tgz",
-      "integrity": "sha512-0Wl+elVUD43Y0BqPZBzZt8Tnkw9CMUdNYnUsTfOM1vuhJVZL+kiesFYsqwBkEEuEixaiPe5ZQdqDgX2jddhmoA==",
+      "version": "10.1.0",
+      "resolved": "https://registry.npmjs.org/mocha/-/mocha-10.1.0.tgz",
+      "integrity": "sha512-vUF7IYxEoN7XhQpFLxQAEMtE4W91acW4B6En9l97MwE9stL1A9gusXfoHZCLVHDUJ/7V5+lbCM6yMqzo5vNymg==",
       "dev": true,
       "requires": {
-        "@ungap/promise-all-settled": "1.1.2",
         "ansi-colors": "4.1.1",
         "browser-stdout": "1.3.1",
         "chokidar": "3.5.3",
@@ -1725,9 +1718,9 @@
       "dev": true
     },
     "phin": {
-      "version": "3.6.0",
-      "resolved": "https://registry.npmjs.org/phin/-/phin-3.6.0.tgz",
-      "integrity": "sha512-nYY4Qh/yGCoxcwOAS2UfCM8+nVJcbI4f9NC4M4zPAsuswnIIS2aB14uYAbvdxP/4DqzXfrpadT2WQOx9mLDyTA==",
+      "version": "3.6.1",
+      "resolved": "https://registry.npmjs.org/phin/-/phin-3.6.1.tgz",
+      "integrity": "sha512-ubcFKk2jRr2WUJEh+QpMkCgOQansJDuIShKbsjpejeyI/aOMLrAf0TaisbMjKwTq9CsypFFJqUaN9ZSRmBJLPw==",
       "requires": {
         "centra": "^2.4.2"
       }
@@ -1907,9 +1900,9 @@
       "dev": true
     },
     "sinon": {
-      "version": "14.0.0",
-      "resolved": "https://registry.npmjs.org/sinon/-/sinon-14.0.0.tgz",
-      "integrity": "sha512-ugA6BFmE+WrJdh0owRZHToLd32Uw3Lxq6E6LtNRU+xTVBefx632h03Q7apXWRsRdZAJ41LB8aUfn2+O4jsDNMw==",
+      "version": "14.0.1",
+      "resolved": "https://registry.npmjs.org/sinon/-/sinon-14.0.1.tgz",
+      "integrity": "sha512-JhJ0jCiyBWVAHDS+YSjgEbDn7Wgz9iIjA1/RK+eseJN0vAAWIWiXBdrnb92ELPyjsfreCYntD1ORtLSfIrlvSQ==",
       "dev": true,
       "requires": {
         "@sinonjs/commons": "^1.8.3",
diff --git a/package.json b/package.json
index 9d69e53..ff942e2 100644
--- a/package.json
+++ b/package.json
@@ -52,7 +52,7 @@
   "author": "Anudeep <asa.anudeep4@gmail.com>",
   "license": "MIT",
   "dependencies": {
-    "@exodus/schemasafe": "^1.0.0-rc.7",
+    "@exodus/schemasafe": "^1.0.0-rc.9",
     "deep-override": "^1.0.2",
     "form-data-lite": "^1.0.3",
     "json-query": "^2.2.2",
@@ -61,14 +61,14 @@
     "openapi-fuzzer-core": "^1.0.6",
     "pactum-matchers": "^1.1.3",
     "parse-graphql": "^1.0.0",
-    "phin": "^3.6.0",
+    "phin": "^3.6.1",
     "polka": "^0.5.2"
   },
   "devDependencies": {
     "chai": "^4.3.6",
-    "mocha": "^10.0.0",
+    "mocha": "^10.1.0",
     "nyc": "^15.1.0",
-    "sinon": "^14.0.0"
+    "sinon": "^14.0.1"
   },
   "engines": {
     "node": ">=10"
diff --git a/src/helpers/dataProcessor.js b/src/helpers/dataProcessor.js
index 9df7c2b..c6c3eec 100644
--- a/src/helpers/dataProcessor.js
+++ b/src/helpers/dataProcessor.js
@@ -110,6 +110,10 @@ const dataProcessor = {
           const value = jq(refValue, { data: stash.getDataStore() }).value;
           values.push(typeof value === 'undefined' ? raw : value);
         }
+        if (refType === 'E') {
+          const value = process.env[refValue];
+          values.push(typeof value === 'undefined' ? raw : value);
+        }
       }
       if (values.length === 1 && raw.length === dataRefMatches[0].length) {
         return values[0];


Test patch:
diff --git a/test/unit/dataProcessor.spec.js b/test/unit/dataProcessor.spec.js
index 8b02b86..bab4909 100644
--- a/test/unit/dataProcessor.spec.js
+++ b/test/unit/dataProcessor.spec.js
@@ -782,7 +782,6 @@ describe('Data Processing - Invalid Data', () => {
 
 });
 
-
 describe('Data Processing - Functions', () => {
 
   it('should return object data', () => {
diff --git a/test/unit/parse.spec.js b/test/unit/parse.spec.js
index f9f6fa4..c1452dc 100644
--- a/test/unit/parse.spec.js
+++ b/test/unit/parse.spec.js
@@ -34,5 +34,15 @@ describe('parse', () => {
     expect(actual).deep.equals({ name: 'guest' });
   });
 
+  it('data - environment variables', () => {
+    const actual = parse('$E{USER}');
+    expect(actual).not.equals('$E{USER_AGE_NUMBER}');
+  });
+
+  it('data - invalid environment variables', () => {
+    const actual = parse('$E{USER_AGE_NUMBER}');
+    expect(actual).equals('$E{USER_AGE_NUMBER}');
+  });
+
 });