diff --git a/packages/bruno-app/src/components/CodeEditor/index.js b/packages/bruno-app/src/components/CodeEditor/index.js index cd91c1b46..61ba430d7 100644 --- a/packages/bruno-app/src/components/CodeEditor/index.js +++ b/packages/bruno-app/src/components/CodeEditor/index.js @@ -65,6 +65,7 @@ if (!SERVER_RENDERED) { 'bru.getFolderVar(key)', 'bru.getCollectionVar(key)', 'bru.setEnvVar(key,value)', + 'bru.deleteEnvVar(key)', 'bru.hasVar(key)', 'bru.getVar(key)', 'bru.setVar(key,value)', diff --git a/packages/bruno-app/src/utils/importers/translators/index.spec.js b/packages/bruno-app/src/utils/importers/translators/index.spec.js index b70691f21..26b804b00 100644 --- a/packages/bruno-app/src/utils/importers/translators/index.spec.js +++ b/packages/bruno-app/src/utils/importers/translators/index.spec.js @@ -11,6 +11,9 @@ describe('postmanTranslation function', () => { pm.collectionVariables.set('key', 'value'); const data = pm.response.json(); pm.expect(pm.environment.has('key')).to.be.true; + postman.setEnvironmentVariable('key', 'value'); + postman.getEnvironmentVariable('key'); + postman.clearEnvironmentVariable('key'); `; const expectedOutput = ` bru.getEnvVar('key'); @@ -21,6 +24,9 @@ describe('postmanTranslation function', () => { bru.setVar('key', 'value'); const data = res.getBody(); expect(bru.getEnvVar('key') !== undefined && bru.getEnvVar('key') !== null).to.be.true; + bru.setEnvVar('key', 'value'); + bru.getEnvVar('key'); + bru.deleteEnvVar('key'); `; expect(postmanTranslation(inputScript)).toBe(expectedOutput); }); @@ -151,3 +157,13 @@ test('should handle response commands', () => { `; expect(postmanTranslation(inputScript)).toBe(expectedOutput); }); + +test('should handle tests object', () => { + const inputScript = ` + tests['Status code is 200'] = responseCode.code === 200; + `; + const expectedOutput = ` + test("Status code is 200", function() { expect(Boolean(responseCode.code === 200)).to.be.true; }); + `; + expect(postmanTranslation(inputScript)).toBe(expectedOutput); +}); diff --git a/packages/bruno-app/src/utils/importers/translators/postman_translation.js b/packages/bruno-app/src/utils/importers/translators/postman_translation.js index ae5cd093d..bd244673e 100644 --- a/packages/bruno-app/src/utils/importers/translators/postman_translation.js +++ b/packages/bruno-app/src/utils/importers/translators/postman_translation.js @@ -17,7 +17,12 @@ const replacements = { 'pm\\.response\\.code': 'res.getStatus()', 'pm\\.response\\.text\\(': 'res.getBody()?.toString(', 'pm\\.expect\\.fail\\(': 'expect.fail(', - 'pm\\.response\\.responseTime': 'res.getResponseTime()' + 'pm\\.response\\.responseTime': 'res.getResponseTime()', + "tests\\['([^']+)'\\]\\s*=\\s*([^;]+);": 'test("$1", function() { expect(Boolean($2)).to.be.true; });', + // deprecated translations + 'postman\\.setEnvironmentVariable\\(': 'bru.setEnvVar(', + 'postman\\.getEnvironmentVariable\\(': 'bru.getEnvVar(', + 'postman\\.clearEnvironmentVariable\\(': 'bru.deleteEnvVar(', }; const extendedReplacements = Object.keys(replacements).reduce((acc, key) => { diff --git a/packages/bruno-js/src/bru.js b/packages/bruno-js/src/bru.js index fc6f81378..5a4d69426 100644 --- a/packages/bruno-js/src/bru.js +++ b/packages/bruno-js/src/bru.js @@ -65,6 +65,10 @@ class Bru { this.envVariables[key] = value; } + deleteEnvVar(key) { + delete this.envVariables[key]; + } + getGlobalEnvVar(key) { return this._interpolate(this.globalEnvironmentVariables[key]); }