diff --git a/desktop/app/package.json b/desktop/app/package.json index 0d172ad69..8fc7c2020 100644 --- a/desktop/app/package.json +++ b/desktop/app/package.json @@ -68,6 +68,7 @@ }, "devDependencies": { "@testing-library/react": "^10.0.2", + "flipper-test-utils": "0.45.0", "mac-ca": "^1.0.4", "metro": "^0.59.0", "mock-fs": "^4.12.0", diff --git a/desktop/package.json b/desktop/package.json index 25b8d570c..52d9faca1 100644 --- a/desktop/package.json +++ b/desktop/package.json @@ -26,7 +26,8 @@ "static", "plugins/*", "e2e", - "plugin-lib" + "plugin-lib", + "test-utils" ], "nohoist": [ "flipper-plugin-kaios-big-allocations/firefox-client" diff --git a/desktop/pkg/package.json b/desktop/pkg/package.json index 545021a66..315597db8 100644 --- a/desktop/pkg/package.json +++ b/desktop/pkg/package.json @@ -33,6 +33,7 @@ "@types/inquirer": "^6.5.0", "@types/jest": "^25.1.0", "@types/node": "^13.7.5", + "flipper-test-utils": "0.45.0", "globby": "^10", "jest": "^25.1.0", "prettier": "^2.0.0", diff --git a/desktop/pkg/src/__tests__/runInit.node.ts b/desktop/pkg/src/__tests__/runInit.node.ts index d2c2b9560..7096d42c8 100644 --- a/desktop/pkg/src/__tests__/runInit.node.ts +++ b/desktop/pkg/src/__tests__/runInit.node.ts @@ -10,6 +10,7 @@ import fse from 'fs-extra'; import {initTemplate} from '../commands/init'; +import {normalizePath} from 'flipper-test-utils'; let files: Record = {}; @@ -18,7 +19,7 @@ beforeEach(() => { // no implementation } function writeFile(name: string, contents: string) { - files[name.replace(/\\/g, '/')] = contents; + files[normalizePath(name)] = contents; } files = {}; diff --git a/desktop/pkg/tsconfig.json b/desktop/pkg/tsconfig.json index b68777a6a..ff7073f78 100644 --- a/desktop/pkg/tsconfig.json +++ b/desktop/pkg/tsconfig.json @@ -4,7 +4,11 @@ "outDir": "lib", "rootDir": "src" }, - "references": [{"path": "../pkg-lib"}, {"path": "../plugin-lib"}], + "references": [ + {"path": "../pkg-lib"}, + {"path": "../plugin-lib"}, + {"path": "../test-utils"} + ], "include": ["src"], "exclude": ["node_modules", "**/__tests__/*"] } diff --git a/desktop/plugin-lib/package.json b/desktop/plugin-lib/package.json index b75b7314f..354357ed1 100644 --- a/desktop/plugin-lib/package.json +++ b/desktop/plugin-lib/package.json @@ -21,6 +21,7 @@ "@types/fs-extra": "^8.1.0", "@types/jest": "^25.1.0", "@types/node": "^13.7.5", + "flipper-test-utils": "0.45.0", "globby": "^10", "jest": "^25.1.0", "rimraf": "^3.0.2", diff --git a/desktop/plugin-lib/src/__tests__/getPluginDetails.node.ts b/desktop/plugin-lib/src/__tests__/getPluginDetails.node.ts index 63be8a388..82353b4f2 100644 --- a/desktop/plugin-lib/src/__tests__/getPluginDetails.node.ts +++ b/desktop/plugin-lib/src/__tests__/getPluginDetails.node.ts @@ -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; -}; diff --git a/desktop/plugin-lib/tsconfig.json b/desktop/plugin-lib/tsconfig.json index 2fb289f45..875c0ea8f 100644 --- a/desktop/plugin-lib/tsconfig.json +++ b/desktop/plugin-lib/tsconfig.json @@ -4,6 +4,7 @@ "outDir": "lib", "rootDir": "src" }, + "references": [{"path": "../test-utils"}], "include": ["src"], "exclude": ["node_modules", "**/__tests__/*"] } diff --git a/desktop/test-utils/LICENSE b/desktop/test-utils/LICENSE new file mode 100644 index 000000000..b96dcb048 --- /dev/null +++ b/desktop/test-utils/LICENSE @@ -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. diff --git a/desktop/test-utils/README.md b/desktop/test-utils/README.md new file mode 100644 index 000000000..bef50004d --- /dev/null +++ b/desktop/test-utils/README.md @@ -0,0 +1,3 @@ +# flipper-test-utils + +`flipper-test-utils` is a library containing common Flipper test utilities. diff --git a/desktop/test-utils/package.json b/desktop/test-utils/package.json new file mode 100644 index 000000000..2db819618 --- /dev/null +++ b/desktop/test-utils/package.json @@ -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" +} diff --git a/desktop/app/src/__mocks__/console.tsx b/desktop/test-utils/src/consoleMock.ts similarity index 100% rename from desktop/app/src/__mocks__/console.tsx rename to desktop/test-utils/src/consoleMock.ts diff --git a/desktop/test-utils/src/index.ts b/desktop/test-utils/src/index.ts new file mode 100644 index 000000000..fae07300a --- /dev/null +++ b/desktop/test-utils/src/index.ts @@ -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'; diff --git a/desktop/test-utils/src/pathUtils.ts b/desktop/test-utils/src/pathUtils.ts new file mode 100644 index 000000000..a6ab0538f --- /dev/null +++ b/desktop/test-utils/src/pathUtils.ts @@ -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; +} diff --git a/desktop/test-utils/tsconfig.json b/desktop/test-utils/tsconfig.json new file mode 100644 index 000000000..2fb289f45 --- /dev/null +++ b/desktop/test-utils/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../tsconfig.base.json", + "compilerOptions": { + "outDir": "lib", + "rootDir": "src" + }, + "include": ["src"], + "exclude": ["node_modules", "**/__tests__/*"] +}