-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(exports): Set up ESM first (#27)
* feat(exports): Set up ESM first * Switch to VItest * Update ESLint * Move register files to a single TS * Enhance replace(..), fix bad RendererProxy mock, and create a RN Vitest environment * Revert README.md changes * Polishing
- Loading branch information
Showing
22 changed files
with
1,885 additions
and
622 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// eslint-disable-next-line import/no-namespace | ||
import * as RendererImplementation from "react-native/Libraries/ReactNative/RendererImplementation"; | ||
|
||
export const RendererProxyMock = RendererImplementation; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,21 @@ | ||
import { noop, replace, replaceEsm } from "../helpers/commons"; | ||
import { noop, replace } from "../helpers/commons"; | ||
import { mockNativeComponent } from "../helpers/mockNativeComponent"; | ||
|
||
import { LinkingMock } from "./Components/Linking"; | ||
import { NativeComponentRegistryMock } from "./Core/NativeComponentRegistry"; | ||
import { NativeModulesMock } from "./Core/NativeModules"; | ||
import { RendererProxyMock } from "./Core/RendererProxy"; | ||
import { UIManagerMock } from "./Core/UIManager"; | ||
import { verifyComponentAttrEqMock } from "./Core/verifyComponentAttributeEquivalence"; | ||
|
||
Object.assign(global, { jest: { fn: () => noop } }); | ||
|
||
replace("react-native/Libraries/Core/InitializeCore", { }); | ||
replace("react-native/Libraries/Core/NativeExceptionsManager", { }); | ||
replace("react-native/Libraries/ReactNative/UIManager", UIManagerMock); | ||
replace("react-native/Libraries/Linking/Linking", LinkingMock); | ||
replace("react-native/Libraries/BatchedBridge/NativeModules", NativeModulesMock); | ||
replace("react-native/Libraries/NativeComponent/NativeComponentRegistry", NativeComponentRegistryMock); | ||
replaceEsm("react-native/Libraries/ReactNative/requireNativeComponent", mockNativeComponent); | ||
replace("react-native/Libraries/Utilities/verifyComponentAttributeEquivalence", verifyComponentAttrEqMock); | ||
replace( | ||
"react-native/Libraries/ReactNative/RendererProxy", | ||
"react-native/Libraries/ReactNative/RendererImplementation", | ||
); | ||
replace("react-native/Libraries/Core/InitializeCore", () => ({ })); | ||
replace("react-native/Libraries/Core/NativeExceptionsManager", () => ({ })); | ||
replace("react-native/Libraries/ReactNative/UIManager", () => UIManagerMock); | ||
replace("react-native/Libraries/Linking/Linking", () => LinkingMock); | ||
replace("react-native/Libraries/BatchedBridge/NativeModules", () => NativeModulesMock); | ||
replace("react-native/Libraries/NativeComponent/NativeComponentRegistry", () => NativeComponentRegistryMock); | ||
replace("react-native/Libraries/ReactNative/requireNativeComponent", () => ({ default: mockNativeComponent })); | ||
replace("react-native/Libraries/Utilities/verifyComponentAttributeEquivalence", () => verifyComponentAttrEqMock); | ||
replace("react-native/Libraries/ReactNative/RendererProxy", () => RendererProxyMock); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import "./lib/babelRegister"; | ||
import "./lib/polyfills"; | ||
import "./lib/coreMocks"; | ||
|
||
import { replace } 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"; | ||
|
||
const libs = "react-native/Libraries"; | ||
|
||
replace(`${libs}/Image/Image`, () => ImageMock); | ||
replace(`${libs}/Text/Text`, () => TextMock); | ||
replace(`${libs}/Components/TextInput/TextInput`, () => TextInputMock); | ||
replace(`${libs}/Modal/Modal`, () => ModalMock); | ||
replace(`${libs}/Components/AccessibilityInfo/AccessibilityInfo`, () => ({ default: AccessibilityInfoMock })); | ||
replace(`${libs}/Components/Clipboard/Clipboard`, () => ClipboardMock); | ||
replace(`${libs}/Components/RefreshControl/RefreshControl`, () => RefreshControlMock); | ||
replace(`${libs}/Components/ScrollView/ScrollView`, () => ScrollViewMock); | ||
replace(`${libs}/Components/ActivityIndicator/ActivityIndicator`, () => ({ default: ActivityIndicatorMock })); | ||
replace(`${libs}/AppState/AppState`, () => AppStateMock); | ||
replace(`${libs}/Vibration/Vibration`, () => VibrationMock); | ||
replace(`${libs}/Components/View/View`, () => ViewMock); | ||
replace(`${libs}/Components/View/ViewNativeComponent`, () => ViewNativeComponentMock); | ||
replace(`${libs}/Animated/Animated`, () => ({ default: AnimatedMock })); | ||
|
||
export { }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +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); | ||
|
||
require("./load.cjs"); | ||
|
||
const end = Date.now(); | ||
const diff = (end - start) / 1000; | ||
|
||
logger.info(`React Native testing mocks registered! (${diff}s)`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { Environment } from "vitest"; | ||
|
||
const reactNativeEnv: Environment = { | ||
name: "react-native", | ||
setup: async () => { | ||
await import("../src/load"); | ||
return { teardown: () => undefined }; | ||
}, | ||
transformMode: "ssr", | ||
}; | ||
|
||
export default reactNativeEnv; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.