Compare commits

..

1 Commits

Author SHA1 Message Date
Anoop M D
5fc32d035f wip: working on async scripting support 2023-03-28 14:49:57 +05:30
23 changed files with 51 additions and 193 deletions

View File

@@ -1,12 +0,0 @@
name: Bump Homebrew Cask
on:
release:
types: [published]
jobs:
bump:
runs-on: macos-10.15
steps:
- name: Bump Homebrew Cask
run: brew bump-cask-pr bruno --version "${GITHUB_REF_NAME#v}"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 153 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 94 KiB

View File

@@ -27,10 +27,6 @@ const Wrapper = styled.div`
&:nth-child(4) {
width: 70px;
}
select {
background-color: transparent;
}
}
}

View File

@@ -117,7 +117,7 @@ const Sidebar = () => {
</GitHubButton>
)}
</div>
<div className="flex flex-grow items-center justify-end text-xs mr-2">v0.12.0</div>
<div className="flex flex-grow items-center justify-end text-xs mr-2">v0.10.2</div>
</div>
</div>
</div>

View File

@@ -122,12 +122,6 @@ export const sendRequest = (item, collectionUid) => (dispatch, getState) => {
response: null
})
);
if(err && err.message === "Error invoking remote method 'send-http-request': Error: Request cancelled") {
console.log('>> request cancelled');
return;
}
console.log('>> sending request failed');
console.log(err);
toast.error(err ? err.message : 'Something went wrong!');

View File

@@ -49,15 +49,3 @@ export const safeStringifyJSON = (obj, indent=false) => {
return obj;
}
}
// Remove any characters that are not alphanumeric, spaces, hyphens, or underscores
export const normalizeFileName = (name) => {
if (!name) {
return name;
}
const validChars = /[^\w\s-]/g;
const formattedName = name.replace(validChars, '-');
return formattedName;
}

View File

@@ -1,19 +0,0 @@
const { describe, it, expect } = require("@jest/globals");
import { normalizeFileName } from './index';
describe("common utils", () => {
describe("normalizeFileName", () => {
it("should remove special characters", () => {
expect(normalizeFileName("hello world")).toBe("hello world");
expect(normalizeFileName("hello-world")).toBe("hello-world");
expect(normalizeFileName("hello_world")).toBe("hello_world");
expect(normalizeFileName("hello_world-")).toBe("hello_world-");
expect(normalizeFileName("hello_world-123")).toBe("hello_world-123");
expect(normalizeFileName("hello_world-123!@#$%^&*()")).toBe("hello_world-123----------");
expect(normalizeFileName("hello_world?")).toBe("hello_world-");
expect(normalizeFileName("foo/bar/")).toBe("foo-bar-");
expect(normalizeFileName("foo\\bar\\")).toBe("foo-bar-");
});
});
});

View File

@@ -3,7 +3,7 @@ import each from 'lodash/each';
import get from 'lodash/get';
import cloneDeep from 'lodash/cloneDeep';
import { uuid, normalizeFileName } from 'utils/common';
import { uuid } from 'utils/common';
import { isItemARequest } from 'utils/collections';
import { collectionSchema } from '@usebruno/schema';
import { BrunoError } from 'utils/common/error';
@@ -63,8 +63,6 @@ export const updateUidsInCollection = (_collection) => {
export const transformItemsInCollection = (collection) => {
const transformItems = (items = []) => {
each(items, (item) => {
item.name = normalizeFileName(item.name);
if (['http', 'graphql'].includes(item.type)) {
item.type = `${item.type}-request`;
if(item.request.query) {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 61 KiB

View File

@@ -1,22 +0,0 @@
MIT License
Copyright (c) 2022 Anoop M D, Anusree P S and Contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -1,26 +1,18 @@
{
"name": "@usebruno/cli",
"version": "0.4.4",
"version": "0.3.0",
"main": "src/index.js",
"bin": {
"bru": "./bin/bru.js"
},
"bugs": {
"url": "https://github.com/usebruno/bruno/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/usebruno/bruno.git"
},
"files": [
"src",
"bin",
"readme.md",
"package.json"
],
"dependencies": {
"@usebruno/js": "0.3.0",
"@usebruno/lang": "0.3.0",
"@usebruno/js": "0.2.0",
"@usebruno/lang": "0.2.2",
"axios": "^1.3.2",
"chai": "^4.3.7",
"chalk": "^3.0.0",

View File

@@ -1,44 +1,8 @@
# bruno-cli
With Bruno CLI, you can now run your API collections with ease using simple command line commands.
Bru CLI
This makes it easier to test your APIs in different environments, automate your testing process, and integrate your API tests with your continuous integration and deployment workflows.
## Installation
To install the Bruno CLI, use the node package manager of your choice, such as NPM:
### Publish to Npm Registry
```bash
npm install -g @usebruno/cli
```
## Getting started
Navigate to the directory where your API collection resides, and then run:
```bash
bru run
```
This command will run all the requests in your collection. You can also run a single request by specifying its filename:
```bash
bru run request.bru
```
Or run all requests in a folder:
```bash
bru run folder
```
If you need to use an environment, you can specify it with the --env option:
```bash
bru run folder --env Local
```
## Demo
![demo](assets/images/cli-demo.png)
## Support
If you encounter any issues or have any feedback or suggestions, please raise them on our [GitHub repository](https://github.com/usebruno/bruno)
Thank you for using Bruno CLI!
## License
[MIT](license.md)
npm publish --access=public
```

