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:
committed by
Facebook GitHub Bot
parent
eeded4e32f
commit
d27fa34505
@@ -68,6 +68,7 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@testing-library/react": "^10.0.2",
|
"@testing-library/react": "^10.0.2",
|
||||||
|
"flipper-test-utils": "0.45.0",
|
||||||
"mac-ca": "^1.0.4",
|
"mac-ca": "^1.0.4",
|
||||||
"metro": "^0.59.0",
|
"metro": "^0.59.0",
|
||||||
"mock-fs": "^4.12.0",
|
"mock-fs": "^4.12.0",
|
||||||
|
|||||||
@@ -26,7 +26,8 @@
|
|||||||
"static",
|
"static",
|
||||||
"plugins/*",
|
"plugins/*",
|
||||||
"e2e",
|
"e2e",
|
||||||
"plugin-lib"
|
"plugin-lib",
|
||||||
|
"test-utils"
|
||||||
],
|
],
|
||||||
"nohoist": [
|
"nohoist": [
|
||||||
"flipper-plugin-kaios-big-allocations/firefox-client"
|
"flipper-plugin-kaios-big-allocations/firefox-client"
|
||||||
|
|||||||
@@ -33,6 +33,7 @@
|
|||||||
"@types/inquirer": "^6.5.0",
|
"@types/inquirer": "^6.5.0",
|
||||||
"@types/jest": "^25.1.0",
|
"@types/jest": "^25.1.0",
|
||||||
"@types/node": "^13.7.5",
|
"@types/node": "^13.7.5",
|
||||||
|
"flipper-test-utils": "0.45.0",
|
||||||
"globby": "^10",
|
"globby": "^10",
|
||||||
"jest": "^25.1.0",
|
"jest": "^25.1.0",
|
||||||
"prettier": "^2.0.0",
|
"prettier": "^2.0.0",
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
import fse from 'fs-extra';
|
import fse from 'fs-extra';
|
||||||
|
|
||||||
import {initTemplate} from '../commands/init';
|
import {initTemplate} from '../commands/init';
|
||||||
|
import {normalizePath} from 'flipper-test-utils';
|
||||||
|
|
||||||
let files: Record<string, string> = {};
|
let files: Record<string, string> = {};
|
||||||
|
|
||||||
@@ -18,7 +19,7 @@ beforeEach(() => {
|
|||||||
// no implementation
|
// no implementation
|
||||||
}
|
}
|
||||||
function writeFile(name: string, contents: string) {
|
function writeFile(name: string, contents: string) {
|
||||||
files[name.replace(/\\/g, '/')] = contents;
|
files[normalizePath(name)] = contents;
|
||||||
}
|
}
|
||||||
|
|
||||||
files = {};
|
files = {};
|
||||||
|
|||||||
@@ -4,7 +4,11 @@
|
|||||||
"outDir": "lib",
|
"outDir": "lib",
|
||||||
"rootDir": "src"
|
"rootDir": "src"
|
||||||
},
|
},
|
||||||
"references": [{"path": "../pkg-lib"}, {"path": "../plugin-lib"}],
|
"references": [
|
||||||
|
{"path": "../pkg-lib"},
|
||||||
|
{"path": "../plugin-lib"},
|
||||||
|
{"path": "../test-utils"}
|
||||||
|
],
|
||||||
"include": ["src"],
|
"include": ["src"],
|
||||||
"exclude": ["node_modules", "**/__tests__/*"]
|
"exclude": ["node_modules", "**/__tests__/*"]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
"@types/fs-extra": "^8.1.0",
|
"@types/fs-extra": "^8.1.0",
|
||||||
"@types/jest": "^25.1.0",
|
"@types/jest": "^25.1.0",
|
||||||
"@types/node": "^13.7.5",
|
"@types/node": "^13.7.5",
|
||||||
|
"flipper-test-utils": "0.45.0",
|
||||||
"globby": "^10",
|
"globby": "^10",
|
||||||
"jest": "^25.1.0",
|
"jest": "^25.1.0",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import fs from 'fs-extra';
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import getPluginDetails from '../getPluginDetails';
|
import getPluginDetails from '../getPluginDetails';
|
||||||
import {pluginInstallationDir} from '../pluginPaths';
|
import {pluginInstallationDir} from '../pluginPaths';
|
||||||
|
import {normalizePath} from 'flipper-test-utils';
|
||||||
|
|
||||||
jest.mock('../pluginPaths', () => ({
|
jest.mock('../pluginPaths', () => ({
|
||||||
pluginInstallationDir: '/Users/mock/.flipper/thirdparty',
|
pluginInstallationDir: '/Users/mock/.flipper/thirdparty',
|
||||||
@@ -31,8 +32,8 @@ test('getPluginDetailsV1', async () => {
|
|||||||
jest.mock('fs-extra', () => jest.fn());
|
jest.mock('fs-extra', () => jest.fn());
|
||||||
fs.readJson = jest.fn().mockImplementation(() => pluginV1);
|
fs.readJson = jest.fn().mockImplementation(() => pluginV1);
|
||||||
const details = await getPluginDetails(pluginPath);
|
const details = await getPluginDetails(pluginPath);
|
||||||
details.dir = normalizeOnWindows(details.dir);
|
details.dir = normalizePath(details.dir);
|
||||||
details.entry = normalizeOnWindows(details.entry);
|
details.entry = normalizePath(details.entry);
|
||||||
expect(details).toMatchInlineSnapshot(`
|
expect(details).toMatchInlineSnapshot(`
|
||||||
Object {
|
Object {
|
||||||
"bugs": undefined,
|
"bugs": undefined,
|
||||||
@@ -68,8 +69,8 @@ test('getPluginDetailsV2', async () => {
|
|||||||
jest.mock('fs-extra', () => jest.fn());
|
jest.mock('fs-extra', () => jest.fn());
|
||||||
fs.readJson = jest.fn().mockImplementation(() => pluginV2);
|
fs.readJson = jest.fn().mockImplementation(() => pluginV2);
|
||||||
const details = await getPluginDetails(pluginPath);
|
const details = await getPluginDetails(pluginPath);
|
||||||
details.dir = normalizeOnWindows(details.dir);
|
details.dir = normalizePath(details.dir);
|
||||||
details.entry = normalizeOnWindows(details.entry);
|
details.entry = normalizePath(details.entry);
|
||||||
expect(details).toMatchInlineSnapshot(`
|
expect(details).toMatchInlineSnapshot(`
|
||||||
Object {
|
Object {
|
||||||
"bugs": undefined,
|
"bugs": undefined,
|
||||||
@@ -105,8 +106,8 @@ test('id used as title if the latter omited', async () => {
|
|||||||
jest.mock('fs-extra', () => jest.fn());
|
jest.mock('fs-extra', () => jest.fn());
|
||||||
fs.readJson = jest.fn().mockImplementation(() => pluginV2);
|
fs.readJson = jest.fn().mockImplementation(() => pluginV2);
|
||||||
const details = await getPluginDetails(pluginPath);
|
const details = await getPluginDetails(pluginPath);
|
||||||
details.dir = normalizeOnWindows(details.dir);
|
details.dir = normalizePath(details.dir);
|
||||||
details.entry = normalizeOnWindows(details.entry);
|
details.entry = normalizePath(details.entry);
|
||||||
expect(details).toMatchInlineSnapshot(`
|
expect(details).toMatchInlineSnapshot(`
|
||||||
Object {
|
Object {
|
||||||
"bugs": undefined,
|
"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());
|
jest.mock('fs-extra', () => jest.fn());
|
||||||
fs.readJson = jest.fn().mockImplementation(() => pluginV2);
|
fs.readJson = jest.fn().mockImplementation(() => pluginV2);
|
||||||
const details = await getPluginDetails(pluginPath);
|
const details = await getPluginDetails(pluginPath);
|
||||||
details.dir = normalizeOnWindows(details.dir);
|
details.dir = normalizePath(details.dir);
|
||||||
details.entry = normalizeOnWindows(details.entry);
|
details.entry = normalizePath(details.entry);
|
||||||
expect(details).toMatchInlineSnapshot(`
|
expect(details).toMatchInlineSnapshot(`
|
||||||
Object {
|
Object {
|
||||||
"bugs": undefined,
|
"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;
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
"outDir": "lib",
|
"outDir": "lib",
|
||||||
"rootDir": "src"
|
"rootDir": "src"
|
||||||
},
|
},
|
||||||
|
"references": [{"path": "../test-utils"}],
|
||||||
"include": ["src"],
|
"include": ["src"],
|
||||||
"exclude": ["node_modules", "**/__tests__/*"]
|
"exclude": ["node_modules", "**/__tests__/*"]
|
||||||
}
|
}
|
||||||
|
|||||||
21
desktop/test-utils/LICENSE
Normal file
21
desktop/test-utils/LICENSE
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
3
desktop/test-utils/README.md
Normal file
3
desktop/test-utils/README.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# flipper-test-utils
|
||||||
|
|
||||||
|
`flipper-test-utils` is a library containing common Flipper test utilities.
|
||||||
24
desktop/test-utils/package.json
Normal file
24
desktop/test-utils/package.json
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"name": "flipper-test-utils",
|
||||||
|
"version": "0.45.0",
|
||||||
|
"description": "Library containing common Flipper test utilities",
|
||||||
|
"repository": "facebook/flipper",
|
||||||
|
"main": "lib/index.js",
|
||||||
|
"flipperBundlerEntry": "src",
|
||||||
|
"types": "lib/index.d.ts",
|
||||||
|
"license": "MIT",
|
||||||
|
"bugs": "https://github.com/facebook/flipper/issues",
|
||||||
|
"scripts": {
|
||||||
|
"reset": "rimraf lib *.tsbuildinfo",
|
||||||
|
"build": "tsc -b",
|
||||||
|
"prepack": "yarn reset && yarn build"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"lib/**/*"
|
||||||
|
],
|
||||||
|
"homepage": "https://github.com/facebook/flipper",
|
||||||
|
"keywords": [
|
||||||
|
"Flipper"
|
||||||
|
],
|
||||||
|
"author": "Facebook, Inc"
|
||||||
|
}
|
||||||
11
desktop/test-utils/src/index.ts
Normal file
11
desktop/test-utils/src/index.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
|
||||||
|
export * from './pathUtils';
|
||||||
|
export {default as consoleMock} from './consoleMock';
|
||||||
16
desktop/test-utils/src/pathUtils.ts
Normal file
16
desktop/test-utils/src/pathUtils.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
|
||||||
|
export function normalizePath(path: string): string {
|
||||||
|
if (process.platform === 'win32') {
|
||||||
|
path = path.replace(/\\/g, '/');
|
||||||
|
path = path.substring(path.indexOf('/'));
|
||||||
|
}
|
||||||
|
return path;
|
||||||
|
}
|
||||||
9
desktop/test-utils/tsconfig.json
Normal file
9
desktop/test-utils/tsconfig.json
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"extends": "../tsconfig.base.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"outDir": "lib",
|
||||||
|
"rootDir": "src"
|
||||||
|
},
|
||||||
|
"include": ["src"],
|
||||||
|
"exclude": ["node_modules", "**/__tests__/*"]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user