first commit

This commit is contained in:
2026-03-10 16:18:05 +00:00
commit 11f9c069b5
31635 changed files with 3187747 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
import type { LoaderFunction } from 'expo-server';
import requireContext from './require-context-ponyfill';
import { NativeIntent } from '../types';
export type ReactComponent = () => React.ReactElement<any, any> | null;
export type NativeIntentStub = NativeIntent;
export type FileStub = (Record<string, unknown> & {
default: ReactComponent;
unstable_settings?: Record<string, any>;
loader?: LoaderFunction;
}) | ReactComponent;
export type MemoryContext = Record<string, FileStub | NativeIntentStub> & {
'+native-intent'?: NativeIntentStub;
};
export { requireContext };
export declare function inMemoryContext(context: MemoryContext): ((id: string) => NativeIntent | ReactComponent | (Record<string, unknown> & {
default: ReactComponent;
unstable_settings?: Record<string, any>;
loader?: LoaderFunction;
}) | {
default: NativeIntent | FileStub;
}) & {
resolve: (key: string) => string;
id: string;
keys: () => string[];
};
export declare function requireContextWithOverrides(dir: string, overrides: MemoryContext): ((id: string) => any) & {
keys: () => string[];
resolve: (key: string) => string;
id: string;
};
//# sourceMappingURL=context-stubs.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"context-stubs.d.ts","sourceRoot":"","sources":["../../src/testing-library/context-stubs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAGlD,OAAO,cAAc,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC,MAAM,MAAM,cAAc,GAAG,MAAM,KAAK,CAAC,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC;AACvE,MAAM,MAAM,gBAAgB,GAAG,YAAY,CAAC;AAC5C,MAAM,MAAM,QAAQ,GAChB,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IACzB,OAAO,EAAE,cAAc,CAAC;IACxB,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACxC,MAAM,CAAC,EAAE,cAAc,CAAC;CACzB,CAAC,GACF,cAAc,CAAC;AAEnB,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,GAAG,gBAAgB,CAAC,GAAG;IACxE,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;CACrC,CAAC;AAEF,OAAO,EAAE,cAAc,EAAE,CAAC;AAI1B,wBAAgB,eAAe,CAAC,OAAO,EAAE,aAAa,SAEpC,MAAM;aAhBT,cAAc;wBACH,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;aAC9B,cAAc;;;;mBAmBR,MAAM;;;EAa1B;AAED,wBAAgB,2BAA2B,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,aAAa,SAI/D,MAAM;;mBAUH,MAAM;;EAI1B"}

View File

