From 3f794c3a71f939502bf0d1efa7c87447d817d612 Mon Sep 17 00:00:00 2001 From: JoseLion Date: Sat, 29 Jun 2024 03:31:50 -0500 Subject: [PATCH] Move register files to a single TS --- package.json | 10 ++++------ register.cjs | 13 ------------- register.js | 16 ---------------- src/load.ts | 36 ++++++++++++++++++++++++++++++++++++ src/register.ts | 45 ++++++++++++--------------------------------- vite.config.ts | 1 + vitest.config.ts | 2 +- 7 files changed, 54 insertions(+), 69 deletions(-) delete mode 100644 register.cjs delete mode 100644 register.js create mode 100644 src/load.ts diff --git a/package.json b/package.json index c4a1a7b..a47ccb0 100644 --- a/package.json +++ b/package.json @@ -27,19 +27,17 @@ "default": "./dist/main.js" }, "./register": { - "import": "./register.js", - "require": "./register.cjs", + "import": "./dist/register.js", + "require": "./dist/register.cjs", "types": "./dist/register.d.ts", - "default": "./register.js" + "default": "./dist/register.js" }, "./package.json": "./package.json" }, "files": [ "./dist", "./src/", - "./package.json", - "./register.cjs", - "./register.js" + "./package.json" ], "engines": { "node": ">=18" diff --git a/register.cjs b/register.cjs deleted file mode 100644 index ddf2d41..0000000 --- a/register.cjs +++ /dev/null @@ -1,13 +0,0 @@ -// @ts-check -const pino = require("pino").default; -const pinoPretty = require("pino-pretty").default; - -const start = Date.now(); -const logger = pino(pinoPretty({ colorize: true })); - -require("./dist/register.cjs"); - -const end = Date.now(); -const diff = (end - start) / 1000; - -logger.info(`React Native testing mocks registered! (${diff}s)`); diff --git a/register.js b/register.js deleted file mode 100644 index 8dfa0c7..0000000 --- a/register.js +++ /dev/null @@ -1,16 +0,0 @@ -// @ts-check -import { createRequire } from "module"; - -import pino from "pino"; -import pinoPretty from "pino-pretty"; - -const start = Date.now(); -const logger = pino(pinoPretty({ colorize: true })); -const require = createRequire(import.meta.url); - -require("./dist/register.cjs"); - -const end = Date.now(); -const diff = (end - start) / 1000; - -logger.info(`React Native testing mocks registered! (${diff}s)`); diff --git a/src/load.ts b/src/load.ts new file mode 100644 index 0000000..e3a4f97 --- /dev/null +++ b/src/load.ts @@ -0,0 +1,36 @@ +import "./lib/babelRegister"; +import "./lib/polyfills"; +import "./lib/coreMocks"; + +import { replace, replaceEsm } from "./helpers/commons"; +import { AnimatedMock } from "./lib/Animated/AnimatedMock"; +import { AccessibilityInfoMock } from "./lib/Components/AccessibilityInfo"; +import { ActivityIndicatorMock } from "./lib/Components/ActivityIndicator"; +import { AppStateMock } from "./lib/Components/AppState"; +import { ClipboardMock } from "./lib/Components/Clipboard"; +import { ImageMock } from "./lib/Components/Image"; +import { ModalMock } from "./lib/Components/Modal"; +import { RefreshControlMock } from "./lib/Components/RefreshControl"; +import { ScrollViewMock } from "./lib/Components/ScrollView"; +import { TextMock } from "./lib/Components/Text"; +import { TextInputMock } from "./lib/Components/TextInput"; +import { VibrationMock } from "./lib/Components/Vibration"; +import { ViewMock } from "./lib/Components/View"; +import { ViewNativeComponentMock } from "./lib/Components/ViewNativeComponent"; + +replace("react-native/Libraries/Image/Image", ImageMock); +replace("react-native/Libraries/Text/Text", TextMock); +replace("react-native/Libraries/Components/TextInput/TextInput", TextInputMock); +replace("react-native/Libraries/Modal/Modal", ModalMock); +replaceEsm("react-native/Libraries/Components/AccessibilityInfo/AccessibilityInfo", AccessibilityInfoMock); +replace("react-native/Libraries/Components/Clipboard/Clipboard", ClipboardMock); +replace("react-native/Libraries/Components/RefreshControl/RefreshControl", RefreshControlMock); +replace("react-native/Libraries/Components/ScrollView/ScrollView", ScrollViewMock); +replaceEsm("react-native/Libraries/Components/ActivityIndicator/ActivityIndicator", ActivityIndicatorMock); +replace("react-native/Libraries/AppState/AppState", AppStateMock); +replace("react-native/Libraries/Vibration/Vibration", VibrationMock); +replace("react-native/Libraries/Components/View/View", ViewMock); +replace("react-native/Libraries/Components/View/ViewNativeComponent", ViewNativeComponentMock); +replaceEsm("react-native/Libraries/Animated/Animated", AnimatedMock); + +export { }; diff --git a/src/register.ts b/src/register.ts index e3a4f97..f2f6947 100644 --- a/src/register.ts +++ b/src/register.ts @@ -1,36 +1,15 @@ -import "./lib/babelRegister"; -import "./lib/polyfills"; -import "./lib/coreMocks"; +import { createRequire } from "module"; -import { replace, replaceEsm } from "./helpers/commons"; -import { AnimatedMock } from "./lib/Animated/AnimatedMock"; -import { AccessibilityInfoMock } from "./lib/Components/AccessibilityInfo"; -import { ActivityIndicatorMock } from "./lib/Components/ActivityIndicator"; -import { AppStateMock } from "./lib/Components/AppState"; -import { ClipboardMock } from "./lib/Components/Clipboard"; -import { ImageMock } from "./lib/Components/Image"; -import { ModalMock } from "./lib/Components/Modal"; -import { RefreshControlMock } from "./lib/Components/RefreshControl"; -import { ScrollViewMock } from "./lib/Components/ScrollView"; -import { TextMock } from "./lib/Components/Text"; -import { TextInputMock } from "./lib/Components/TextInput"; -import { VibrationMock } from "./lib/Components/Vibration"; -import { ViewMock } from "./lib/Components/View"; -import { ViewNativeComponentMock } from "./lib/Components/ViewNativeComponent"; +import pino from "pino"; +import pinoPretty from "pino-pretty"; -replace("react-native/Libraries/Image/Image", ImageMock); -replace("react-native/Libraries/Text/Text", TextMock); -replace("react-native/Libraries/Components/TextInput/TextInput", TextInputMock); -replace("react-native/Libraries/Modal/Modal", ModalMock); -replaceEsm("react-native/Libraries/Components/AccessibilityInfo/AccessibilityInfo", AccessibilityInfoMock); -replace("react-native/Libraries/Components/Clipboard/Clipboard", ClipboardMock); -replace("react-native/Libraries/Components/RefreshControl/RefreshControl", RefreshControlMock); -replace("react-native/Libraries/Components/ScrollView/ScrollView", ScrollViewMock); -replaceEsm("react-native/Libraries/Components/ActivityIndicator/ActivityIndicator", ActivityIndicatorMock); -replace("react-native/Libraries/AppState/AppState", AppStateMock); -replace("react-native/Libraries/Vibration/Vibration", VibrationMock); -replace("react-native/Libraries/Components/View/View", ViewMock); -replace("react-native/Libraries/Components/View/ViewNativeComponent", ViewNativeComponentMock); -replaceEsm("react-native/Libraries/Animated/Animated", AnimatedMock); +const start = Date.now(); +const logger = pino(pinoPretty({ colorize: true })); +const require = createRequire(import.meta.url); -export { }; +require("./load.cjs"); + +const end = Date.now(); +const diff = (end - start) / 1000; + +logger.info(`React Native testing mocks registered! (${diff}s)`); diff --git a/vite.config.ts b/vite.config.ts index 277fb56..208485a 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -5,6 +5,7 @@ export default defineConfig({ build: { lib: { entry: { + load: "./src/load.ts", main: "./src/main.ts", register: "./src/register.ts", }, diff --git a/vitest.config.ts b/vitest.config.ts index adf447e..aa838bc 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -13,7 +13,7 @@ export default defineConfig({ }, }, setupFiles: [ - "./src/register.ts", + "./src/load.ts", "./test/setup.ts", ], },