Skip to content

Commit

Permalink
Merge branch 'develop' into feature/friendly-json-viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
gschier committed Oct 13, 2017
2 parents 5f6b52d + a14bac2 commit c43c251
Show file tree
Hide file tree
Showing 77 changed files with 1,612 additions and 638 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"fail": true,
"HTMLDivElement": true,
"HTMLElement": true,
"HTMLInputElement": true
"HTMLInputElement": true,
"HTMLSelectElement": true
},
"env": {
"jest/globals": true
Expand Down
7 changes: 7 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
* text eol=lf

*.gif binary
*.icns binary
*.ico binary
*.png binary
*.woff2 binary
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
node_modules
.idea
.vscode
dist/*
build/*
.DS_Store
Expand Down
1 change: 1 addition & 0 deletions app/__jest__/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ const localStorageMock = (function () {
})();

global.localStorage = localStorageMock;
global.requestAnimationFrame = cb => process.nextTick(cb);
global.require = require;
11 changes: 10 additions & 1 deletion app/__mocks__/insomnia-node-libcurl.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class Curl extends EventEmitter {
constructor () {
super();
this._options = {};
this._meta = {};
}
setOpt (name, value) {
if (!name) {
Expand All @@ -15,6 +16,12 @@ class Curl extends EventEmitter {
return;
}

if (name === Curl.option.READFUNCTION) {
const buffer = new Buffer(10000);
const bytes = value(buffer);
this._meta[`${name}_VALUE`] = buffer.slice(0, bytes).toString('utf8');
}

if (name === Curl.option.COOKIELIST) {
// This can be set multiple times
this._options[name] = this._options[name] || [];
Expand Down Expand Up @@ -42,7 +49,8 @@ class Curl extends EventEmitter {
perform () {
process.nextTick(() => {
const data = Buffer.from(JSON.stringify({
options: this._options
options: this._options,
meta: this._meta
}));

this.emit('data', data);
Expand Down Expand Up @@ -110,6 +118,7 @@ Curl.option = {
PROXY: 'PROXY',
PROXYAUTH: 'PROXYAUTH',
READDATA: 'READDATA',
READFUNCTION: 'READFUNCTION',
SSLCERT: 'SSLCERT',
SSLCERTTYPE: 'SSLCERTTYPE',
SSLKEY: 'SSLKEY',
Expand Down
4 changes: 0 additions & 4 deletions app/__tests__/package.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,4 @@ describe('package.json', () => {
expect(`${name}::${actual}`).toBe(`${name}::${expected}`);
}
});

it('pdfjs should not be in deps', () => {
expect(appPackage.dependencies['simple-react-pdf']).toBeUndefined();
});
});
4 changes: 2 additions & 2 deletions app/analytics/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as google from './google';
import * as models from '../models';
import {ipcRenderer} from 'electron';
import {getAppVersion, getAppPlatform} from '../common/constants';
import {getAppVersion, getAppPlatform, isDevelopment} from '../common/constants';

let initialized = false;
export async function init (accountId) {
Expand All @@ -24,7 +24,7 @@ export async function init (accountId) {
trackEvent(...args);
});

if (window) {
if (window && !isDevelopment()) {
window.addEventListener('error', e => {
trackEvent('Error', 'Uncaught Error');
console.error('Uncaught Error', e);
Expand Down
16 changes: 14 additions & 2 deletions app/common/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,19 @@ export function escapeRegex (str: string): string {
}

export function fuzzyMatch (searchString: string, text: string): boolean {
const regexSearchString = escapeRegex(searchString.toLowerCase()).split('').join('.*');
const toMatch = new RegExp(regexSearchString);
const lowercase = searchString.toLowerCase();

// Split into individual chars, then escape the ones that need it.
const regexSearchString = lowercase.split('').map(v => escapeRegex(v)).join('.*');

let toMatch;
try {
toMatch = new RegExp(regexSearchString);
} catch (err) {
console.warn('Invalid regex', searchString, regexSearchString);
// Invalid regex somehow
return false;
}

return toMatch.test(text.toLowerCase());
}
8 changes: 8 additions & 0 deletions app/main/window-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,14 @@ export function createWindow () {
trackEvent('App Menu', 'Shortcuts');
}
},
{
label: 'Show App Data Folder',
click: (menuItem, window, e) => {
const directory = app.getPath('userData');
shell.showItemInFolder(directory);
trackEvent('App Menu', 'Open App Data');
}
},
{
label: 'Insomnia Help',
accelerator: 'CmdOrCtrl+/',
Expand Down
6 changes: 4 additions & 2 deletions app/models/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ type BaseSettings = {
theme: string,
maxRedirects: number,
disableAnalyticsTracking: boolean,
pluginPath: string
pluginPath: string,
nunjucksPowerUserMode: boolean
};

export type Settings = BaseModel & Settings;
Expand Down Expand Up @@ -51,7 +52,8 @@ export function init (): BaseSettings {
autoHideMenuBar: false,
theme: 'default',
disableAnalyticsTracking: false,
pluginPath: ''
pluginPath: '',
nunjucksPowerUserMode: false
};
}

Expand Down
79 changes: 79 additions & 0 deletions app/network/__tests__/multipart.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import {globalBeforeEach} from '../../__jest__/before-each';
import {buildMultipart} from '../multipart';
import path from 'path';

describe('buildMultipart()', () => {
beforeEach(globalBeforeEach);

it('builds a simple request', async () => {
const {body, boundary} = buildMultipart([
{name: 'foo', value: 'bar'},
{name: 'multi-line', value: 'Hello\nWorld!'}
]);

expect(boundary).toBe('------------------------X-INSOMNIA-BOUNDARY');
expect(body.toString()).toBe([
`--${boundary}`,
'Content-Disposition: form-data; name="foo"',
'',
'bar',
`--${boundary}`,
'Content-Disposition: form-data; name="multi-line"',
'',
'Hello\nWorld!',
`--${boundary}--`,
''
].join('\r\n'));
});

it('builds with file', async () => {
const fileName = path.resolve(path.join(__dirname, './testfile.txt'));
const {body, boundary} = buildMultipart([
{name: 'foo', value: 'bar'},
{name: 'file', type: 'file', fileName: fileName},
{name: 'baz', value: 'qux'}
]);

expect(boundary).toBe('------------------------X-INSOMNIA-BOUNDARY');
expect(body.toString()).toBe([
`--${boundary}`,
'Content-Disposition: form-data; name="foo"',
'',
'bar',
`--${boundary}`,
'Content-Disposition: form-data; name="file"; filename="testfile.txt"',
'Content-Type: text/plain',
'',
'Hello World!\n\nHow are you?',
`--${boundary}`,
'Content-Disposition: form-data; name="baz"',
'',
'qux',
`--${boundary}--`,
''
].join('\r\n'));
});

it('skips entries with no name or value', async () => {
const {body, boundary} = buildMultipart([
{value: 'bar'},
{name: 'foo'},
{name: '', value: ''},
{name: '', type: 'file', fileName: ''}
]);

expect(boundary).toBe('------------------------X-INSOMNIA-BOUNDARY');
expect(body.toString()).toBe([
`--${boundary}`,
'Content-Disposition: form-data; name=""',
'',
'bar',
`--${boundary}`,
'Content-Disposition: form-data; name="foo"',
'',
'',
`--${boundary}--`,
''
].join('\r\n'));
});
});
Loading

0 comments on commit c43c251

Please sign in to comment.