mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-09 06:55:03 +00:00
feat(#197): prettier formatting on all files in packages/bruno-app
This commit is contained in:
@@ -14,7 +14,7 @@ if (!SERVER_RENDERED) {
|
||||
|
||||
const renderVarInfo = (token, options, cm, pos) => {
|
||||
const str = token.string || '';
|
||||
if(!str || !str.length || typeof str !== 'string') {
|
||||
if (!str || !str.length || typeof str !== 'string') {
|
||||
return;
|
||||
}
|
||||
// str is of format {{variableName}}, extract variableName
|
||||
@@ -32,8 +32,7 @@ if (!SERVER_RENDERED) {
|
||||
return into;
|
||||
};
|
||||
|
||||
CodeMirror.defineOption('brunoVarInfo', false, function(cm, options, old) {
|
||||
|
||||
CodeMirror.defineOption('brunoVarInfo', false, function (cm, options, old) {
|
||||
if (old && old !== CodeMirror.Init) {
|
||||
const oldOnMouseOver = cm.state.brunoVarInfo.onMouseOver;
|
||||
CodeMirror.off(cm.getWrapperElement(), 'mouseover', oldOnMouseOver);
|
||||
@@ -50,10 +49,7 @@ if (!SERVER_RENDERED) {
|
||||
|
||||
function createState(options) {
|
||||
return {
|
||||
options:
|
||||
options instanceof Function
|
||||
? {render: options}
|
||||
: options === true ? {} : options,
|
||||
options: options instanceof Function ? { render: options } : options === true ? {} : options
|
||||
};
|
||||
}
|
||||
|
||||
@@ -70,7 +66,7 @@ if (!SERVER_RENDERED) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(target.className !== 'cm-variable-valid') {
|
||||
if (target.className !== 'cm-variable-valid') {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -79,19 +75,19 @@ if (!SERVER_RENDERED) {
|
||||
const hoverTime = getHoverTime(cm);
|
||||
state.hoverTimeout = setTimeout(onHover, hoverTime);
|
||||
|
||||
const onMouseMove = function() {
|
||||
const onMouseMove = function () {
|
||||
clearTimeout(state.hoverTimeout);
|
||||
state.hoverTimeout = setTimeout(onHover, hoverTime);
|
||||
};
|
||||
|
||||
const onMouseOut = function() {
|
||||
const onMouseOut = function () {
|
||||
CodeMirror.off(document, 'mousemove', onMouseMove);
|
||||
CodeMirror.off(cm.getWrapperElement(), 'mouseout', onMouseOut);
|
||||
clearTimeout(state.hoverTimeout);
|
||||
state.hoverTimeout = undefined;
|
||||
};
|
||||
|
||||
const onHover = function() {
|
||||
const onHover = function () {
|
||||
CodeMirror.off(document, 'mousemove', onMouseMove);
|
||||
CodeMirror.off(cm.getWrapperElement(), 'mouseout', onMouseOut);
|
||||
state.hoverTimeout = undefined;
|
||||
@@ -105,7 +101,7 @@ if (!SERVER_RENDERED) {
|
||||
function onMouseHover(cm, box) {
|
||||
const pos = cm.coordsChar({
|
||||
left: (box.left + box.right) / 2,
|
||||
top: (box.top + box.bottom) / 2,
|
||||
top: (box.top + box.bottom) / 2
|
||||
});
|
||||
|
||||
const state = cm.state.brunoVarInfo;
|
||||
@@ -128,21 +124,12 @@ if (!SERVER_RENDERED) {
|
||||
const popupBox = popup.getBoundingClientRect();
|
||||
const popupStyle = popup.currentStyle || window.getComputedStyle(popup);
|
||||
const popupWidth =
|
||||
popupBox.right -
|
||||
popupBox.left +
|
||||
parseFloat(popupStyle.marginLeft) +
|
||||
parseFloat(popupStyle.marginRight);
|
||||
popupBox.right - popupBox.left + parseFloat(popupStyle.marginLeft) + parseFloat(popupStyle.marginRight);
|
||||
const popupHeight =
|
||||
popupBox.bottom -
|
||||
popupBox.top +
|
||||
parseFloat(popupStyle.marginTop) +
|
||||
parseFloat(popupStyle.marginBottom);
|
||||
popupBox.bottom - popupBox.top + parseFloat(popupStyle.marginTop) + parseFloat(popupStyle.marginBottom);
|
||||
|
||||
let topPos = box.bottom;
|
||||
if (
|
||||
popupHeight > window.innerHeight - box.bottom - 15 &&
|
||||
box.top > window.innerHeight - box.bottom
|
||||
) {
|
||||
if (popupHeight > window.innerHeight - box.bottom - 15 && box.top > window.innerHeight - box.bottom) {
|
||||
topPos = box.top - popupHeight;
|
||||
}
|
||||
|
||||
@@ -166,23 +153,23 @@ if (!SERVER_RENDERED) {
|
||||
|
||||
let popupTimeout;
|
||||
|
||||
const onMouseOverPopup = function() {
|
||||
const onMouseOverPopup = function () {
|
||||
clearTimeout(popupTimeout);
|
||||
};
|
||||
|
||||
const onMouseOut = function() {
|
||||
const onMouseOut = function () {
|
||||
clearTimeout(popupTimeout);
|
||||
popupTimeout = setTimeout(hidePopup, 200);
|
||||
};
|
||||
|
||||
const hidePopup = function() {
|
||||
const hidePopup = function () {
|
||||
CodeMirror.off(popup, 'mouseover', onMouseOverPopup);
|
||||
CodeMirror.off(popup, 'mouseout', onMouseOut);
|
||||
CodeMirror.off(cm.getWrapperElement(), 'mouseout', onMouseOut);
|
||||
|
||||
if (popup.style.opacity) {
|
||||
popup.style.opacity = 0;
|
||||
setTimeout(function() {
|
||||
setTimeout(function () {
|
||||
if (popup.parentNode) {
|
||||
popup.parentNode.removeChild(popup);
|
||||
}
|
||||
|
||||
@@ -32,11 +32,11 @@ const transformItem = (items = []) => {
|
||||
item.request.query = item.request.params;
|
||||
delete item.request.params;
|
||||
|
||||
if(item.type === 'graphql-request') {
|
||||
if (item.type === 'graphql-request') {
|
||||
item.type = 'graphql';
|
||||
}
|
||||
|
||||
if(item.type === 'http-request') {
|
||||
if (item.type === 'http-request') {
|
||||
item.type = 'http';
|
||||
}
|
||||
}
|
||||
@@ -61,7 +61,6 @@ const exportCollection = (collection) => {
|
||||
deleteUidsInEnvs(collection.environments);
|
||||
transformItem(collection.items);
|
||||
|
||||
|
||||
const fileName = `${collection.name}.json`;
|
||||
const fileBlob = new Blob([JSON.stringify(collection, null, 2)], { type: 'application/json' });
|
||||
|
||||
|
||||
@@ -158,13 +158,13 @@ export const moveCollectionItemToRootOfCollection = (collection, draggedItem) =>
|
||||
let draggedItemParent = findParentItemInCollection(collection, draggedItem.uid);
|
||||
|
||||
// If the dragged item is already at the root of the collection, do nothing
|
||||
if(!draggedItemParent) {
|
||||
if (!draggedItemParent) {
|
||||
return;
|
||||
}
|
||||
|
||||
draggedItemParent.items = filter(draggedItemParent.items, (i) => i.uid !== draggedItem.uid);
|
||||
collection.items.push(draggedItem);
|
||||
if(draggedItem.type == 'folder') {
|
||||
if (draggedItem.type == 'folder') {
|
||||
draggedItem.pathname = path.join(collection.pathname, draggedItem.name);
|
||||
} else {
|
||||
draggedItem.pathname = path.join(collection.pathname, draggedItem.filename);
|
||||
@@ -174,10 +174,10 @@ export const moveCollectionItemToRootOfCollection = (collection, draggedItem) =>
|
||||
export const getItemsToResequence = (parent, collection) => {
|
||||
let itemsToResequence = [];
|
||||
|
||||
if(!parent) {
|
||||
if (!parent) {
|
||||
let index = 1;
|
||||
each(collection.items, (item) => {
|
||||
if(isItemARequest(item)) {
|
||||
if (isItemARequest(item)) {
|
||||
itemsToResequence.push({
|
||||
pathname: item.pathname,
|
||||
seq: index++
|
||||
@@ -190,7 +190,7 @@ export const getItemsToResequence = (parent, collection) => {
|
||||
if (parent.items && parent.items.length) {
|
||||
let index = 1;
|
||||
each(parent.items, (item) => {
|
||||
if(isItemARequest(item)) {
|
||||
if (isItemARequest(item)) {
|
||||
itemsToResequence.push({
|
||||
pathname: item.pathname,
|
||||
seq: index++
|
||||
@@ -499,11 +499,11 @@ export const areItemsTheSameExceptSeqUpdate = (_item1, _item2) => {
|
||||
};
|
||||
|
||||
export const getDefaultRequestPaneTab = (item) => {
|
||||
if(item.type === 'http-request') {
|
||||
if (item.type === 'http-request') {
|
||||
return 'params';
|
||||
}
|
||||
|
||||
if(item.type === 'graphql-request') {
|
||||
if (item.type === 'graphql-request') {
|
||||
return 'query';
|
||||
}
|
||||
};
|
||||
@@ -514,7 +514,7 @@ export const getEnvironmentVariables = (collection) => {
|
||||
const environment = findEnvironmentInCollection(collection, collection.activeEnvironmentUid);
|
||||
if (environment) {
|
||||
each(environment.variables, (variable) => {
|
||||
if(variable.name && variable.value && variable.enabled) {
|
||||
if (variable.name && variable.value && variable.enabled) {
|
||||
variables[variable.name] = variable.value;
|
||||
}
|
||||
});
|
||||
@@ -522,7 +522,7 @@ export const getEnvironmentVariables = (collection) => {
|
||||
}
|
||||
|
||||
return variables;
|
||||
}
|
||||
};
|
||||
|
||||
export const getTotalRequestCountInCollection = (collection) => {
|
||||
let count = 0;
|
||||
@@ -544,4 +544,4 @@ export const getAllVariables = (collection) => {
|
||||
...environmentVariables,
|
||||
...collection.collectionVariables
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
let CodeMirror;
|
||||
const SERVER_RENDERED = typeof navigator === 'undefined' || global['PREVENT_CODEMIRROR_RENDER'] === true;
|
||||
|
||||
@@ -7,29 +6,29 @@ if (!SERVER_RENDERED) {
|
||||
}
|
||||
|
||||
export const defineCodeMirrorBrunoVariablesMode = (variables, mode) => {
|
||||
CodeMirror.defineMode("brunovariables", function(config, parserConfig) {
|
||||
CodeMirror.defineMode('brunovariables', function (config, parserConfig) {
|
||||
let variablesOverlay = {
|
||||
token: function(stream, state) {
|
||||
if (stream.match("{{", true)) {
|
||||
token: function (stream, state) {
|
||||
if (stream.match('{{', true)) {
|
||||
let ch;
|
||||
let word = "";
|
||||
let word = '';
|
||||
while ((ch = stream.next()) != null) {
|
||||
if (ch == "}" && stream.next() == "}") {
|
||||
stream.eat("}");
|
||||
if (ch == '}' && stream.next() == '}') {
|
||||
stream.eat('}');
|
||||
if (word in variables) {
|
||||
return "variable-valid";
|
||||
return 'variable-valid';
|
||||
} else {
|
||||
return "variable-invalid";
|
||||
return 'variable-invalid';
|
||||
}
|
||||
}
|
||||
word += ch;
|
||||
}
|
||||
}
|
||||
while (stream.next() != null && !stream.match("{{", false)) {}
|
||||
while (stream.next() != null && !stream.match('{{', false)) {}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
return CodeMirror.overlayMode(CodeMirror.getMode(config, parserConfig.backdrop || mode), variablesOverlay);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
@@ -26,7 +26,7 @@ export const waitForNextTick = () => {
|
||||
};
|
||||
|
||||
export const safeParseJSON = (str) => {
|
||||
if(!str || !str.length || typeof str !== 'string') {
|
||||
if (!str || !str.length || typeof str !== 'string') {
|
||||
return str;
|
||||
}
|
||||
try {
|
||||
@@ -36,19 +36,19 @@ export const safeParseJSON = (str) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const safeStringifyJSON = (obj, indent=false) => {
|
||||
if(!obj) {
|
||||
export const safeStringifyJSON = (obj, indent = false) => {
|
||||
if (!obj) {
|
||||
return obj;
|
||||
}
|
||||
try {
|
||||
if(indent) {
|
||||
if (indent) {
|
||||
return JSON.stringify(obj, null, 2);
|
||||
}
|
||||
return JSON.stringify(obj);
|
||||
} catch (e) {
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Remove any characters that are not alphanumeric, spaces, hyphens, or underscores
|
||||
export const normalizeFileName = (name) => {
|
||||
@@ -60,4 +60,4 @@ export const normalizeFileName = (name) => {
|
||||
const formattedName = name.replace(validChars, '-');
|
||||
|
||||
return formattedName;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
const { describe, it, expect } = require("@jest/globals");
|
||||
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-");
|
||||
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-');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import trim from 'lodash/trim';
|
||||
import path from 'path';
|
||||
import slash from './slash';
|
||||
import slash from './slash';
|
||||
|
||||
export const isElectron = () => {
|
||||
if (!window) {
|
||||
@@ -32,4 +32,4 @@ export const getDirectoryName = (pathname) => {
|
||||
pathname = slash(pathname);
|
||||
|
||||
return path.dirname(pathname);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
*
|
||||
* Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
||||
* 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.
|
||||
@@ -8,13 +8,13 @@
|
||||
*/
|
||||
|
||||
const slash = (path) => {
|
||||
const isExtendedLengthPath = /^\\\\\?\\/.test(path);
|
||||
const isExtendedLengthPath = /^\\\\\?\\/.test(path);
|
||||
|
||||
if (isExtendedLengthPath) {
|
||||
return path;
|
||||
}
|
||||
if (isExtendedLengthPath) {
|
||||
return path;
|
||||
}
|
||||
|
||||
return path.replace(/\\/g, '/');
|
||||
}
|
||||
return path.replace(/\\/g, '/');
|
||||
};
|
||||
|
||||
export default slash;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import each from 'lodash/each';
|
||||
import get from 'lodash/get';
|
||||
|
||||
@@ -67,7 +66,7 @@ export const transformItemsInCollection = (collection) => {
|
||||
|
||||
if (['http', 'graphql'].includes(item.type)) {
|
||||
item.type = `${item.type}-request`;
|
||||
if(item.request.query) {
|
||||
if (item.request.query) {
|
||||
item.request.params = item.request.query;
|
||||
}
|
||||
|
||||
@@ -89,7 +88,7 @@ export const hydrateSeqInCollection = (collection) => {
|
||||
const hydrateSeq = (items = []) => {
|
||||
let index = 1;
|
||||
each(items, (item) => {
|
||||
if(isItemARequest(item) && !item.seq) {
|
||||
if (isItemARequest(item) && !item.seq) {
|
||||
item.seq = index;
|
||||
index++;
|
||||
}
|
||||
@@ -101,4 +100,4 @@ export const hydrateSeqInCollection = (collection) => {
|
||||
hydrateSeq(collection.items);
|
||||
|
||||
return collection;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -21,15 +21,14 @@ const parseGraphQL = (text) => {
|
||||
return {
|
||||
query: graphql.query,
|
||||
variables: JSON.stringify(graphql.variables, null, 2)
|
||||
}
|
||||
};
|
||||
} catch (e) {
|
||||
return {
|
||||
query: '',
|
||||
variables: {}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
const transformInsomniaRequestItem = (request) => {
|
||||
const brunoRequestItem = {
|
||||
@@ -111,7 +110,6 @@ const transformInsomniaRequestItem = (request) => {
|
||||
brunoRequestItem.request.body.graphql = parseGraphQL(request.body.text);
|
||||
}
|
||||
|
||||
|
||||
return brunoRequestItem;
|
||||
};
|
||||
|
||||
@@ -119,7 +117,7 @@ const parseInsomniaCollection = (data) => {
|
||||
const brunoCollection = {
|
||||
name: '',
|
||||
uid: uuid(),
|
||||
version: "1",
|
||||
version: '1',
|
||||
items: [],
|
||||
environments: []
|
||||
};
|
||||
@@ -128,7 +126,9 @@ const parseInsomniaCollection = (data) => {
|
||||
try {
|
||||
const insomniaExport = JSON.parse(data);
|
||||
const insomniaResources = get(insomniaExport, 'resources', []);
|
||||
const insomniaCollection = insomniaResources.find(resource => resource._type === 'workspace' && resource.scope === 'collection');
|
||||
const insomniaCollection = insomniaResources.find(
|
||||
(resource) => resource._type === 'workspace' && resource.scope === 'collection'
|
||||
);
|
||||
|
||||
if (!insomniaCollection) {
|
||||
reject(new BrunoError('Collection not found inside Insomnia export'));
|
||||
@@ -136,31 +136,33 @@ const parseInsomniaCollection = (data) => {
|
||||
|
||||
brunoCollection.name = insomniaCollection.name;
|
||||
|
||||
const requestsAndFolders = insomniaResources.filter(
|
||||
(resource) => resource._type === 'request' || resource._type === 'request_group'
|
||||
) || [];
|
||||
const requestsAndFolders =
|
||||
insomniaResources.filter((resource) => resource._type === 'request' || resource._type === 'request_group') ||
|
||||
[];
|
||||
|
||||
function createFolderStructure(resources, parentId = null) {
|
||||
const requestGroups = resources.filter((resource) => resource._type === 'request_group' && resource.parentId === parentId) || [];
|
||||
const requestGroups =
|
||||
resources.filter((resource) => resource._type === 'request_group' && resource.parentId === parentId) || [];
|
||||
const requests = resources.filter((resource) => resource._type === 'request' && resource.parentId === parentId);
|
||||
|
||||
const folders = requestGroups.map((folder) => {
|
||||
const requests = resources.filter((resource) => resource._type === 'request' && resource.parentId === folder._id);
|
||||
const requests = resources.filter(
|
||||
(resource) => resource._type === 'request' && resource.parentId === folder._id
|
||||
);
|
||||
|
||||
return {
|
||||
uid: uuid(),
|
||||
name: folder.name,
|
||||
type: 'folder',
|
||||
items: createFolderStructure(resources, folder._id).concat(requests.map(transformInsomniaRequestItem)),
|
||||
}
|
||||
items: createFolderStructure(resources, folder._id).concat(requests.map(transformInsomniaRequestItem))
|
||||
};
|
||||
});
|
||||
|
||||
return folders.concat(requests.map(transformInsomniaRequestItem));
|
||||
}
|
||||
|
||||
brunoCollection.items = createFolderStructure(requestsAndFolders, insomniaCollection._id),
|
||||
|
||||
resolve(brunoCollection);
|
||||
(brunoCollection.items = createFolderStructure(requestsAndFolders, insomniaCollection._id)),
|
||||
resolve(brunoCollection);
|
||||
} catch (err) {
|
||||
reject(new BrunoError('An error occurred while parsing the Insomnia collection'));
|
||||
}
|
||||
@@ -183,4 +185,4 @@ const importCollection = () => {
|
||||
});
|
||||
};
|
||||
|
||||
export default importCollection;
|
||||
export default importCollection;
|
||||
|
||||
@@ -22,7 +22,7 @@ const importPostmanV2CollectionItem = (brunoParent, item) => {
|
||||
brunoParent.items = brunoParent.items || [];
|
||||
|
||||
each(item, (i) => {
|
||||
if(isItemAFolder(i)) {
|
||||
if (isItemAFolder(i)) {
|
||||
const brunoFolderItem = {
|
||||
uid: uuid(),
|
||||
name: i.name,
|
||||
@@ -30,13 +30,13 @@ const importPostmanV2CollectionItem = (brunoParent, item) => {
|
||||
items: []
|
||||
};
|
||||
brunoParent.items.push(brunoFolderItem);
|
||||
if(i.item && i.item.length) {
|
||||
if (i.item && i.item.length) {
|
||||
importPostmanV2CollectionItem(brunoFolderItem, i.item);
|
||||
}
|
||||
} else {
|
||||
if(i.request) {
|
||||
if (i.request) {
|
||||
let url = '';
|
||||
if(typeof i.request.url === 'string') {
|
||||
if (typeof i.request.url === 'string') {
|
||||
url = i.request.url;
|
||||
} else {
|
||||
url = get(i, 'request.url.raw') || '';
|
||||
@@ -63,8 +63,8 @@ const importPostmanV2CollectionItem = (brunoParent, item) => {
|
||||
};
|
||||
|
||||
const bodyMode = get(i, 'request.body.mode');
|
||||
if(bodyMode) {
|
||||
if(bodyMode === 'formdata') {
|
||||
if (bodyMode) {
|
||||
if (bodyMode === 'formdata') {
|
||||
brunoRequestItem.request.body.mode = 'multipartForm';
|
||||
each(i.request.body.formdata, (param) => {
|
||||
brunoRequestItem.request.body.formUrlEncoded.push({
|
||||
@@ -77,7 +77,7 @@ const importPostmanV2CollectionItem = (brunoParent, item) => {
|
||||
});
|
||||
}
|
||||
|
||||
if(bodyMode === 'urlencoded') {
|
||||
if (bodyMode === 'urlencoded') {
|
||||
brunoRequestItem.request.body.mode = 'formUrlEncoded';
|
||||
each(i.request.body.urlencoded, (param) => {
|
||||
brunoRequestItem.request.body.formUrlEncoded.push({
|
||||
@@ -90,9 +90,9 @@ const importPostmanV2CollectionItem = (brunoParent, item) => {
|
||||
});
|
||||
}
|
||||
|
||||
if(bodyMode === 'raw') {
|
||||
if (bodyMode === 'raw') {
|
||||
const language = get(i, 'request.body.options.raw.language');
|
||||
if(language === 'json') {
|
||||
if (language === 'json') {
|
||||
brunoRequestItem.request.body.mode = 'json';
|
||||
brunoRequestItem.request.body.json = i.request.body.raw;
|
||||
} else if (language === 'xml') {
|
||||
@@ -135,7 +135,7 @@ const importPostmanV2Collection = (collection) => {
|
||||
const brunoCollection = {
|
||||
name: collection.info.name,
|
||||
uid: uuid(),
|
||||
version: "1",
|
||||
version: '1',
|
||||
items: [],
|
||||
environments: []
|
||||
};
|
||||
@@ -145,7 +145,6 @@ const importPostmanV2Collection = (collection) => {
|
||||
return brunoCollection;
|
||||
};
|
||||
|
||||
|
||||
const parsePostmanCollection = (str) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
@@ -157,14 +156,14 @@ const parsePostmanCollection = (str) => {
|
||||
'https://schema.getpostman.com/json/collection/v2.1.0/collection.json'
|
||||
];
|
||||
|
||||
if(v2Schemas.includes(schema)) {
|
||||
if (v2Schemas.includes(schema)) {
|
||||
return resolve(importPostmanV2Collection(collection));
|
||||
}
|
||||
|
||||
throw new BrunoError('Unknown postman schema');
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
if(err instanceof BrunoError) {
|
||||
if (err instanceof BrunoError) {
|
||||
return reject(err);
|
||||
}
|
||||
|
||||
|
||||
@@ -35,18 +35,12 @@ export const fetchGqlSchema = async (endpoint, environment) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const { ipcRenderer } = window;
|
||||
|
||||
ipcRenderer
|
||||
.invoke('fetch-gql-schema', endpoint, environment)
|
||||
.then(resolve)
|
||||
.catch(reject);
|
||||
ipcRenderer.invoke('fetch-gql-schema', endpoint, environment).then(resolve).catch(reject);
|
||||
});
|
||||
};
|
||||
|
||||
export const cancelNetworkRequest = async (cancelTokenUid) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
ipcRenderer
|
||||
.invoke('cancel-http-request', cancelTokenUid)
|
||||
.then(resolve)
|
||||
.catch(reject);
|
||||
ipcRenderer.invoke('cancel-http-request', cancelTokenUid).then(resolve).catch(reject);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -4,7 +4,7 @@ import each from 'lodash/each';
|
||||
import filter from 'lodash/filter';
|
||||
|
||||
const hasLength = (str) => {
|
||||
if(!str || !str.length) {
|
||||
if (!str || !str.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ export const parseQueryParams = (query) => {
|
||||
return [];
|
||||
}
|
||||
|
||||
let params = query.split('&').map(param => {
|
||||
let params = query.split('&').map((param) => {
|
||||
let [name, value = ''] = param.split('=');
|
||||
return { name, value };
|
||||
});
|
||||
@@ -42,7 +42,7 @@ export const stringifyQueryParams = (params) => {
|
||||
};
|
||||
|
||||
export const splitOnFirst = (str, char) => {
|
||||
if(!str || !str.length) {
|
||||
if (!str || !str.length) {
|
||||
return [str];
|
||||
}
|
||||
|
||||
|
||||
@@ -1,70 +1,79 @@
|
||||
import { parseQueryParams, splitOnFirst } from './index';
|
||||
|
||||
describe('Url Utils - parseQueryParams', () => {
|
||||
it('should parse query - case 1', () => {
|
||||
const params = parseQueryParams("");
|
||||
it('should parse query - case 1', () => {
|
||||
const params = parseQueryParams('');
|
||||
expect(params).toEqual([]);
|
||||
});
|
||||
|
||||
it('should parse query - case 2', () => {
|
||||
const params = parseQueryParams("a");
|
||||
expect(params).toEqual([{name: 'a', value: ''}]);
|
||||
it('should parse query - case 2', () => {
|
||||
const params = parseQueryParams('a');
|
||||
expect(params).toEqual([{ name: 'a', value: '' }]);
|
||||
});
|
||||
|
||||
it('should parse query - case 3', () => {
|
||||
const params = parseQueryParams("a=");
|
||||
expect(params).toEqual([{name: 'a', value: ''}]);
|
||||
it('should parse query - case 3', () => {
|
||||
const params = parseQueryParams('a=');
|
||||
expect(params).toEqual([{ name: 'a', value: '' }]);
|
||||
});
|
||||
|
||||
it('should parse query - case 4', () => {
|
||||
const params = parseQueryParams("a=1");
|
||||
expect(params).toEqual([{name: 'a', value: '1'}]);
|
||||
it('should parse query - case 4', () => {
|
||||
const params = parseQueryParams('a=1');
|
||||
expect(params).toEqual([{ name: 'a', value: '1' }]);
|
||||
});
|
||||
|
||||
it('should parse query - case 5', () => {
|
||||
const params = parseQueryParams("a=1&");
|
||||
expect(params).toEqual([{name: 'a', value: '1'}]);
|
||||
it('should parse query - case 5', () => {
|
||||
const params = parseQueryParams('a=1&');
|
||||
expect(params).toEqual([{ name: 'a', value: '1' }]);
|
||||
});
|
||||
|
||||
it('should parse query - case 6', () => {
|
||||
const params = parseQueryParams("a=1&b");
|
||||
expect(params).toEqual([{name: 'a', value: '1'}, {name: 'b', value: ''}]);
|
||||
it('should parse query - case 6', () => {
|
||||
const params = parseQueryParams('a=1&b');
|
||||
expect(params).toEqual([
|
||||
{ name: 'a', value: '1' },
|
||||
{ name: 'b', value: '' }
|
||||
]);
|
||||
});
|
||||
|
||||
it('should parse query - case 7', () => {
|
||||
const params = parseQueryParams("a=1&b=");
|
||||
expect(params).toEqual([{name: 'a', value: '1'}, {name: 'b', value: ''}]);
|
||||
it('should parse query - case 7', () => {
|
||||
const params = parseQueryParams('a=1&b=');
|
||||
expect(params).toEqual([
|
||||
{ name: 'a', value: '1' },
|
||||
{ name: 'b', value: '' }
|
||||
]);
|
||||
});
|
||||
|
||||
it('should parse query - case 8', () => {
|
||||
const params = parseQueryParams("a=1&b=2");
|
||||
expect(params).toEqual([{name: 'a', value: '1'}, {name: 'b', value: '2'}]);
|
||||
it('should parse query - case 8', () => {
|
||||
const params = parseQueryParams('a=1&b=2');
|
||||
expect(params).toEqual([
|
||||
{ name: 'a', value: '1' },
|
||||
{ name: 'b', value: '2' }
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Url Utils - splitOnFirst', () => {
|
||||
it('should split on first - case 1', () => {
|
||||
const params = splitOnFirst("a", "=");
|
||||
it('should split on first - case 1', () => {
|
||||
const params = splitOnFirst('a', '=');
|
||||
expect(params).toEqual(['a']);
|
||||
});
|
||||
|
||||
it('should split on first - case 2', () => {
|
||||
const params = splitOnFirst("a=", "=");
|
||||
it('should split on first - case 2', () => {
|
||||
const params = splitOnFirst('a=', '=');
|
||||
expect(params).toEqual(['a', '']);
|
||||
});
|
||||
|
||||
it('should split on first - case 3', () => {
|
||||
const params = splitOnFirst("a=1", "=");
|
||||
it('should split on first - case 3', () => {
|
||||
const params = splitOnFirst('a=1', '=');
|
||||
expect(params).toEqual(['a', '1']);
|
||||
});
|
||||
|
||||
it('should split on first - case 4', () => {
|
||||
const params = splitOnFirst("a=1&b=2", "=");
|
||||
it('should split on first - case 4', () => {
|
||||
const params = splitOnFirst('a=1&b=2', '=');
|
||||
expect(params).toEqual(['a', '1&b=2']);
|
||||
});
|
||||
|
||||
it('should split on first - case 5', () => {
|
||||
const params = splitOnFirst("a=1&b=2", "&");
|
||||
it('should split on first - case 5', () => {
|
||||
const params = splitOnFirst('a=1&b=2', '&');
|
||||
expect(params).toEqual(['a=1', 'b=2']);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user