Skip to content

Commit c027045

Browse files
committed
refactor(tests): migrate test suite and mock-builders to TypeScript
Migrates 44 mock-builders, 36 test files, 2 offline-support helpers, 1 test utility (BetterSqlite), and jest-setup from JS to TS. Adds tsconfig.test.json so tests and mock-builders are type-checked (base tsconfig still excludes them from the published build) and a test:typecheck script. Dependency changes: - @types/jest: ^29.5.14 -> ^30.0.0 - jest: ^30.0.0 -> ^30.3.0 - @total-typescript/shoehorn: new devDependency (fromPartial<T>() for type-safe partial mocks, replacing `as any` / `Record<string, any>`) Caveats: - tsconfig.test.json keeps noImplicitAny: false as a starting point; tightening is follow-up work (Phase 5 of the migration plan). - yarn test:typecheck exists but is not wired into CI yet. Verification: - yarn build passes - yarn lint passes - yarn test:unit shows only the pre-existing SQLite-isolation flake in offline-support/index.test.ts (baseline had 5 failures; now 2 — no regressions).
1 parent b0db688 commit c027045

134 files changed

Lines changed: 1401 additions & 881 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* global require */
2-
import rn, { FlatList, View } from 'react-native';
2+
import type { ReactNode } from 'react';
3+
import { FlatList, View } from 'react-native';
34

45
import mockRNCNetInfo from '@react-native-community/netinfo/jest/netinfo-mock.js';
56
import mockSafeAreaContext from 'react-native-safe-area-context/jest/mock';
@@ -36,12 +37,18 @@ registerNativeHandlers({
3637

3738
jest.mock('react-native-reanimated', () => {
3839
const RNReanimatedmock = require('react-native-reanimated/mock');
39-
return { ...RNReanimatedmock, runOnUI: (fn) => fn };
40+
return { ...RNReanimatedmock, runOnUI: (fn: () => unknown) => fn };
4041
});
4142

4243
jest.mock('@react-native-community/netinfo', () => mockRNCNetInfo);
4344

44-
const BottomSheetMock = ({ handleComponent, children }) => (
45+
const BottomSheetMock = ({
46+
handleComponent,
47+
children,
48+
}: {
49+
handleComponent: () => ReactNode;
50+
children: ReactNode;
51+
}) => (
4552
<View>
4653
{handleComponent()}
4754
{children}

package/jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports = {
99
setupFiles: ['./node_modules/react-native-gesture-handler/jestSetup.js'],
1010
setupFilesAfterEnv: [
1111
'@testing-library/jest-native/extend-expect',
12-
require.resolve('./jest-setup.js'),
12+
require.resolve('./jest-setup.tsx'),
1313
],
1414
testEnvironment: 'node',
1515
testPathIgnorePatterns: ['/node_modules/', '/examples/', '__snapshots__', '/lib/'],

package/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"prettier": "prettier --list-different '**/*.{js,ts,tsx,md,json}' eslint.config.mjs ../.prettierrc babel.config.js",
3838
"prettier-fix": "prettier --write '**/*.{js,ts,tsx,md,json}' eslint.config.mjs ../.prettierrc babel.config.js",
3939
"test:coverage": "yarn test:unit --coverage",
40+
"test:typecheck": "tsc --noEmit -p tsconfig.test.json",
4041
"test:unit": "TZ=UTC jest",
4142
"validate-translations": "node bin/validate-translations.js",
4243
"get-version": "echo $npm_package_version",
@@ -127,9 +128,10 @@
127128
"@shopify/flash-list": "^2.1.0",
128129
"@testing-library/jest-native": "^5.4.3",
129130
"@testing-library/react-native": "13.2.0",
131+
"@total-typescript/shoehorn": "^0.1.2",
130132
"@types/better-sqlite3": "^7.6.13",
131133
"@types/eslint": "9.6.1",
132-
"@types/jest": "^29.5.14",
134+
"@types/jest": "^30.0.0",
133135
"@types/linkify-it": "5.0.0",
134136
"@types/lodash": "4.17.16",
135137
"@types/mime-types": "2.1.4",
@@ -154,7 +156,7 @@
154156
"eslint-plugin-react-hooks": "^5.2.0",
155157
"eslint-plugin-react-native": "^5.0.0",
156158
"i18next-cli": "^1.31.0",
157-
"jest": "^30.0.0",
159+
"jest": "^30.3.0",
158160
"moment-timezone": "^0.6.0",
159161
"prettier": "^3.5.3",
160162
"react": "19.1.0",

package/src/__tests__/offline-support/offline-feature.js renamed to package/src/__tests__/offline-support/offline-feature.tsx

File renamed without changes.

package/src/__tests__/offline-support/optimistic-update.js renamed to package/src/__tests__/offline-support/optimistic-update.tsx

File renamed without changes.

package/src/components/Attachment/__tests__/Attachment.test.js renamed to package/src/components/Attachment/__tests__/Attachment.test.tsx

File renamed without changes.

package/src/components/Attachment/__tests__/Gallery.test.js renamed to package/src/components/Attachment/__tests__/Gallery.test.tsx

File renamed without changes.

package/src/components/Attachment/__tests__/Giphy.test.js renamed to package/src/components/Attachment/__tests__/Giphy.test.tsx

File renamed without changes.

package/src/components/Attachment/__tests__/buildGallery.test.js renamed to package/src/components/Attachment/__tests__/buildGallery.test.ts

File renamed without changes.

package/src/components/AutoCompleteInput/__tests__/AutoCompleteInput.test.js renamed to package/src/components/AutoCompleteInput/__tests__/AutoCompleteInput.test.tsx

File renamed without changes.

0 commit comments

Comments
 (0)