@@ -0,0 +1,45 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.requireContext = void 0;
exports.inMemoryContext = inMemoryContext;
exports.requireContextWithOverrides = requireContextWithOverrides;
const path_1 = __importDefault(require("path"));
const require_context_ponyfill_1 = __importDefault(require("./require-context-ponyfill"));
exports.requireContext = require_context_ponyfill_1.default;
const validExtensions = ['.js', '.jsx', '.ts', '.tsx'];
function inMemoryContext(context) {
return Object.assign(function (id) {
id = id.replace(/^\.\//, '').replace(/\.\w*$/, '');
return typeof context[id] === 'function' ? { default: context[id] } : context[id];
}, {
resolve: (key) => key,
id: '0',
keys: () => Object.keys(context).map((key) => {
const ext = path_1.default.extname(key);
key = key.replace(/^\.\//, '');
key = key.startsWith('/') ? key : `./${key}`;
key = validExtensions.includes(ext) ? key : `${key}.js`;
return key;
}),
});
}
function requireContextWithOverrides(dir, overrides) {
const existingContext = (0, require_context_ponyfill_1.default)(path_1.default.resolve(process.cwd(), dir));
return Object.assign(function (id) {
if (id in overrides) {
const route = overrides[id];
return typeof route === 'function' ? { default: route } : route;
}
else {
return existingContext(id);
}
}, {
keys: () => [...Object.keys(overrides), ...existingContext.keys()],
resolve: (key) => key,
id: '0',
});
}
//# sourceMappingURL=context-stubs.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"context-stubs.js","sourceRoot":"","sources":["../../src/testing-library/context-stubs.ts"],"names":[],"mappings":";;;;;;AAwBA,0CAoBC;AAED,kEAkBC;AA/DD,gDAAwB;AAExB,0FAAwD;AAiB/C,yBAjBF,kCAAc,CAiBE;AAEvB,MAAM,eAAe,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;AAEvD,SAAgB,eAAe,CAAC,OAAsB;IACpD,OAAO,MAAM,CAAC,MAAM,CAClB,UAAU,EAAU;QAClB,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QACnD,OAAO,OAAO,OAAO,CAAC,EAAE,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACpF,CAAC,EACD;QACE,OAAO,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,GAAG;QAC7B,EAAE,EAAE,GAAG;QACP,IAAI,EAAE,GAAG,EAAE,CACT,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;YAC/B,MAAM,GAAG,GAAG,cAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YAC9B,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;YAC/B,GAAG,GAAG,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;YAC7C,GAAG,GAAG,eAAe,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,KAAK,CAAC;YAExD,OAAO,GAAG,CAAC;QACb,CAAC,CAAC;KACL,CACF,CAAC;AACJ,CAAC;AAED,SAAgB,2BAA2B,CAAC,GAAW,EAAE,SAAwB;IAC/E,MAAM,eAAe,GAAG,IAAA,kCAAc,EAAC,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC;IAEzE,OAAO,MAAM,CAAC,MAAM,CAClB,UAAU,EAAU;QAClB,IAAI,EAAE,IAAI,SAAS,EAAE,CAAC;YACpB,MAAM,KAAK,GAAG,SAAS,CAAC,EAAE,CAAC,CAAC;YAC5B,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;QAClE,CAAC;aAAM,CAAC;YACN,OAAO,eAAe,CAAC,EAAE,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC,EACD;QACE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,eAAe,CAAC,IAAI,EAAE,CAAC;QAClE,OAAO,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,GAAG;QAC7B,EAAE,EAAE,GAAG;KACR,CACF,CAAC;AACJ,CAAC","sourcesContent":["import type { LoaderFunction } from 'expo-server';\nimport path from 'path';\n\nimport requireContext from './require-context-ponyfill';\nimport { NativeIntent } from '../types';\n\nexport type ReactComponent = () => React.ReactElement<any, any> | null;\nexport type NativeIntentStub = NativeIntent;\nexport type FileStub =\n | (Record<string, unknown> & {\n default: ReactComponent;\n unstable_settings?: Record<string, any>;\n loader?: LoaderFunction;\n })\n | ReactComponent;\n\nexport type MemoryContext = Record<string, FileStub | NativeIntentStub> & {\n '+native-intent'?: NativeIntentStub;\n};\n\nexport { requireContext };\n\nconst validExtensions = ['.js', '.jsx', '.ts', '.tsx'];\n\nexport function inMemoryContext(context: MemoryContext) {\n return Object.assign(\n function (id: string) {\n id = id.replace(/^\\.\\//, '').replace(/\\.\\w*$/, '');\n return typeof context[id] === 'function' ? { default: context[id] } : context[id];\n },\n {\n resolve: (key: string) => key,\n id: '0',\n keys: () =>\n Object.keys(context).map((key) => {\n const ext = path.extname(key);\n key = key.replace(/^\\.\\//, '');\n key = key.startsWith('/') ? key : `./${key}`;\n key = validExtensions.includes(ext) ? key : `${key}.js`;\n\n return key;\n }),\n }\n );\n}\n\nexport function requireContextWithOverrides(dir: string, overrides: MemoryContext) {\n const existingContext = requireContext(path.resolve(process.cwd(), dir));\n\n return Object.assign(\n function (id: string) {\n if (id in overrides) {\n const route = overrides[id];\n return typeof route === 'function' ? { default: route } : route;\n } else {\n return existingContext(id);\n }\n },\n {\n keys: () => [...Object.keys(overrides), ...existingContext.keys()],\n resolve: (key: string) => key,\n id: '0',\n }\n );\n}\n"]}

View File

@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=expect.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"expect.d.ts","sourceRoot":"","sources":["../../src/testing-library/expect.ts"],"names":[],"mappings":""}

View File

@@ -0,0 +1,25 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const matchers_1 = __importDefault(require("expect/build/matchers"));
matchers_1.default.customTesters = [];
expect.extend({
toHavePathname(screen, expected) {
return matchers_1.default.toEqual(screen.getPathname(), expected);
},
toHavePathnameWithParams(screen, expected) {
return matchers_1.default.toEqual(screen.getPathnameWithParams(), expected);
},
toHaveSegments(screen, expected) {
return matchers_1.default.toEqual(screen.getSegments(), expected);
},
toHaveSearchParams(screen, expected) {
return matchers_1.default.toEqual(screen.getSearchParams(), expected);
},
toHaveRouterState(screen, expected) {
return matchers_1.default.toEqual(screen.getRouterState(), expected);
},
});
//# sourceMappingURL=expect.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"expect.js","sourceRoot":"","sources":["../../src/testing-library/expect.ts"],"names":[],"mappings":";;;;;AAAA,qEAA6C;AAE7C,kBAAQ,CAAC,aAAa,GAAG,EAAE,CAAC;AAE5B,MAAM,CAAC,MAAM,CAAC;IACZ,cAAc,CAAC,MAAM,EAAE,QAAQ;QAC7B,OAAO,kBAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,EAAE,QAAQ,CAAC,CAAC;IAC1D,CAAC;IACD,wBAAwB,CAAC,MAAM,EAAE,QAAQ;QACvC,OAAO,kBAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,qBAAqB,EAAE,EAAE,QAAQ,CAAC,CAAC;IACpE,CAAC;IACD,cAAc,CAAC,MAAM,EAAE,QAAQ;QAC7B,OAAO,kBAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,EAAE,QAAQ,CAAC,CAAC;IAC1D,CAAC;IACD,kBAAkB,CAAC,MAAM,EAAE,QAAQ;QACjC,OAAO,kBAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,eAAe,EAAE,EAAE,QAAQ,CAAC,CAAC;IAC9D,CAAC;IACD,iBAAiB,CAAC,MAAM,EAAE,QAAQ;QAChC,OAAO,kBAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,cAAc,EAAE,EAAE,QAAQ,CAAC,CAAC;IAC7D,CAAC;CACF,CAAC,CAAC","sourcesContent":["import matchers from 'expect/build/matchers';\n\nmatchers.customTesters = [];\n\nexpect.extend({\n toHavePathname(screen, expected) {\n return matchers.toEqual(screen.getPathname(), expected);\n },\n toHavePathnameWithParams(screen, expected) {\n return matchers.toEqual(screen.getPathnameWithParams(), expected);\n },\n toHaveSegments(screen, expected) {\n return matchers.toEqual(screen.getSegments(), expected);\n },\n toHaveSearchParams(screen, expected) {\n return matchers.toEqual(screen.getSearchParams(), expected);\n },\n toHaveRouterState(screen, expected) {\n return matchers.toEqual(screen.getRouterState(), expected);\n },\n});\n"]}

View File

@@ -0,0 +1,48 @@
import './expect';
import './mocks';
import React from 'react';
import { MockContextConfig, getMockConfig, getMockContext } from './mock-config';
import { ExpoLinkingOptions } from '../getLinkingConfig';
import { ReactNavigationState } from '../global-state/router-store';
declare const rnTestingLibrary: typeof import("@testing-library/react-native");
export type * from '@testing-library/react-native';
export declare const act: typeof React.act, cleanup: typeof import("@testing-library/react-native").cleanup, fireEvent: typeof import("@testing-library/react-native").fireEvent, waitFor: typeof import("@testing-library/react-native").waitFor, waitForElementToBeRemoved: typeof import("@testing-library/react-native").waitForElementToBeRemoved, within: typeof import("@testing-library/react-native").within, configure: typeof import("@testing-library/react-native").configure, resetToDefaults: typeof import("@testing-library/react-native").resetToDefaults, isHiddenFromAccessibility: typeof import("@testing-library/react-native").isHiddenFromAccessibility, isInaccessible: typeof import("@testing-library/react-native").isHiddenFromAccessibility, getDefaultNormalizer: typeof import("@testing-library/react-native").getDefaultNormalizer, renderHook: typeof import("@testing-library/react-native").renderHook, userEvent: {
setup: typeof import("@testing-library/react-native/build/user-event/setup").setup;
press: (element: import("react-test-renderer").ReactTestInstance) => Promise<void>;
longPress: (element: import("react-test-renderer").ReactTestInstance, options?: import("@testing-library/react-native/build/user-event/press").PressOptions) => Promise<void>;
type: (element: import("react-test-renderer").ReactTestInstance, text: string, options?: import("@testing-library/react-native/build/user-event/type").TypeOptions) => Promise<void>;
clear: (element: import("react-test-renderer").ReactTestInstance) => Promise<void>;
paste: (element: import("react-test-renderer").ReactTestInstance, text: string) => Promise<void>;
scrollTo: (element: import("react-test-renderer").ReactTestInstance, options: import("@testing-library/react-native/build/user-event/scroll").ScrollToOptions) => Promise<void>;
};
export declare let screen: typeof rnTestingLibrary.screen;
export type RenderRouterOptions = Parameters<typeof rnTestingLibrary.render>[1] & {
initialUrl?: any;
linking?: Partial<ExpoLinkingOptions>;
};
type Result = ReturnType<typeof rnTestingLibrary.render> & {
getPathname(): string;
getPathnameWithParams(): string;
getSegments(): string[];
getSearchParams(): Record<string, string | string[]>;
getRouterState(): ReactNavigationState | undefined;
};
export { MockContextConfig, getMockConfig, getMockContext };
export declare function renderRouter(context?: MockContextConfig, { initialUrl, linking, ...options }?: RenderRouterOptions): Result;
export declare const testRouter: {
/** Navigate to the provided pathname and the pathname */
navigate(path: string): void;
/** Push the provided pathname and assert the pathname */
push(path: string): void;
/** Replace with provided pathname and assert the pathname */
replace(path: string): void;
/** Go back in history and asset the new pathname */
back(path?: string): void;
/** If there's history that supports invoking the `back` function. */
canGoBack(): boolean;
/** Update the current route query params and assert the new pathname */
setParams(params: Record<string, string>, path?: string): void;
/** If there's history that supports invoking the `back` function. */
dismissAll(): void;
};
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing-library/index.tsx"],"names":[],"mappings":"AAAA,OAAO,UAAU,CAAC;AAClB,OAAO,SAAS,CAAC;AAGjB,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEjF,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAS,MAAM,8BAA8B,CAAC;AAG3E,QAAA,MAAM,gBAAgB,gDAclB,CAAC;AAEL,mBAAmB,+BAA+B,CAAC;AAGnD,MAAM,CAAC,OAAO,CAAC,MACb,GAAG,oBACH,OAAO,0DACP,SAAS,4DACT,OAAO,0DACP,yBAAyB,4EACzB,MAAM,yDACN,SAAS,4DACT,eAAe,kEACf,yBAAyB,4EACzB,cAAc,4EACd,oBAAoB,uEACpB,UAAU,6DACV,SAAS;;;iFAhCF,CAAC;0FAEI,CAAC;;;;CA+BW,CAAC;AAE3B,MAAM,CAAC,OAAO,CAAC,IAAI,MAAM,EAAE,OAAO,gBAAgB,CAAC,MAAM,CAAC;AAS1D,MAAM,MAAM,mBAAmB,GAAG,UAAU,CAAC,OAAO,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG;IAChF,UAAU,CAAC,EAAE,GAAG,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAC;CACvC,CAAC;AAEF,KAAK,MAAM,GAAG,UAAU,CAAC,OAAO,gBAAgB,CAAC,MAAM,CAAC,GAAG;IACzD,WAAW,IAAI,MAAM,CAAC;IACtB,qBAAqB,IAAI,MAAM,CAAC;IAChC,WAAW,IAAI,MAAM,EAAE,CAAC;IACxB,eAAe,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;IACrD,cAAc,IAAI,oBAAoB,GAAG,SAAS,CAAC;CACpD,CAAC;AAEF,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,cAAc,EAAE,CAAC;AAE5D,wBAAgB,YAAY,CAC1B,OAAO,GAAE,iBAA2B,EACpC,EAAE,UAAgB,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE,GAAE,mBAAwB,GAClE,MAAM,CAmCR;AAED,eAAO,MAAM,UAAU;IACrB,yDAAyD;mBAC1C,MAAM;IAIrB,yDAAyD;eAC9C,MAAM;IAIjB,6DAA6D;kBAC/C,MAAM;IAIpB,oDAAoD;gBACxC,MAAM;IAOlB,qEAAqE;;IAIrE,wEAAwE;sBACtD,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,SAAS,MAAM;IAMvD,qEAAqE;;CAItE,CAAC"}

106
node_modules/expo-router/build/testing-library/index.js generated vendored Normal file
View File

@@ -0,0 +1,106 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.testRouter = exports.getMockContext = exports.getMockConfig = void 0;
exports.renderRouter = renderRouter;
require("./expect");
require("./mocks");
const react_1 = __importDefault(require("react"));
const mock_config_1 = require("./mock-config");
Object.defineProperty(exports, "getMockConfig", { enumerable: true, get: function () { return mock_config_1.getMockConfig; } });
Object.defineProperty(exports, "getMockContext", { enumerable: true, get: function () { return mock_config_1.getMockContext; } });
const ExpoRoot_1 = require("../ExpoRoot");
const router_store_1 = require("../global-state/router-store");
const imperative_api_1 = require("../imperative-api");
const rnTestingLibrary = (() => {
try {
return require('@testing-library/react-native');
}
catch (error) {
if ('code' in error && error.code === 'MODULE_NOT_FOUND') {
const newError = new Error(`[expo-router/testing-library] "@testing-library/react-native" failed to import. You need to install it to use expo-router's testing library.`);
newError.stack = error.stack;
newError.cause = error;
throw newError;
}
throw error;
}
})();
Object.assign(exports, rnTestingLibrary);
Object.defineProperty(exports, 'screen', {
get() {
return rnTestingLibrary.screen;
},
});
function renderRouter(context = './app', { initialUrl = '/', linking, ...options } = {}) {
jest.useFakeTimers();
const mockContext = (0, mock_config_1.getMockContext)(context);
// Force the render to be synchronous
process.env.EXPO_ROUTER_IMPORT_MODE = 'sync';
const result = rnTestingLibrary.render(<ExpoRoot_1.ExpoRoot context={mockContext} location={initialUrl} linking={linking}/>, options);
/**
* This is a hack to ensure that React Navigation's state updates are processed before we run assertions.
* Some updates are async and we need to wait for them to complete, otherwise will we get a false positive.
* (that the app will briefly be in the right state, but then update to an invalid state)
*/
return Object.assign(result, {
getPathname() {
return router_store_1.store.getRouteInfo().pathname;
},
getSegments() {
return router_store_1.store.getRouteInfo().segments;
},
getSearchParams() {
return router_store_1.store.getRouteInfo().params;
},
getPathnameWithParams() {
return router_store_1.store.getRouteInfo().pathnameWithParams;
},
getRouterState() {
return router_store_1.store.state;
},
});
}
exports.testRouter = {
/** Navigate to the provided pathname and the pathname */
navigate(path) {
rnTestingLibrary.act(() => imperative_api_1.router.navigate(path));
expect(rnTestingLibrary.screen).toHavePathnameWithParams(path);
},
/** Push the provided pathname and assert the pathname */
push(path) {
rnTestingLibrary.act(() => imperative_api_1.router.push(path));
expect(rnTestingLibrary.screen).toHavePathnameWithParams(path);
},
/** Replace with provided pathname and assert the pathname */
replace(path) {
rnTestingLibrary.act(() => imperative_api_1.router.replace(path));
expect(rnTestingLibrary.screen).toHavePathnameWithParams(path);
},
/** Go back in history and asset the new pathname */
back(path) {
expect(imperative_api_1.router.canGoBack()).toBe(true);
rnTestingLibrary.act(() => imperative_api_1.router.back());
if (path) {
expect(rnTestingLibrary.screen).toHavePathnameWithParams(path);
}
},
/** If there's history that supports invoking the `back` function. */
canGoBack() {
return imperative_api_1.router.canGoBack();
},
/** Update the current route query params and assert the new pathname */
setParams(params, path) {
imperative_api_1.router.setParams(params);
if (path) {
expect(exports.screen).toHavePathnameWithParams(path);
}
},
/** If there's history that supports invoking the `back` function. */
dismissAll() {
rnTestingLibrary.act(() => imperative_api_1.router.dismissAll());
},
};
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,38 @@
import { MemoryContext } from './context-stubs';
export type MockContextConfig = string | string[] | MemoryContext | {
appDir: string;
overrides: MemoryContext;
};
export declare function getMockConfig(context: MockContextConfig, metaOnly?: boolean): {
screens: {
__root: {
initialRouteName: undefined;
screens: Record<string, import("../getReactNavigationConfig").Screen>;
path: string;
};
} | {
__root: {
initialRouteName: undefined;
screens: Record<string, import("../getReactNavigationConfig").Screen>;
path: string;
};
} | {
__root: {
initialRouteName: undefined;
screens: Record<string, import("../getReactNavigationConfig").Screen>;
path: string;
};
} | {
__root: {
initialRouteName: undefined;
screens: Record<string, import("../getReactNavigationConfig").Screen>;
path: string;
};
};
};
export declare function getMockContext(context: MockContextConfig): ((id: string) => any) & {
keys: () => string[];
resolve: (key: string) => string;
id: string;
};
//# sourceMappingURL=mock-config.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"mock-config.d.ts","sourceRoot":"","sources":["../../src/testing-library/mock-config.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,aAAa,EAId,MAAM,iBAAiB,CAAC;AAIzB,MAAM,MAAM,iBAAiB,GACzB,MAAM,GACN,MAAM,EAAE,GACR,aAAa,GACb;IAEE,MAAM,EAAE,MAAM,CAAC;IAEf,SAAS,EAAE,aAAa,CAAC;CAC1B,CAAC;AAEN,wBAAgB,aAAa,CAAC,OAAO,EAAE,iBAAiB,EAAE,QAAQ,GAAE,OAAc;;;;;;;;;;;;;;;;;;;;;;;;;;EAKjF;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,iBAAiB;;;;EAcxD"}

View File

@@ -0,0 +1,35 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getMockConfig = getMockConfig;
exports.getMockContext = getMockContext;
const path_1 = __importDefault(require("path"));
const context_stubs_1 = require("./context-stubs");
const getLinkingConfig_1 = require("../getLinkingConfig");
const getRoutes_1 = require("../getRoutes");
function getMockConfig(context, metaOnly = true) {
return (0, getLinkingConfig_1.getNavigationConfig)((0, getRoutes_1.getExactRoutes)(getMockContext(context)), metaOnly, {
sitemap: true,
notFound: true,
});
}
function getMockContext(context) {
if (typeof context === 'string') {
return (0, context_stubs_1.requireContext)(path_1.default.resolve(process.cwd(), context));
}
else if (Array.isArray(context)) {
return (0, context_stubs_1.inMemoryContext)(Object.fromEntries(context.map((filename) => [filename, { default: () => null }])));
}
else if (!('appDir' in context)) {
return (0, context_stubs_1.inMemoryContext)(context);
}
else if ('appDir' in context && typeof context.appDir === 'string') {
return (0, context_stubs_1.requireContextWithOverrides)(context.appDir, context.overrides);
}
else {
throw new Error('Invalid context');
}
}
//# sourceMappingURL=mock-config.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"mock-config.js","sourceRoot":"","sources":["../../src/testing-library/mock-config.ts"],"names":[],"mappings":";;;;;AAsBA,sCAKC;AAED,wCAcC;AA3CD,gDAAwB;AAExB,mDAKyB;AACzB,0DAA0D;AAC1D,4CAA8C;AAa9C,SAAgB,aAAa,CAAC,OAA0B,EAAE,WAAoB,IAAI;IAChF,OAAO,IAAA,sCAAmB,EAAC,IAAA,0BAAc,EAAC,cAAc,CAAC,OAAO,CAAC,CAAE,EAAE,QAAQ,EAAE;QAC7E,OAAO,EAAE,IAAI;QACb,QAAQ,EAAE,IAAI;KACf,CAAC,CAAC;AACL,CAAC;AAED,SAAgB,cAAc,CAAC,OAA0B;IACvD,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,OAAO,IAAA,8BAAc,EAAC,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC;IAC9D,CAAC;SAAM,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAClC,OAAO,IAAA,+BAAe,EACpB,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,QAAQ,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CACnF,CAAC;IACJ,CAAC;SAAM,IAAI,CAAC,CAAC,QAAQ,IAAI,OAAO,CAAC,EAAE,CAAC;QAClC,OAAO,IAAA,+BAAe,EAAC,OAAO,CAAC,CAAC;IAClC,CAAC;SAAM,IAAI,QAAQ,IAAI,OAAO,IAAI,OAAO,OAAO,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;QACrE,OAAO,IAAA,2CAA2B,EAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,SAA0B,CAAC,CAAC;IACzF,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;AACH,CAAC","sourcesContent":["import path from 'path';\n\nimport {\n MemoryContext,\n inMemoryContext,\n requireContext,\n requireContextWithOverrides,\n} from './context-stubs';\nimport { getNavigationConfig } from '../getLinkingConfig';\nimport { getExactRoutes } from '../getRoutes';\n\nexport type MockContextConfig =\n | string // Pathname to a directory\n | string[] // Array of filenames to mock as empty components, e.g () => null\n | MemoryContext // Map of filenames and their exports\n | {\n // Directory to load as context\n appDir: string;\n // Map of filenames and their exports. Will override contents of files loaded in `appDir\n overrides: MemoryContext;\n };\n\nexport function getMockConfig(context: MockContextConfig, metaOnly: boolean = true) {\n return getNavigationConfig(getExactRoutes(getMockContext(context))!, metaOnly, {\n sitemap: true,\n notFound: true,\n });\n}\n\nexport function getMockContext(context: MockContextConfig) {\n if (typeof context === 'string') {\n return requireContext(path.resolve(process.cwd(), context));\n } else if (Array.isArray(context)) {\n return inMemoryContext(\n Object.fromEntries(context.map((filename) => [filename, { default: () => null }]))\n );\n } else if (!('appDir' in context)) {\n return inMemoryContext(context);\n } else if ('appDir' in context && typeof context.appDir === 'string') {\n return requireContextWithOverrides(context.appDir, context.overrides as MemoryContext);\n } else {\n throw new Error('Invalid context');\n }\n}\n"]}

View File

@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=mocks.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"mocks.d.ts","sourceRoot":"","sources":["../../src/testing-library/mocks.ts"],"names":[],"mappings":""}

