Files
flipper/desktop/plugin-lib/src/__tests__/getPluginDetails.node.ts
Anton Nikolaev 907cb9e3cc Read description from plugin's package json
Summary: Added "description" field to PluginDetails interface and read it from package.json

Reviewed By: passy

Differential Revision: D21927391

fbshipit-source-id: 0513637d3afa3d8be8e2bc8ee87cc1d77c5e2250
2020-06-08 08:57:07 -07:00

141 lines
4.3 KiB
TypeScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
import fs from 'fs-extra';
import getPluginDetails from '../getPluginDetails';
test('getPluginDetailsV1', async () => {
const pluginV1 = {
name: 'flipper-plugin-test',
version: '2.0.0',
title: 'Test Plugin',
main: 'src/index.tsx',
description: 'Description of Test Plugin',
gatekeeper: 'GK_flipper_plugin_test',
};
jest.mock('fs-extra', () => jest.fn());
fs.readJson = jest.fn().mockImplementation(() => pluginV1);
const details = await getPluginDetails('./plugins/flipper-plugin-test');
expect(details).toMatchInlineSnapshot(`
Object {
"bugs": undefined,
"category": undefined,
"description": "Description of Test Plugin",
"dir": "./plugins/flipper-plugin-test",
"gatekeeper": "GK_flipper_plugin_test",
"icon": undefined,
"id": "flipper-plugin-test",
"main": "dist/bundle.js",
"name": "flipper-plugin-test",
"source": "src/index.tsx",
"specVersion": 1,
"title": "Test Plugin",
"version": "2.0.0",
}
`);
});
test('getPluginDetailsV2', async () => {
const pluginV2 = {
$schema: 'https://fbflipper.com/schemas/plugin-package/v2.json',
name: 'flipper-plugin-test',
title: 'Test',
version: '3.0.1',
main: 'dist/bundle.js',
flipperBundlerEntry: 'src/index.tsx',
description: 'Description of Test Plugin',
gatekeeper: 'GK_flipper_plugin_test',
};
jest.mock('fs-extra', () => jest.fn());
fs.readJson = jest.fn().mockImplementation(() => pluginV2);
const details = await getPluginDetails('./plugins/flipper-plugin-test');
expect(details).toMatchInlineSnapshot(`
Object {
"bugs": undefined,
"category": undefined,
"description": "Description of Test Plugin",
"dir": "./plugins/flipper-plugin-test",
"gatekeeper": "GK_flipper_plugin_test",
"icon": undefined,
"id": "flipper-plugin-test",
"main": "dist/bundle.js",
"name": "flipper-plugin-test",
"source": "src/index.tsx",
"specVersion": 2,
"title": "Test",
"version": "3.0.1",
}
`);
});
test('id used as title if the latter omited', async () => {
const pluginV2 = {
$schema: 'https://fbflipper.com/schemas/plugin-package/v2.json',
name: 'flipper-plugin-test',
id: 'test',
version: '3.0.1',
main: 'dist/bundle.js',
flipperBundlerEntry: 'src/index.tsx',
description: 'Description of Test Plugin',
gatekeeper: 'GK_flipper_plugin_test',
};
jest.mock('fs-extra', () => jest.fn());
fs.readJson = jest.fn().mockImplementation(() => pluginV2);
const details = await getPluginDetails('./plugins/flipper-plugin-test');
expect(details).toMatchInlineSnapshot(`
Object {
"bugs": undefined,
"category": undefined,
"description": "Description of Test Plugin",
"dir": "./plugins/flipper-plugin-test",
"gatekeeper": "GK_flipper_plugin_test",
"icon": undefined,
"id": "test",
"main": "dist/bundle.js",
"name": "flipper-plugin-test",
"source": "src/index.tsx",
"specVersion": 2,
"title": "test",
"version": "3.0.1",
}
`);
});
test('name without "flipper-plugin-" prefix is used as title if the latter omited', async () => {
const pluginV2 = {
$schema: 'https://fbflipper.com/schemas/plugin-package/v2.json',
name: 'flipper-plugin-test',
version: '3.0.1',
main: 'dist/bundle.js',
flipperBundlerEntry: 'src/index.tsx',
description: 'Description of Test Plugin',
gatekeeper: 'GK_flipper_plugin_test',
};
jest.mock('fs-extra', () => jest.fn());
fs.readJson = jest.fn().mockImplementation(() => pluginV2);
const details = await getPluginDetails('./plugins/flipper-plugin-test');
expect(details).toMatchInlineSnapshot(`
Object {
"bugs": undefined,
"category": undefined,
"description": "Description of Test Plugin",
"dir": "./plugins/flipper-plugin-test",
"gatekeeper": "GK_flipper_plugin_test",
"icon": undefined,
"id": "flipper-plugin-test",
"main": "dist/bundle.js",
"name": "flipper-plugin-test",
"source": "src/index.tsx",
"specVersion": 2,
"title": "test",
"version": "3.0.1",
}
`);
});