Skip to content

Commit

Permalink
making exports git friendly (#1409)
Browse files Browse the repository at this point in the history
As YAML supports multi line content, each line of requests' body will
appear in separate line when exported. Hence, making the exports git
friendly.
  • Loading branch information
everplays authored and gschier committed Apr 18, 2019
1 parent 6b24456 commit 86860e4
Show file tree
Hide file tree
Showing 60 changed files with 197 additions and 14,015 deletions.
9 changes: 5 additions & 4 deletions packages/insomnia-app/app/common/__tests__/import.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as models from '../../models';
import * as importUtil from '../import';
import { getAppVersion } from '../constants';
import { globalBeforeEach } from '../../__jest__/before-each';
import YAML from 'yaml';

describe('exportHAR()', () => {
beforeEach(globalBeforeEach);
Expand Down Expand Up @@ -156,7 +157,7 @@ describe('exportHAR()', () => {
});
});

describe('exportJSON()', () => {
describe('exportYAML()', () => {
beforeEach(globalBeforeEach);
it('exports all workspaces', async () => {
const w = await models.workspace.create({ name: 'Workspace' });
Expand All @@ -176,11 +177,11 @@ describe('exportJSON()', () => {
parentId: eBase._id,
});

const json = await importUtil.exportJSON();
const data = JSON.parse(json);
const yaml = await importUtil.exportYAML();
const data = YAML.parse(yaml);

expect(data._type).toBe('export');
expect(data.__export_format).toBe(3);
expect(data.__export_format).toBe(4);
expect(data.__export_date).toMatch(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/);
expect(data.__export_source).toBe(`insomnia.desktop.app:v${getAppVersion()}`);
expect(data.resources[0]._id).toBe(w._id);
Expand Down
7 changes: 4 additions & 3 deletions packages/insomnia-app/app/common/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import fs from 'fs';
import type { Workspace } from '../models/workspace';
import type { Environment } from '../models/environment';
import { fnOrString, generateId } from './misc';
import YAML from 'yaml';

const EXPORT_FORMAT = 3;
const EXPORT_FORMAT = 4;

const EXPORT_TYPE_REQUEST = 'request';
const EXPORT_TYPE_REQUEST_GROUP = 'request_group';
Expand Down Expand Up @@ -230,7 +231,7 @@ export async function exportHAR(
return JSON.stringify(data, null, '\t');
}

export async function exportJSON(
export async function exportYAML(
parentDoc: BaseModel | null = null,
includePrivateDocs: boolean = false,
): Promise<string> {
Expand Down Expand Up @@ -272,7 +273,7 @@ export async function exportJSON(
return d;
});

return JSON.stringify(data, null, '\t');
return YAML.stringify(data);
}

async function getDocWithDescendants(
Expand Down
4 changes: 2 additions & 2 deletions packages/insomnia-app/app/plugins/context/data.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @flow
import { exportHAR, exportJSON, importRaw, importUri } from '../../common/import';
import { exportHAR, exportYAML, importRaw, importUri } from '../../common/import';

export function init(): { import: Object, export: Object } {
return {
Expand All @@ -14,7 +14,7 @@ export function init(): { import: Object, export: Object } {
export: {
async insomnia(options: { includePrivate?: boolean } = {}): Promise<string> {
options = options || {};
return exportJSON(null, options.includePrivate);
return exportYAML(null, options.includePrivate);
},
async har(options: { includePrivate?: boolean } = {}): Promise<string> {
return exportHAR(null, options.includePrivate);
Expand Down
8 changes: 4 additions & 4 deletions packages/insomnia-app/app/ui/redux/modules/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,15 @@ export function exportFile(workspaceId = null) {
return dispatch => {
dispatch(loadStart());

const VALUE_JSON = 'json';
const VALUE_YAML = 'yaml';
const VALUE_HAR = 'har';

showModal(SelectModal, {
title: 'Select Export Type',
options: [
{
name: 'Insomnia – Sharable with other Insomnia users',
value: VALUE_JSON,
value: VALUE_YAML,
},
{ name: 'HAR – HTTP Archive Format', value: VALUE_HAR },
],
Expand Down Expand Up @@ -251,7 +251,7 @@ export function exportFile(workspaceId = null) {
},
];
} else {
options.filters = [{ name: 'Insomnia Export', extensions: ['json'] }];
options.filters = [{ name: 'Insomnia Export', extensions: ['yaml'] }];
}

electron.remote.dialog.showSaveDialog(options, async filename => {
Expand All @@ -266,7 +266,7 @@ export function exportFile(workspaceId = null) {
if (selectedFormat === VALUE_HAR) {
json = await importUtils.exportHAR(workspace, exportPrivateEnvironments);
} else {
json = await importUtils.exportJSON(workspace, exportPrivateEnvironments);
json = await importUtils.exportYAML(workspace, exportPrivateEnvironments);
}
} catch (err) {
showError({
Expand Down
Loading

0 comments on commit 86860e4

Please sign in to comment.