View File

@@ -0,0 +1,36 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
try {
require('react-native-gesture-handler/jestSetup');
}
catch { }
try {
require('react-native-reanimated');
jest.mock('react-native-reanimated', () => {
try {
const Reanimated = require('react-native-reanimated/mock');
Reanimated.default.call = () => { }; // Override `call` with a no-op if needed
return Reanimated;
}
catch {
return {};
}
});
}
catch { }
jest.mock('expo-linking', () => {
const module = {
...jest.requireActual('expo-linking'),
createURL(path) {
return 'yourscheme://' + path;
},
resolveScheme() {
return 'yourscheme';
},
addEventListener() {
return { remove() { } };
},
};
return module;
});
//# sourceMappingURL=mocks.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"mocks.js","sourceRoot":"","sources":["../../src/testing-library/mocks.ts"],"names":[],"mappings":";;AAAA,IAAI,CAAC;IACH,OAAO,CAAC,wCAAwC,CAAC,CAAC;AACpD,CAAC;AAAC,MAAM,CAAC,CAAA,CAAC;AAEV,IAAI,CAAC;IACH,OAAO,CAAC,yBAAyB,CAAC,CAAC;IACnC,IAAI,CAAC,IAAI,CAAC,yBAAyB,EAAE,GAAG,EAAE;QACxC,IAAI,CAAC;YACH,MAAM,UAAU,GAAG,OAAO,CAAC,8BAA8B,CAAC,CAAC;YAC3D,UAAU,CAAC,OAAO,CAAC,IAAI,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC,yCAAyC;YAC7E,OAAO,UAAU,CAAC;QACpB,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAAC,MAAM,CAAC,CAAA,CAAC;AAEV,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,GAAG,EAAE;IAC7B,MAAM,MAAM,GAAkC;QAC5C,GAAG,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;QACrC,SAAS,CAAC,IAAY;YACpB,OAAO,eAAe,GAAG,IAAI,CAAC;QAChC,CAAC;QACD,aAAa;YACX,OAAO,YAAY,CAAC;QACtB,CAAC;QACD,gBAAgB;YACd,OAAO,EAAE,MAAM,KAAI,CAAC,EAAS,CAAC;QAChC,CAAC;KACF,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC,CAAC","sourcesContent":["try {\n require('react-native-gesture-handler/jestSetup');\n} catch {}\n\ntry {\n require('react-native-reanimated');\n jest.mock('react-native-reanimated', () => {\n try {\n const Reanimated = require('react-native-reanimated/mock');\n Reanimated.default.call = () => {}; // Override `call` with a no-op if needed\n return Reanimated;\n } catch {\n return {};\n }\n });\n} catch {}\n\njest.mock('expo-linking', () => {\n const module: typeof import('expo-linking') = {\n ...jest.requireActual('expo-linking'),\n createURL(path: string) {\n return 'yourscheme://' + path;\n },\n resolveScheme() {\n return 'yourscheme';\n },\n addEventListener() {\n return { remove() {} } as any;\n },\n };\n\n return module;\n});\n"]}

