Skip to content

Commit

Permalink
Move register files to a single TS
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseLion committed Jun 29, 2024
1 parent debd618 commit 3f794c3
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 69 deletions.
10 changes: 4 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 0 additions & 13 deletions register.cjs

This file was deleted.

16 changes: 0 additions & 16 deletions register.js

This file was deleted.

36 changes: 36 additions & 0 deletions src/load.ts
Original file line number Diff line number Diff line change
@@ -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 { };
45 changes: 12 additions & 33 deletions src/register.ts
Original file line number Diff line number Diff line change
@@ -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)`);
1 change: 1 addition & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default defineConfig({
build: {
lib: {
entry: {
load: "./src/load.ts",
main: "./src/main.ts",
register: "./src/register.ts",
},
Expand Down
2 changes: 1 addition & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default defineConfig({
},
},
setupFiles: [
"./src/register.ts",
"./src/load.ts",
"./test/setup.ts",
],
},
Expand Down

0 comments on commit 3f794c3

Please sign in to comment.