Added module for test-utilities used across all packages

Summary: Added new package with test utilities re-used by other packages

Reviewed By: mweststrate

Differential Revision: D21949629

fbshipit-source-id: 8bfa959401669dc8911a1f647f417cafd92c2e4b
This commit is contained in:
Anton Nikolaev
2020-06-09 04:52:39 -07:00
committed by Facebook GitHub Bot
parent eeded4e32f
commit d27fa34505
15 changed files with 106 additions and 19 deletions

View File

@@ -11,6 +11,7 @@ import fs from 'fs-extra';
import path from 'path';
import getPluginDetails from '../getPluginDetails';
import {pluginInstallationDir} from '../pluginPaths';
import {normalizePath} from 'flipper-test-utils';
jest.mock('../pluginPaths', () => ({
pluginInstallationDir: '/Users/mock/.flipper/thirdparty',
@@ -31,8 +32,8 @@ test('getPluginDetailsV1', async () => {
jest.mock('fs-extra', () => jest.fn());
fs.readJson = jest.fn().mockImplementation(() => pluginV1);
const details = await getPluginDetails(pluginPath);
details.dir = normalizeOnWindows(details.dir);
details.entry = normalizeOnWindows(details.entry);
details.dir = normalizePath(details.dir);
details.entry = normalizePath(details.entry);
expect(details).toMatchInlineSnapshot(`
Object {
"bugs": undefined,
@@ -68,8 +69,8 @@ test('getPluginDetailsV2', async () => {
jest.mock('fs-extra', () => jest.fn());
fs.readJson = jest.fn().mockImplementation(() => pluginV2);
const details = await getPluginDetails(pluginPath);
details.dir = normalizeOnWindows(details.dir);
details.entry = normalizeOnWindows(details.entry);
details.dir = normalizePath(details.dir);
details.entry = normalizePath(details.entry);
expect(details).toMatchInlineSnapshot(`
Object {
"bugs": undefined,
@@ -105,8 +106,8 @@ test('id used as title if the latter omited', async () => {
jest.mock('fs-extra', () => jest.fn());
fs.readJson = jest.fn().mockImplementation(() => pluginV2);
const details = await getPluginDetails(pluginPath);
details.dir = normalizeOnWindows(details.dir);
details.entry = normalizeOnWindows(details.entry);
details.dir = normalizePath(details.dir);
details.entry = normalizePath(details.entry);
expect(details).toMatchInlineSnapshot(`
Object {
"bugs": undefined,
@@ -141,8 +142,8 @@ test('name without "flipper-plugin-" prefix is used as title if the latter omite
jest.mock('fs-extra', () => jest.fn());
fs.readJson = jest.fn().mockImplementation(() => pluginV2);
const details = await getPluginDetails(pluginPath);
details.dir = normalizeOnWindows(details.dir);
details.entry = normalizeOnWindows(details.entry);
details.dir = normalizePath(details.dir);
details.entry = normalizePath(details.entry);
expect(details).toMatchInlineSnapshot(`
Object {
"bugs": undefined,
@@ -163,11 +164,3 @@ test('name without "flipper-plugin-" prefix is used as title if the latter omite
}
`);
});
const normalizeOnWindows = (path: string): string => {
if (process.platform === 'win32') {
path = path.replace(/\\/g, '/');
path = path.substring(path.indexOf('/'));
}
return path;
};