View File

@@ -0,0 +1,7 @@
import type { RequireContext } from '../types';
export interface RequireContextPonyFill extends RequireContext {
__add(file: string): void;
__delete(file: string): void;
}
export default function requireContext(base?: string, scanSubDirectories?: boolean, regularExpression?: RegExp, files?: Record<string, unknown>): RequireContextPonyFill;
//# sourceMappingURL=require-context-ponyfill.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"require-context-ponyfill.d.ts","sourceRoot":"","sources":["../../src/testing-library/require-context-ponyfill.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C,MAAM,WAAW,sBAAuB,SAAQ,cAAc;IAC5D,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B;AAED,MAAM,CAAC,OAAO,UAAU,cAAc,CACpC,IAAI,SAAM,EACV,kBAAkB,UAAO,EACzB,iBAAiB,SAAe,EAChC,KAAK,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,0BAyCpC"}

View File

@@ -0,0 +1,44 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = requireContext;
// @ts-ignore: types node
const node_fs_1 = __importDefault(require("node:fs"));
// @ts-ignore: types node
const node_path_1 = __importDefault(require("node:path"));
function requireContext(base = '.', scanSubDirectories = true, regularExpression = /\.[tj]sx?$/, files = {}) {
function readDirectory(directory) {
node_fs_1.default.readdirSync(directory).forEach((file) => {
const fullPath = node_path_1.default.resolve(directory, file);
const relativePath = `./${node_path_1.default.relative(base, fullPath).split(node_path_1.default.sep).join('/')}`;
if (node_fs_1.default.statSync(fullPath).isDirectory()) {
if (scanSubDirectories)
readDirectory(fullPath);
return;
}
if (!regularExpression.test(relativePath))
return;
files[relativePath] = true;
});
}
if (node_fs_1.default.existsSync(base)) {
readDirectory(base);
}
const context = Object.assign(function Module(file) {
return require(node_path_1.default.join(base, file));
}, {
keys: () => Object.keys(files),
resolve: (key) => key,
id: '0',
__add(file) {
files[file] = true;
},
__delete(file) {
delete files[file];
},
});
return context;
}
//# sourceMappingURL=require-context-ponyfill.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"require-context-ponyfill.js","sourceRoot":"","sources":["../../src/testing-library/require-context-ponyfill.ts"],"names":[],"mappings":";;;;;AAYA,iCA6CC;AAzDD,yBAAyB;AACzB,sDAAyB;AACzB,yBAAyB;AACzB,0DAA6B;AAS7B,SAAwB,cAAc,CACpC,IAAI,GAAG,GAAG,EACV,kBAAkB,GAAG,IAAI,EACzB,iBAAiB,GAAG,YAAY,EAChC,QAAiC,EAAE;IAEnC,SAAS,aAAa,CAAC,SAAiB;QACtC,iBAAE,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,CAAC,IAAY,EAAE,EAAE;YACjD,MAAM,QAAQ,GAAG,mBAAI,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;YAC/C,MAAM,YAAY,GAAG,KAAK,mBAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,KAAK,CAAC,mBAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YAEpF,IAAI,iBAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC;gBACxC,IAAI,kBAAkB;oBAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;gBAEhD,OAAO;YACT,CAAC;YAED,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,YAAY,CAAC;gBAAE,OAAO;YAElD,KAAK,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC;QAC7B,CAAC,CAAC,CAAC;IACL,CAAC;IAED,IAAI,iBAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACxB,aAAa,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;IAED,MAAM,OAAO,GAA2B,MAAM,CAAC,MAAM,CACnD,SAAS,MAAM,CAAC,IAAY;QAC1B,OAAO,OAAO,CAAC,mBAAI,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;IACxC,CAAC,EACD;QACE,IAAI,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;QAC9B,OAAO,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,GAAG;QAC7B,EAAE,EAAE,GAAG;QACP,KAAK,CAAC,IAAY;YAChB,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;QACrB,CAAC;QACD,QAAQ,CAAC,IAAY;YACnB,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC;QACrB,CAAC;KACF,CACF,CAAC;IAEF,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["// @ts-ignore: types node\nimport fs from 'node:fs';\n// @ts-ignore: types node\nimport path from 'node:path';\n\nimport type { RequireContext } from '../types';\n\nexport interface RequireContextPonyFill extends RequireContext {\n __add(file: string): void;\n __delete(file: string): void;\n}\n\nexport default function requireContext(\n base = '.',\n scanSubDirectories = true,\n regularExpression = /\\.[tj]sx?$/,\n files: Record<string, unknown> = {}\n) {\n function readDirectory(directory: string) {\n fs.readdirSync(directory).forEach((file: string) => {\n const fullPath = path.resolve(directory, file);\n const relativePath = `./${path.relative(base, fullPath).split(path.sep).join('/')}`;\n\n if (fs.statSync(fullPath).isDirectory()) {\n if (scanSubDirectories) readDirectory(fullPath);\n\n return;\n }\n\n if (!regularExpression.test(relativePath)) return;\n\n files[relativePath] = true;\n });\n }\n\n if (fs.existsSync(base)) {\n readDirectory(base);\n }\n\n const context: RequireContextPonyFill = Object.assign(\n function Module(file: string) {\n return require(path.join(base, file));\n },\n {\n keys: () => Object.keys(files),\n resolve: (key: string) => key,\n id: '0',\n __add(file: string) {\n files[file] = true;\n },\n __delete(file: string) {\n delete files[file];\n },\n }\n );\n\n return context;\n}\n"]}