View File

@@ -42,8 +42,6 @@ const interpolateVars = (request, envVars = {}, collectionVariables ={}) => {
request.data = interpolate(request.data);
}
}
} else {
request.data = interpolate(request.data);
}
each(request.params, (param) => {

View File

@@ -1,5 +1,5 @@
{
"version": "0.12.0",
"version": "0.10.2",
"name": "bruno",
"description": "Opensource API Client",
"homepage": "https://www.usebruno.com",
@@ -13,8 +13,8 @@
"pack": "electron-builder --dir"
},
"dependencies": {
"@usebruno/js": "0.3.0",
"@usebruno/lang": "0.3.0",
"@usebruno/js": "0.2.0",
"@usebruno/lang": "0.2.2",
"@usebruno/schema": "0.3.1",
"axios": "^0.26.0",
"chai": "^4.3.7",

View File

@@ -158,7 +158,7 @@ const registerNetworkIpc = (mainWindow, watcher, lastOpenedCollections) => {
const responseScript = get(request, 'script.res');
if(responseScript && responseScript.length) {
const scriptRuntime = new ScriptRuntime();
const result = await scriptRuntime.runResponseScript(responseScript, request, response, envVars, collectionVariables, collectionPath);
const result = scriptRuntime.runResponseScript(responseScript, request, response, envVars, collectionVariables, collectionPath);
mainWindow.webContents.send('main:script-environment-update', {
envVariables: result.envVariables,
@@ -179,15 +179,17 @@ const registerNetworkIpc = (mainWindow, watcher, lastOpenedCollections) => {
});
// run tests
const testFile = item.draft ? get(item.draft, 'request.tests') : get(item, 'request.tests');
const testRuntime = new TestRuntime();
const testResults = testRuntime.runTests(testFile, request, response, envVars, collectionVariables, collectionPath);
const testFile = get(item, 'request.tests');
if(testFile && testFile.length) {
const testRuntime = new TestRuntime();
const result = testRuntime.runTests(testFile, request, response, envVars, collectionVariables, collectionPath);
mainWindow.webContents.send('main:test-results', {
results: testResults.results,
itemUid: item.uid,
collectionUid
});
mainWindow.webContents.send('main:test-results', {
results: result.results,
itemUid: item.uid,
collectionUid
});
}
deleteCancelToken(cancelTokenUid);
@@ -202,12 +204,6 @@ const registerNetworkIpc = (mainWindow, watcher, lastOpenedCollections) => {
// need to convey the error to the UI
// and need not be always a network error
deleteCancelToken(cancelTokenUid);
if (axios.isCancel(error)) {
let error = new Error("Request cancelled");
error.isCancel = true;
return Promise.reject(error);
}
if(error.response) {
return {
@@ -339,7 +335,7 @@ const registerNetworkIpc = (mainWindow, watcher, lastOpenedCollections) => {
const requestScript = get(request, 'script.req');
if(requestScript && requestScript.length) {
const scriptRuntime = new ScriptRuntime();
const result = await scriptRuntime.runRequestScript(requestScript, request, envVars, collectionVariables, collectionPath);
const result = scriptRuntime.runRequestScript(requestScript, request, envVars, collectionVariables, collectionPath);
mainWindow.webContents.send('main:script-environment-update', {
envVariables: result.envVariables,
@@ -387,7 +383,7 @@ const registerNetworkIpc = (mainWindow, watcher, lastOpenedCollections) => {
const responseScript = get(request, 'script.res');
if(responseScript && responseScript.length) {
const scriptRuntime = new ScriptRuntime();
const result = await scriptRuntime.runResponseScript(responseScript, request, response, envVars, collectionVariables, collectionPath);
const result = scriptRuntime.runResponseScript(responseScript, request, response, envVars, collectionVariables, collectionPath);
mainWindow.webContents.send('main:script-environment-update', {
envVariables: result.envVariables,
@@ -411,15 +407,17 @@ const registerNetworkIpc = (mainWindow, watcher, lastOpenedCollections) => {
}
// run tests
const testFile = item.draft ? get(item.draft, 'request.tests') : get(item, 'request.tests');
const testRuntime = new TestRuntime();
const testResults = testRuntime.runTests(testFile, request, response, envVars, collectionVariables, collectionPath);
const testFile = get(item, 'request.tests');
if(testFile && testFile.length) {
const testRuntime = new TestRuntime();
const result = testRuntime.runTests(testFile, request, response, envVars, collectionVariables, collectionPath);
mainWindow.webContents.send('main:run-folder-event', {
type: 'test-results',
testResults: testResults.results,
...eventData
});
mainWindow.webContents.send('main:run-folder-event', {
type: 'test-results',
testResults: result.results,
...eventData
});
}
mainWindow.webContents.send('main:run-folder-event', {
type: 'response-received',

View File

@@ -42,8 +42,6 @@ const interpolateVars = (request, envVars = {}, collectionVariables ={}) => {
request.data = interpolate(request.data);
}
}
} else {
request.data = interpolate(request.data);
}
each(request.params, (param) => {

View File

@@ -1,6 +1,6 @@
{
"name": "@usebruno/js",
"version": "0.3.0",
"version": "0.2.0",
"main": "src/index.js",
"files": [
"src",
@@ -16,14 +16,12 @@
"@usebruno/query": "0.1.0",
"ajv": "^8.12.0",
"atob": "^2.1.2",
"axios": "^0.26.0",
"btoa": "^1.2.1",
"crypto-js": "^4.1.1",
"json-query": "^2.2.2",
"lodash": "^4.17.21",
"moment": "^2.29.4",
"nanoid": "3.3.4",
"node-fetch": "2.*",
"uuid": "^9.0.0"
}
}

View File

@@ -19,16 +19,16 @@ const moment = require('moment');
const uuid = require('uuid');
const nanoid = require('nanoid');
const axios = require('axios');
const fetch = require('node-fetch');
const CryptoJS = require('crypto-js');
class ScriptRuntime {
constructor() {
}
async runRequestScript(script, request, envVariables, collectionVariables, collectionPath){
async runRequestScript(script, request, envVariables, collectionVariables, collectionPath) {
const bru = new Bru(envVariables, collectionVariables);
const req = new BrunoRequest(request);
const context = {
bru,
req
@@ -57,13 +57,20 @@ class ScriptRuntime {
uuid,
nanoid,
axios,
'node-fetch': fetch,
'crypto-js': CryptoJS
}
}
});
const asyncVM = vm.run(`module.exports = async () => { ${script} }`, path.join(collectionPath, 'vm.js'));
await asyncVM();
// wrap script inside a async function that gets called
script = `return (async () => { ${script} })()`;
// bug that needs to be fixed
// vm.run is not awaiting the async function
// created an issue in vm2 repo: https://github.com/patriksimek/vm2/issues/513
const result = await vm.run(script, path.join(collectionPath, 'vm.js'));
console.log(result);
return {
request,
envVariables,
@@ -71,7 +78,7 @@ class ScriptRuntime {
};
}
async runResponseScript(script, request, response, envVariables, collectionVariables, collectionPath) {
runResponseScript(script, request, response, envVariables, collectionVariables, collectionPath) {
const bru = new Bru(envVariables, collectionVariables);
const req = new BrunoRequest(request);
const res = new BrunoResponse(response);
@@ -94,15 +101,12 @@ class ScriptRuntime {
moment,
uuid,
nanoid,
axios,
'node-fetch': fetch,
'crypto-js': CryptoJS
}
}
});
const asyncVM = vm.run(`module.exports = async () => { ${script} }`, path.join(collectionPath, 'vm.js'));
await asyncVM();
vm.run(script, path.join(collectionPath, 'vm.js'));
return {
response,

View File

@@ -28,15 +28,6 @@ class TestRuntime {
const __brunoTestResults = new TestResults();
const test = Test(__brunoTestResults, chai);
if(!testsFile || !testsFile.length) {
return {
request,
envVariables,
collectionVariables,
results: __brunoTestResults.getResults()
};
}
const context = {
test,
bru,

View File

@@ -1,6 +1,6 @@
{
"name": "@usebruno/lang",
"version": "0.3.0",
"version": "0.2.2",
"main": "src/index.js",
"files": [
"src",

View File

@@ -20,14 +20,6 @@ You can use git or any version control of your choice to collaborate over your a
![bruno](assets/images/landing-2.png) <br /><br />
### Run across multiple platforms 🖥️
![bruno](assets/images/run-anywhere.png) <br /><br />
### Collaborate via Git 👩‍💻🧑‍💻
Or any version control system of your choice
![bruno](assets/images/version-control.png) <br /><br />
### Website 📄
Please visit [here](https://www.usebruno.com) to checkout our website and download the app