mirror of
https://github.com/Kong/insomnia.git
synced 2026-04-20 22:27:24 -04:00
Add plugin bundle to default config (#3092)
This commit is contained in:
@@ -3,6 +3,8 @@ import { containsOnlyDeprecationWarnings, isDeprecatedDependencies } from '../pl
|
||||
describe('install.js', () => {
|
||||
describe('containsOnlyDeprecationWarning', () => {
|
||||
it('should return true when all lines in stderr are deprecation warnings', () => {
|
||||
const consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
|
||||
|
||||
const stderr =
|
||||
// Warning #1
|
||||
'warning insomnia-plugin-xxx-yyy > xyz > xyz > xyz > xyz > xyz: ' +
|
||||
@@ -17,8 +19,11 @@ describe('install.js', () => {
|
||||
'xyz is no longer maintained and not recommended for usage due to the number of issues. ' +
|
||||
'Please, upgrade your dependencies to the actual version of xyz.';
|
||||
expect(containsOnlyDeprecationWarnings(stderr)).toBe(true);
|
||||
expect(consoleWarnSpy).toHaveBeenCalledTimes(3);
|
||||
});
|
||||
it('should return false when stderr contains a deprecation warning and an error', () => {
|
||||
const consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
|
||||
|
||||
const stderr =
|
||||
// Warning #1
|
||||
'warning insomnia-plugin-xxx-yyy > xyz > xyz > xyz > xyz > xyz: ' +
|
||||
@@ -33,6 +38,7 @@ describe('install.js', () => {
|
||||
'xyz is no longer maintained and not recommended for usage due to the number of issues. ' +
|
||||
'Please, upgrade your dependencies to the actual version of xyz.';
|
||||
expect(containsOnlyDeprecationWarnings(stderr)).toBe(false);
|
||||
expect(consoleWarnSpy).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
});
|
||||
describe('isDeprecatedDependencies', () => {
|
||||
|
||||
@@ -43,6 +43,8 @@ describe('LocalStorage()', () => {
|
||||
});
|
||||
|
||||
it('does handles malformed files', () => {
|
||||
const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
||||
|
||||
const basePath = `/tmp/insomnia-localstorage-${Math.random()}`;
|
||||
const localStorage = new LocalStorage(basePath);
|
||||
|
||||
@@ -53,9 +55,12 @@ describe('LocalStorage()', () => {
|
||||
// Assert that writing our file actually works
|
||||
fs.writeFileSync(path.join(basePath, 'key'), '{"good": "JSON"}');
|
||||
expect(localStorage.getItem('key', 'default')).toEqual({ good: 'JSON' });
|
||||
expect(consoleErrorSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('does handles failing to write file', () => {
|
||||
const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
||||
|
||||
const basePath = `/tmp/insomnia-localstorage-${Math.random()}`;
|
||||
const localStorage = new LocalStorage(basePath);
|
||||
fs.rmdirSync(basePath);
|
||||
@@ -66,6 +71,7 @@ describe('LocalStorage()', () => {
|
||||
// Since the above operation failed to write, we should now get back
|
||||
// the default value
|
||||
expect(localStorage.getItem('key', 'different')).toBe('different');
|
||||
expect(consoleErrorSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('stores a key', () => {
|
||||
|
||||
@@ -103,6 +103,15 @@ async function migratePlugins(designerDataDir: string, coreDataDir: string) {
|
||||
|
||||
await removeDirs(designerPlugins, corePluginDir);
|
||||
await copyDirs(designerPlugins, designerPluginDir, corePluginDir);
|
||||
|
||||
// Remove plugin bundle from installed plugins because it's included with the app now
|
||||
const pluginsToDelete = [
|
||||
'insomnia-plugin-kong-bundle',
|
||||
'insomnia-plugin-kong-declarative-config',
|
||||
'insomnia-plugin-kong-kubernetes-config',
|
||||
'insomnia-plugin-kong-portal',
|
||||
];
|
||||
await removeDirs(pluginsToDelete, corePluginDir);
|
||||
}
|
||||
|
||||
async function readDirs(srcDir: string): Array<string> {
|
||||
|
||||
@@ -2,6 +2,7 @@ import * as db from './database';
|
||||
import { types as modelTypes, stats } from '../models';
|
||||
import { send } from '../network/network';
|
||||
import { getBodyBuffer } from '../models/response';
|
||||
import * as plugins from '../plugins';
|
||||
|
||||
export async function getSendRequestCallbackMemDb(environmentId, memDB) {
|
||||
// Initialize the DB in-memory and fill it with data if we're given one
|
||||
@@ -30,19 +31,24 @@ export function getSendRequestCallback(environmentId) {
|
||||
}
|
||||
|
||||
async function sendAndTransform(requestId, environmentId) {
|
||||
const res = await send(requestId, environmentId);
|
||||
const headersObj = {};
|
||||
for (const h of res.headers || []) {
|
||||
const name = h.name || '';
|
||||
headersObj[name.toLowerCase()] = h.value || '';
|
||||
try {
|
||||
plugins.ignorePlugin('insomnia-plugin-kong-bundle');
|
||||
const res = await send(requestId, environmentId);
|
||||
const headersObj = {};
|
||||
for (const h of res.headers || []) {
|
||||
const name = h.name || '';
|
||||
headersObj[name.toLowerCase()] = h.value || '';
|
||||
}
|
||||
|
||||
const bodyBuffer = await getBodyBuffer(res);
|
||||
|
||||
return {
|
||||
status: res.statusCode,
|
||||
statusMessage: res.statusMessage,
|
||||
data: bodyBuffer ? bodyBuffer.toString('utf8') : undefined,
|
||||
headers: headersObj,
|
||||
};
|
||||
} finally {
|
||||
plugins.clearIgnores();
|
||||
}
|
||||
|
||||
const bodyBuffer = await getBodyBuffer(res);
|
||||
|
||||
return {
|
||||
status: res.statusCode,
|
||||
statusMessage: res.statusMessage,
|
||||
data: bodyBuffer ? bodyBuffer.toString('utf8') : undefined,
|
||||
headers: headersObj,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ export async function migrate(doc: Object) {
|
||||
}
|
||||
|
||||
export function hookDatabaseInit(consoleLog: () => void = console.log) {
|
||||
consoleLog('Init responses DB');
|
||||
consoleLog('[db] Init responses DB');
|
||||
process.nextTick(async () => {
|
||||
await models.response.cleanDeletedResponses();
|
||||
});
|
||||
|
||||
@@ -110,12 +110,17 @@ describe('request.*', () => {
|
||||
});
|
||||
|
||||
it('works for basic getters', async () => {
|
||||
const consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
|
||||
|
||||
const result = plugin.init(await models.request.getById('req_1'), CONTEXT);
|
||||
expect(result.request.getId()).toBe('req_1');
|
||||
expect(result.request.getName()).toBe('My Request');
|
||||
expect(result.request.getUrl()).toBe('');
|
||||
expect(result.request.getMethod()).toBe('GET');
|
||||
expect(result.request.getBodyText()).toBe('body');
|
||||
expect(consoleWarnSpy).toHaveBeenCalledWith(
|
||||
'request.getBodyText() is deprecated. Use request.getBody() instead.',
|
||||
);
|
||||
expect(result.request.getAuthentication()).toEqual({ type: 'oauth2' });
|
||||
});
|
||||
|
||||
|
||||
@@ -105,10 +105,23 @@ export type Theme = {
|
||||
|
||||
let plugins: ?Array<Plugin> = null;
|
||||
|
||||
let ignorePlugins: Array<string> = [];
|
||||
|
||||
export async function init(): Promise<void> {
|
||||
clearIgnores();
|
||||
await reloadPlugins();
|
||||
}
|
||||
|
||||
export function ignorePlugin(name: string) {
|
||||
if (!ignorePlugins.includes(name)) {
|
||||
ignorePlugins.push(name);
|
||||
}
|
||||
}
|
||||
|
||||
export function clearIgnores() {
|
||||
ignorePlugins = [];
|
||||
}
|
||||
|
||||
async function _traversePluginPath(
|
||||
pluginMap: Object,
|
||||
allPaths: Array<string>,
|
||||
@@ -201,7 +214,13 @@ export async function getPlugins(force: boolean = false): Promise<Array<Plugin>>
|
||||
};
|
||||
|
||||
for (const p of appConfig().plugins) {
|
||||
if (ignorePlugins.includes(p)) {
|
||||
continue;
|
||||
}
|
||||
const pluginJson = global.require(`${p}/package.json`);
|
||||
if (ignorePlugins.includes(pluginJson.name)) {
|
||||
continue;
|
||||
}
|
||||
const pluginModule = global.require(p);
|
||||
pluginMap[pluginJson.name] = _initPlugin(pluginJson, pluginModule, allConfigs);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import nunjucks from 'nunjucks';
|
||||
import BaseExtension from './base-extension';
|
||||
import type { NunjucksParsedTag } from './utils';
|
||||
import * as plugins from '../plugins/index';
|
||||
import type { TemplateTag } from '../plugins/index';
|
||||
|
||||
export class RenderError extends Error {
|
||||
message: string;
|
||||
@@ -152,7 +153,14 @@ async function getNunjucks(renderMode: string) {
|
||||
|
||||
const nj = nunjucks.configure(config);
|
||||
|
||||
const allTemplateTagPlugins = await plugins.getTemplateTags();
|
||||
let allTemplateTagPlugins: Array<TemplateTag>;
|
||||
try {
|
||||
plugins.ignorePlugin('insomnia-plugin-kong-bundle');
|
||||
allTemplateTagPlugins = await plugins.getTemplateTags();
|
||||
} finally {
|
||||
plugins.clearIgnores();
|
||||
}
|
||||
|
||||
const allExtensions = allTemplateTagPlugins;
|
||||
for (let i = 0; i < allExtensions.length; i++) {
|
||||
const { templateTag, plugin } = allExtensions[i];
|
||||
|
||||
@@ -105,8 +105,11 @@ class DocumentCardDropdown extends React.PureComponent<Props, State> {
|
||||
}
|
||||
|
||||
async _onOpen() {
|
||||
const plugins = await getDocumentActions();
|
||||
this.setState({ actionPlugins: plugins });
|
||||
// Only load document plugins if the scope is designer, for now
|
||||
if (this.props.workspace.scope === 'designer') {
|
||||
const plugins = await getDocumentActions();
|
||||
this.setState({ actionPlugins: plugins });
|
||||
}
|
||||
}
|
||||
|
||||
async _handlePluginClick(p: DocumentAction) {
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
"insomnia-plugin-response",
|
||||
"insomnia-plugin-jsonpath",
|
||||
"insomnia-plugin-cookie-jar",
|
||||
"insomnia-plugin-core-themes"
|
||||
"insomnia-plugin-core-themes",
|
||||
"insomnia-plugin-kong-bundle"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -131,6 +131,7 @@
|
||||
"insomnia-plugin-file": "^2.2.24",
|
||||
"insomnia-plugin-hash": "^2.2.24",
|
||||
"insomnia-plugin-jsonpath": "^2.2.24",
|
||||
"insomnia-plugin-kong-bundle": "^2.2.26",
|
||||
"insomnia-plugin-now": "^2.2.24",
|
||||
"insomnia-plugin-os": "^2.2.24",
|
||||
"insomnia-plugin-prompt": "^2.2.24",
|
||||
|
||||
Reference in New Issue
Block a user