diff --git a/__tests__/AutocompleteInput.spec.tsx b/__tests__/AutocompleteInput.spec.tsx index e399b0c..bc0dd72 100644 --- a/__tests__/AutocompleteInput.spec.tsx +++ b/__tests__/AutocompleteInput.spec.tsx @@ -1,6 +1,7 @@ -import React from 'react'; -import renderer from 'react-test-renderer'; -import { FlatList, Text, TextInput, View } from 'react-native'; +import React, { type ReactElement } from 'react'; +import { render, screen, within } from '@testing-library/react-native'; +import { FlatList, TextInput, type FlatListProps } from 'react-native'; + import Autocomplete from '../index'; const ITEMS = [ @@ -12,111 +13,85 @@ const ITEMS = [ 'Revenge of the Sith', ] as const; +const suggestionListTestId = 'suggestionListTestId'; +function TestSuggestionList(props: FlatListProps): ReactElement { + return ; +} + describe('', () => { it('should hide suggestion list on initial render', () => { - const r = renderer.create(); - const autocomplete = r.root; - - expect(autocomplete.findAllByType(FlatList)).toHaveLength(0); + render(); + const suggestionList = screen.queryByTestId(suggestionListTestId); + expect(suggestionList).not.toBeOnTheScreen(); }); - it('should show suggestion list when data gets updated with length > 0', () => { - const testRenderer = renderer.create(); - const autocomplete = testRenderer.root; + it('should show suggestion list with suggestions when data gets updated with length > 0', () => { + const { rerender } = render(); - expect(autocomplete.findAllByType(FlatList)).toHaveLength(0); + const hiddenSuggestionList = screen.queryByTestId(suggestionListTestId); + expect(hiddenSuggestionList).not.toBeOnTheScreen(); - testRenderer.update(); + rerender(); - const list = autocomplete.findByType(FlatList); - expect(list.props.data).toEqual(ITEMS); + const suggestionList = screen.getByTestId(suggestionListTestId); + expect(suggestionList).toBeOnTheScreen(); - const texts = list.findAllByType(Text); - expect(texts).toHaveLength(ITEMS.length); + const suggestions = within(suggestionList).getAllByRole('text'); + suggestions.forEach((suggestion, index) => { + expect(suggestion).toHaveTextContent(ITEMS[index]); + }); }); - it('should hide suggestion list when data gets updates with length < 1', () => { - const props = { data: ITEMS }; - const testRenderer = renderer.create(); - const autocomplete = testRenderer.root; + it('should apply default render list function', () => { + render(); + const suggestions = screen.getAllByRole('text'); + suggestions.forEach((suggestion, index) => { + expect(suggestion).toHaveTextContent(ITEMS[index]); + }); + }); + + it('should hide suggestion list when data gets updated with length < 1', () => { + const { rerender } = render( + , + ); - expect(autocomplete.findAllByType(FlatList)).toHaveLength(1); - testRenderer.update(); + const suggestionList = screen.getByTestId(suggestionListTestId); + expect(suggestionList).toBeOnTheScreen(); - expect(autocomplete.findAllByType(FlatList)).toHaveLength(0); + rerender(); + + const hiddenSuggestionList = screen.queryByTestId(suggestionListTestId); + expect(hiddenSuggestionList).not.toBeOnTheScreen(); }); it('should render custom text input', () => { - const text = 'Custom Text Input'; - const testRenderer = renderer.create( + const customTextInputTestId = 'customTextInput'; + render( {text}} + renderTextInput={(props) => } />, ); - const autocomplete = testRenderer.root; - const customTextInput = autocomplete.findByType(Text); - - expect((customTextInput.children[0] as { children: unknown[] }).children).toEqual([text]); - expect(autocomplete.findAllByType(TextInput)).toHaveLength(0); + const textInput = screen.getByTestId(customTextInputTestId); + expect(textInput).toBeOnTheScreen(); }); it('should render default if no custom one is supplied', () => { - const props = { foo: 'bar' }; - const testRenderer = renderer.create(); - const autocomplete = testRenderer.root; - const textInput = autocomplete.findByType(TextInput); - - expect(textInput.props).toEqual(expect.objectContaining(props)); - }); - - it('should render default if no custom one is supplied', () => { - const testRenderer = renderer.create(); - const autocomplete = testRenderer.root; - const list = autocomplete.findByType(FlatList); - - expect(list.props.data).toEqual(ITEMS); - }); - - it('should only pass props in flatListProps to ', () => { - // Using keyExtractor isn't important for the test, but prevents a warning - const keyExtractor = (_, index) => `key-${index}`; - const flatListProps = { foo: 'bar', keyExtractor }; - const otherProps = { baz: 'qux' }; - const testRenderer = renderer.create( - , - ); - const autocomplete = testRenderer.root; - const list = autocomplete.findByType(FlatList); - - expect(list.props).toEqual(expect.objectContaining(flatListProps)); - expect(list.props).toEqual(expect.not.objectContaining(otherProps)); - }); - - it('should render a custom result list', () => { - const testRenderer = renderer.create( - ( - {data?.map((item, index) => {item})} - )} - />, - ); - - const autocomplete = testRenderer.root; - expect(autocomplete.findAllByType(FlatList)).toHaveLength(0); + render(); - const texts = autocomplete.findAllByType(Text); - expect(texts).toHaveLength(ITEMS.length); + const input = screen.getByPlaceholderText('Enter search'); + expect(input).toBeOnTheScreen(); }); - it('should forward the ref to the input', () => { - const inputRef = React.createRef(); + it('should forward the ref to the text input', async () => { + let ref: React.RefObject; + function TestForwardRefComponent() { + ref = React.useRef(null); + return ; + } - renderer.create(); - // eslint-disable-next-line @typescript-eslint/no-explicit-any - expect((inputRef.current as any)._reactInternals.elementType.displayName).toBe('TextInput'); + render(); + expect(ref!.current?.constructor.name).toBe('TextInput'); }); }); diff --git a/index.tsx b/index.tsx index 65ae2b0..a6adaf4 100644 --- a/index.tsx +++ b/index.tsx @@ -34,7 +34,7 @@ function DefaultTextInput(props: TextInputProps): React.ReactElement { return ; } -function AutocompleteInputComponent( +export const AutocompleteInput = React.forwardRef(function AutocompleteInputComponent( props: AutocompleteInputProps, ref: React.ForwardedRef, ): React.ReactElement { @@ -61,7 +61,7 @@ function AutocompleteInputComponent( ref, }; - return renderFunction?.(textProps); + return renderFunction(textProps); } const { @@ -90,7 +90,7 @@ function AutocompleteInputComponent( )} ); -} +}); const border = { borderColor: '#b9b9b9', @@ -150,13 +150,9 @@ const styles = StyleSheet.create({ }), }); -export const AutocompleteInput = React.forwardRef( - AutocompleteInputComponent, -) as typeof AutocompleteInputComponent; - export default AutocompleteInput; -(AutocompleteInput as React.FC).propTypes = { +AutocompleteInput.propTypes = { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore ...TextInput.propTypes, diff --git a/jest.config.js b/jest.config.js index ed694e4..157ea99 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,4 +1,5 @@ export default { preset: 'react-native', + setupFilesAfterEnv: ['@testing-library/react-native/extend-expect'], verbose: true, }; diff --git a/package-lock.json b/package-lock.json index b7cac7c..949c14a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,11 +12,10 @@ "deprecated-react-native-prop-types": "^5.0.0" }, "devDependencies": { - "@react-native/metro-config": "^0.76.1", - "@tsconfig/react-native": "^3.0.5", + "@react-native/typescript-config": "^0.76.1", + "@testing-library/react-native": "^12.8.1", "@types/jest": "^29.4.0", "@types/react": "^18.0.28", - "@types/react-test-renderer": "^18.0.0", "babel-jest": "^29.4.3", "eslint": "^9.11.1", "eslint-plugin-prettier": "^5.2.1", @@ -25,7 +24,6 @@ "prettier": "^3.3.3", "react": "^18.3.1", "react-native": "^0.76.1", - "react-test-renderer": "^18.2.0", "typescript": "^5.6.2", "typescript-eslint": "^8.8.0" } @@ -2084,9 +2082,9 @@ } }, "node_modules/@eslint-community/regexpp": { - "version": "4.12.1", - "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.12.1.tgz", - "integrity": "sha512-CCZCDJuduB9OUkFkY2IgppNZMi2lBQgD2qzwXkEia16cge2pijY/aXi96CJMquDMn3nJdlPV1A5KrJEXwfLNzQ==", + "version": "4.11.1", + "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.11.1.tgz", + "integrity": "sha512-m4DVN9ZqskZoLU5GlWZadwDnYo3vAEydiUayB9widCl9ffWx2IvPnp6n3on5rJmziJSw9Bv+Z3ChDVdMwXCY8Q==", "dev": true, "engines": { "node": "^12.0.0 || ^14.0.0 || >=16.0.0" @@ -2213,9 +2211,9 @@ } }, "node_modules/@eslint/js": { - "version": "9.14.0", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.14.0.tgz", - "integrity": "sha512-pFoEtFWCPyDOl+C6Ift+wC7Ro89otjigCf5vcuWqWgqNSQbRrpjSvdeE6ofLz4dHmyxD5f7gIdGT4+p36L6Twg==", + "version": "9.13.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.13.0.tgz", + "integrity": "sha512-IFLyoY4d72Z5y/6o/BazFBezupzI/taV8sGumxTAVw3lXG9A6md1Dc34T9s1FoD/an9pJH8RHbAxsaEbBed9lA==", "dev": true, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -2243,40 +2241,27 @@ } }, "node_modules/@humanfs/core": { - "version": "0.19.1", - "resolved": "https://registry.npmjs.org/@humanfs/core/-/core-0.19.1.tgz", - "integrity": "sha512-5DyQ4+1JEUzejeK1JGICcideyfUbGixgS9jNgex5nqkW+cY7WZhxBigmieN5Qnw9ZosSNVC9KQKyb+GUaGyKUA==", + "version": "0.19.0", + "resolved": "https://registry.npmjs.org/@humanfs/core/-/core-0.19.0.tgz", + "integrity": "sha512-2cbWIHbZVEweE853g8jymffCA+NCMiuqeECeBBLm8dg2oFdjuGJhgN4UAbI+6v0CKbbhvtXA4qV8YR5Ji86nmw==", "dev": true, "engines": { "node": ">=18.18.0" } }, "node_modules/@humanfs/node": { - "version": "0.16.6", - "resolved": "https://registry.npmjs.org/@humanfs/node/-/node-0.16.6.tgz", - "integrity": "sha512-YuI2ZHQL78Q5HbhDiBA1X4LmYdXCKCMQIfw0pw7piHJwyREFebJUvrQN4cMssyES6x+vfUbx1CIpaQUKYdQZOw==", + "version": "0.16.5", + "resolved": "https://registry.npmjs.org/@humanfs/node/-/node-0.16.5.tgz", + "integrity": "sha512-KSPA4umqSG4LHYRodq31VDwKAvaTF4xmVlzM8Aeh4PlU1JQ3IG0wiA8C25d3RQ9nJyM3mBHyI53K06VVL/oFFg==", "dev": true, "dependencies": { - "@humanfs/core": "^0.19.1", + "@humanfs/core": "^0.19.0", "@humanwhocodes/retry": "^0.3.0" }, "engines": { "node": ">=18.18.0" } }, - "node_modules/@humanfs/node/node_modules/@humanwhocodes/retry": { - "version": "0.3.1", - "resolved": "https://registry.npmjs.org/@humanwhocodes/retry/-/retry-0.3.1.tgz", - "integrity": "sha512-JBxkERygn7Bv/GbN5Rv8Ul6LVknS+5Bp6RgDC/O8gEBU/yeH5Ui5C/OlWrTb6qct7LjjfT6Re2NxB0ln0yYybA==", - "dev": true, - "engines": { - "node": ">=18.18" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/nzakas" - } - }, "node_modules/@humanwhocodes/module-importer": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/@humanwhocodes/module-importer/-/module-importer-1.0.1.tgz", @@ -2291,9 +2276,9 @@ } }, "node_modules/@humanwhocodes/retry": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/@humanwhocodes/retry/-/retry-0.4.0.tgz", - "integrity": "sha512-xnRgu9DxZbkWak/te3fcytNyp8MTbuiZIaueg2rgEvBuN55n04nwLYLU9TX/VVlusc9L2ZNXi99nUFNkHXtr5g==", + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/@humanwhocodes/retry/-/retry-0.3.1.tgz", + "integrity": "sha512-JBxkERygn7Bv/GbN5Rv8Ul6LVknS+5Bp6RgDC/O8gEBU/yeH5Ui5C/OlWrTb6qct7LjjfT6Re2NxB0ln0yYybA==", "dev": true, "engines": { "node": ">=18.18" @@ -2982,27 +2967,18 @@ "@babel/core": "*" } }, - "node_modules/@react-native/metro-config": { - "version": "0.76.1", - "resolved": "https://registry.npmjs.org/@react-native/metro-config/-/metro-config-0.76.1.tgz", - "integrity": "sha512-RvsflPKsQ1tEaHDJksnMWwW5wtv8fskMRviL/jHlEW/ULEQ/MOE2yjuvJlRQkNvfqlJjkc1mczjy4+RO3mDQ6g==", - "dev": true, - "dependencies": { - "@react-native/js-polyfills": "0.76.1", - "@react-native/metro-babel-transformer": "0.76.1", - "metro-config": "^0.81.0", - "metro-runtime": "^0.81.0" - }, - "engines": { - "node": ">=18" - } - }, "node_modules/@react-native/normalize-colors": { "version": "0.76.1", "resolved": "https://registry.npmjs.org/@react-native/normalize-colors/-/normalize-colors-0.76.1.tgz", "integrity": "sha512-/+CUk/wGWIdXbJYVLw/q6Fs8Z0x91zzfXIbNiZUdSW1TNEDmytkF371H8a1/Nx3nWa1RqCMVsaZHCG4zqxeDvg==", "dev": true }, + "node_modules/@react-native/typescript-config": { + "version": "0.76.1", + "resolved": "https://registry.npmjs.org/@react-native/typescript-config/-/typescript-config-0.76.1.tgz", + "integrity": "sha512-KcmgsFG/c3WdAqy7/06Zvfkye3XIc/0zItlFMSGMgAjFFuCTomXqpmJdrtTBheCDy+gbKaR/vWf+snL8C+OVvA==", + "dev": true + }, "node_modules/@react-native/virtualized-lists": { "version": "0.76.1", "resolved": "https://registry.npmjs.org/@react-native/virtualized-lists/-/virtualized-lists-0.76.1.tgz", @@ -3050,11 +3026,27 @@ "@sinonjs/commons": "^3.0.0" } }, - "node_modules/@tsconfig/react-native": { - "version": "3.0.5", - "resolved": "https://registry.npmjs.org/@tsconfig/react-native/-/react-native-3.0.5.tgz", - "integrity": "sha512-0+pmYzHccvwWpFz2Tv5AJxp6UroLALmAy+SX34tKlwaCie1mNbtCv6uOJp7x8pKchgNA9/n6BGrx7uLQvw8p9A==", - "dev": true + "node_modules/@testing-library/react-native": { + "version": "12.8.1", + "resolved": "https://registry.npmjs.org/@testing-library/react-native/-/react-native-12.8.1.tgz", + "integrity": "sha512-/7PIFCpeqAD3j7nzKQhZtm1T6RR/O/tB1We7JHtYP5RpTBj8rPitEpt6xGrD8R0ymOh+DxDKK7Zovfv5uDSRWg==", + "dev": true, + "dependencies": { + "jest-matcher-utils": "^29.7.0", + "pretty-format": "^29.7.0", + "redent": "^3.0.0" + }, + "peerDependencies": { + "jest": ">=28.0.0", + "react": ">=16.8.0", + "react-native": ">=0.59", + "react-test-renderer": ">=16.8.0" + }, + "peerDependenciesMeta": { + "jest": { + "optional": true + } + } }, "node_modules/@types/babel__core": { "version": "7.20.5", @@ -3186,15 +3178,6 @@ "csstype": "^3.0.2" } }, - "node_modules/@types/react-test-renderer": { - "version": "18.3.0", - "resolved": "https://registry.npmjs.org/@types/react-test-renderer/-/react-test-renderer-18.3.0.tgz", - "integrity": "sha512-HW4MuEYxfDbOHQsVlY/XtOvNHftCVEPhJF2pQXXwcUiUF+Oyb0usgp48HSgpK5rt8m9KZb22yqOeZm+rrVG8gw==", - "dev": true, - "dependencies": { - "@types/react": "*" - } - }, "node_modules/@types/stack-utils": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.3.tgz", @@ -3217,16 +3200,16 @@ "dev": true }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "8.14.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.14.0.tgz", - "integrity": "sha512-tqp8H7UWFaZj0yNO6bycd5YjMwxa6wIHOLZvWPkidwbgLCsBMetQoGj7DPuAlWa2yGO3H48xmPwjhsSPPCGU5w==", + "version": "8.12.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.12.0.tgz", + "integrity": "sha512-uRqchEKT0/OwDePTwCjSFO2aH4zccdeQ7DgAzM/8fuXc+PAXvpdMRbuo+oCmK1lSfXssk2UUBNiWihobKxQp/g==", "dev": true, "dependencies": { "@eslint-community/regexpp": "^4.10.0", - "@typescript-eslint/scope-manager": "8.14.0", - "@typescript-eslint/type-utils": "8.14.0", - "@typescript-eslint/utils": "8.14.0", - "@typescript-eslint/visitor-keys": "8.14.0", + "@typescript-eslint/scope-manager": "8.12.0", + "@typescript-eslint/type-utils": "8.12.0", + "@typescript-eslint/utils": "8.12.0", + "@typescript-eslint/visitor-keys": "8.12.0", "graphemer": "^1.4.0", "ignore": "^5.3.1", "natural-compare": "^1.4.0", @@ -3250,15 +3233,15 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "8.14.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.14.0.tgz", - "integrity": "sha512-2p82Yn9juUJq0XynBXtFCyrBDb6/dJombnz6vbo6mgQEtWHfvHbQuEa9kAOVIt1c9YFwi7H6WxtPj1kg+80+RA==", + "version": "8.12.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.12.0.tgz", + "integrity": "sha512-7U20duDQWAOhCk2VtyY41Vor/CJjiEW063Zel9aoRXq89FQ/jr+0e0m3kxh9Sk5SFW9B1AblVIBtXd+1xQ1NWQ==", "dev": true, "dependencies": { - "@typescript-eslint/scope-manager": "8.14.0", - "@typescript-eslint/types": "8.14.0", - "@typescript-eslint/typescript-estree": "8.14.0", - "@typescript-eslint/visitor-keys": "8.14.0", + "@typescript-eslint/scope-manager": "8.12.0", + "@typescript-eslint/types": "8.12.0", + "@typescript-eslint/typescript-estree": "8.12.0", + "@typescript-eslint/visitor-keys": "8.12.0", "debug": "^4.3.4" }, "engines": { @@ -3278,13 +3261,13 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "8.14.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.14.0.tgz", - "integrity": "sha512-aBbBrnW9ARIDn92Zbo7rguLnqQ/pOrUguVpbUwzOhkFg2npFDwTgPGqFqE0H5feXcOoJOfX3SxlJaKEVtq54dw==", + "version": "8.12.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.12.0.tgz", + "integrity": "sha512-jbuCXK18iEshRFUtlCIMAmOKA6OAsKjo41UcXPqx7ZWh2b4cmg6pV/pNcZSB7oW9mtgF95yizr7Jnwt3IUD2pA==", "dev": true, "dependencies": { - "@typescript-eslint/types": "8.14.0", - "@typescript-eslint/visitor-keys": "8.14.0" + "@typescript-eslint/types": "8.12.0", + "@typescript-eslint/visitor-keys": "8.12.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -3295,13 +3278,13 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "8.14.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.14.0.tgz", - "integrity": "sha512-Xcz9qOtZuGusVOH5Uk07NGs39wrKkf3AxlkK79RBK6aJC1l03CobXjJbwBPSidetAOV+5rEVuiT1VSBUOAsanQ==", + "version": "8.12.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.12.0.tgz", + "integrity": "sha512-cHioAZO/nLgyzTmwv7gWIjEKMHSbioKEZqLCaItTn7RvJP1QipuGVwEjPJa6Kv9u9UiUMVAESY9JH186TjKITw==", "dev": true, "dependencies": { - "@typescript-eslint/typescript-estree": "8.14.0", - "@typescript-eslint/utils": "8.14.0", + "@typescript-eslint/typescript-estree": "8.12.0", + "@typescript-eslint/utils": "8.12.0", "debug": "^4.3.4", "ts-api-utils": "^1.3.0" }, @@ -3319,9 +3302,9 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "8.14.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.14.0.tgz", - "integrity": "sha512-yjeB9fnO/opvLJFAsPNYlKPnEM8+z4og09Pk504dkqonT02AyL5Z9SSqlE0XqezS93v6CXn49VHvB2G7XSsl0g==", + "version": "8.12.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.12.0.tgz", + "integrity": "sha512-Cc+iNtqBJ492f8KLEmKXe1l6683P0MlFO8Bk1NMphnzVIGH4/Wn9kvandFH+gYR1DDUjH/hgeWRGdO5Tj8gjYg==", "dev": true, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -3332,13 +3315,13 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "8.14.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.14.0.tgz", - "integrity": "sha512-OPXPLYKGZi9XS/49rdaCbR5j/S14HazviBlUQFvSKz3npr3NikF+mrgK7CFVur6XEt95DZp/cmke9d5i3vtVnQ==", + "version": "8.12.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.12.0.tgz", + "integrity": "sha512-a4koVV7HHVOQWcGb6ZcAlunJnAdwo/CITRbleQBSjq5+2WLoAJQCAAiecvrAdSM+n/man6Ghig5YgdGVIC6xqw==", "dev": true, "dependencies": { - "@typescript-eslint/types": "8.14.0", - "@typescript-eslint/visitor-keys": "8.14.0", + "@typescript-eslint/types": "8.12.0", + "@typescript-eslint/visitor-keys": "8.12.0", "debug": "^4.3.4", "fast-glob": "^3.3.2", "is-glob": "^4.0.3", @@ -3372,15 +3355,15 @@ } }, "node_modules/@typescript-eslint/utils": { - "version": "8.14.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.14.0.tgz", - "integrity": "sha512-OGqj6uB8THhrHj0Fk27DcHPojW7zKwKkPmHXHvQ58pLYp4hy8CSUdTKykKeh+5vFqTTVmjz0zCOOPKRovdsgHA==", + "version": "8.12.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.12.0.tgz", + "integrity": "sha512-5i1tqLwlf0fpX1j05paNKyIzla/a4Y3Xhh6AFzi0do/LDJLvohtZYaisaTB9kq0D4uBocAxWDTGzNMOCCwIgXA==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", - "@typescript-eslint/scope-manager": "8.14.0", - "@typescript-eslint/types": "8.14.0", - "@typescript-eslint/typescript-estree": "8.14.0" + "@typescript-eslint/scope-manager": "8.12.0", + "@typescript-eslint/types": "8.12.0", + "@typescript-eslint/typescript-estree": "8.12.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -3394,12 +3377,12 @@ } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "8.14.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.14.0.tgz", - "integrity": "sha512-vG0XZo8AdTH9OE6VFRwAZldNc7qtJ/6NLGWak+BtENuEUXGZgFpihILPiBvKXvJ2nFu27XNGC6rKiwuaoMbYzQ==", + "version": "8.12.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.12.0.tgz", + "integrity": "sha512-2rXkr+AtZZLuNY18aUjv5wtB9oUiwY1WnNi7VTsdCdy1m958ULeUKoAegldQTjqpbpNJ5cQ4egR8/bh5tbrKKQ==", "dev": true, "dependencies": { - "@typescript-eslint/types": "8.14.0", + "@typescript-eslint/types": "8.12.0", "eslint-visitor-keys": "^3.4.3" }, "engines": { @@ -3436,9 +3419,9 @@ } }, "node_modules/acorn": { - "version": "8.14.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.14.0.tgz", - "integrity": "sha512-cl669nCJTZBsL97OF4kUQm5g5hC2uihk0NxY3WENAC0TYdILVkAyHymAntgxGkl7K+t0cXIrH5siy5S4XkFycA==", + "version": "8.12.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.12.1.tgz", + "integrity": "sha512-tcpGyI9zbizT9JbV6oYE477V6mTlXvvi0T0G3SNIYE2apm/G5huBa1+K89VGeovbg+jycCrfhl3ADxErOuO6Jg==", "dev": true, "bin": { "acorn": "bin/acorn" @@ -4812,21 +4795,21 @@ } }, "node_modules/eslint": { - "version": "9.14.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.14.0.tgz", - "integrity": "sha512-c2FHsVBr87lnUtjP4Yhvk4yEhKrQavGafRA/Se1ouse8PfbfC/Qh9Mxa00yWsZRlqeUB9raXip0aiiUZkgnr9g==", + "version": "9.13.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.13.0.tgz", + "integrity": "sha512-EYZK6SX6zjFHST/HRytOdA/zE72Cq/bfw45LSyuwrdvcclb/gqV8RRQxywOBEWO2+WDpva6UZa4CcDeJKzUCFA==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", - "@eslint-community/regexpp": "^4.12.1", + "@eslint-community/regexpp": "^4.11.0", "@eslint/config-array": "^0.18.0", "@eslint/core": "^0.7.0", "@eslint/eslintrc": "^3.1.0", - "@eslint/js": "9.14.0", + "@eslint/js": "9.13.0", "@eslint/plugin-kit": "^0.2.0", - "@humanfs/node": "^0.16.6", + "@humanfs/node": "^0.16.5", "@humanwhocodes/module-importer": "^1.0.1", - "@humanwhocodes/retry": "^0.4.0", + "@humanwhocodes/retry": "^0.3.1", "@types/estree": "^1.0.6", "@types/json-schema": "^7.0.15", "ajv": "^6.12.4", @@ -4834,9 +4817,9 @@ "cross-spawn": "^7.0.2", "debug": "^4.3.2", "escape-string-regexp": "^4.0.0", - "eslint-scope": "^8.2.0", - "eslint-visitor-keys": "^4.2.0", - "espree": "^10.3.0", + "eslint-scope": "^8.1.0", + "eslint-visitor-keys": "^4.1.0", + "espree": "^10.2.0", "esquery": "^1.5.0", "esutils": "^2.0.2", "fast-deep-equal": "^3.1.3", @@ -4987,9 +4970,9 @@ } }, "node_modules/eslint-scope": { - "version": "8.2.0", - "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-8.2.0.tgz", - "integrity": "sha512-PHlWUfG6lvPc3yvP5A4PNyBL1W8fkDUccmI21JUu/+GKZBoH/W5u6usENXUrWFRsyoW5ACUjFGgAFQp5gUlb/A==", + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-8.1.0.tgz", + "integrity": "sha512-14dSvlhaVhKKsa9Fx1l8A17s7ah7Ef7wCakJ10LYk6+GYmP9yDti2oq2SEwcyndt6knfcZyhyxwY3i9yL78EQw==", "dev": true, "dependencies": { "esrecurse": "^4.3.0", @@ -5025,9 +5008,9 @@ } }, "node_modules/eslint/node_modules/eslint-visitor-keys": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-4.2.0.tgz", - "integrity": "sha512-UyLnSehNt62FFhSwjZlHmeokpRK59rcz29j+F1/aDgbkbRTk7wIc9XzdoasMUbRNKDM0qQt/+BJ4BrpFeABemw==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-4.1.0.tgz", + "integrity": "sha512-Q7lok0mqMUSf5a/AdAZkA5a/gHcO6snwQClVNNvFKCAVlxXucdU8pKydU5ZVZjBx5xr37vGbFFWtLQYreLzrZg==", "dev": true, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -5095,14 +5078,14 @@ } }, "node_modules/espree": { - "version": "10.3.0", - "resolved": "https://registry.npmjs.org/espree/-/espree-10.3.0.tgz", - "integrity": "sha512-0QYC8b24HWY8zjRnDTL6RiHfDbAWn63qb4LMj1Z4b076A4une81+z03Kg7l7mn/48PUTqoLptSXez8oknU8Clg==", + "version": "10.2.0", + "resolved": "https://registry.npmjs.org/espree/-/espree-10.2.0.tgz", + "integrity": "sha512-upbkBJbckcCNBDBDXEbuhjbP68n+scUd3k/U2EkyM9nw+I/jPiL4cLF/Al06CF96wRltFda16sxDFrxsI1v0/g==", "dev": true, "dependencies": { - "acorn": "^8.14.0", + "acorn": "^8.12.0", "acorn-jsx": "^5.3.2", - "eslint-visitor-keys": "^4.2.0" + "eslint-visitor-keys": "^4.1.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -5112,9 +5095,9 @@ } }, "node_modules/espree/node_modules/eslint-visitor-keys": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-4.2.0.tgz", - "integrity": "sha512-UyLnSehNt62FFhSwjZlHmeokpRK59rcz29j+F1/aDgbkbRTk7wIc9XzdoasMUbRNKDM0qQt/+BJ4BrpFeABemw==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-4.1.0.tgz", + "integrity": "sha512-Q7lok0mqMUSf5a/AdAZkA5a/gHcO6snwQClVNNvFKCAVlxXucdU8pKydU5ZVZjBx5xr37vGbFFWtLQYreLzrZg==", "dev": true, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -5999,6 +5982,15 @@ "node": ">=0.8.19" } }, + "node_modules/indent-string": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/indent-string/-/indent-string-4.0.0.tgz", + "integrity": "sha512-EdDDZu4A2OyIK7Lr/2zG+w5jmbuk1DVBnEwREQvBzspBJkCEbRa8GxU1lghYcaGJCnRWibjDXlq779X1/y5xwg==", + "dev": true, + "engines": { + "node": ">=8" + } + }, "node_modules/inflight": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", @@ -7904,6 +7896,15 @@ "node": ">=6" } }, + "node_modules/min-indent": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/min-indent/-/min-indent-1.0.1.tgz", + "integrity": "sha512-I9jwMn07Sy/IwOj3zVkVik2JTvgpaykDZEigL6Rx6N9LbMywwUSMtxET+7lVoDLLd3O3IXwJwvuuns8UB/HeAg==", + "dev": true, + "engines": { + "node": ">=4" + } + }, "node_modules/minimatch": { "version": "9.0.5", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", @@ -8736,6 +8737,7 @@ "resolved": "https://registry.npmjs.org/react-shallow-renderer/-/react-shallow-renderer-16.15.0.tgz", "integrity": "sha512-oScf2FqQ9LFVQgA73vr86xl2NaOIX73rh+YFqcOp68CWj56tSfgtGKrEbyhCj0rSijyG9M1CYprTh39fBi5hzA==", "dev": true, + "peer": true, "dependencies": { "object-assign": "^4.1.1", "react-is": "^16.12.0 || ^17.0.0 || ^18.0.0" @@ -8749,6 +8751,7 @@ "resolved": "https://registry.npmjs.org/react-test-renderer/-/react-test-renderer-18.3.1.tgz", "integrity": "sha512-KkAgygexHUkQqtvvx/otwxtuFu5cVjfzTCtjXLH9boS19/Nbtg84zS7wIQn39G8IlrhThBpQsMKkq5ZHZIYFXA==", "dev": true, + "peer": true, "dependencies": { "react-is": "^18.3.1", "react-shallow-renderer": "^16.15.0", @@ -8763,6 +8766,7 @@ "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.23.2.tgz", "integrity": "sha512-UOShsPwz7NrMUqhR6t0hWjFduvOzbtv7toDH1/hIrfRNIDBnnBWd0CwJTGvTpngVlmwGCdP9/Zl/tVrDqcuYzQ==", "dev": true, + "peer": true, "dependencies": { "loose-envify": "^1.1.0" } @@ -8809,6 +8813,19 @@ "node": ">= 4" } }, + "node_modules/redent": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/redent/-/redent-3.0.0.tgz", + "integrity": "sha512-6tDA8g98We0zd0GvVeMT9arEOnTw9qM03L9cJXaCjrip1OO764RDBLBfrB4cwzNGDj5OA5ioymC9GkizgWJDUg==", + "dev": true, + "dependencies": { + "indent-string": "^4.0.0", + "strip-indent": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/reflect.getprototypeof": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/reflect.getprototypeof/-/reflect.getprototypeof-1.0.6.tgz", @@ -9553,6 +9570,18 @@ "node": ">=6" } }, + "node_modules/strip-indent": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/strip-indent/-/strip-indent-3.0.0.tgz", + "integrity": "sha512-laJTa3Jb+VQpaC6DseHhF7dXVqHTfJPCRDaEbid/drOhgitgYku/letMUqOXFoWV0zIIUbjpdH2t+tYj4bQMRQ==", + "dev": true, + "dependencies": { + "min-indent": "^1.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/strip-json-comments": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", @@ -9756,9 +9785,9 @@ "dev": true }, "node_modules/ts-api-utils": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-1.4.0.tgz", - "integrity": "sha512-032cPxaEKwM+GT3vA5JXNzIaizx388rhsSW79vGRNGXfRRAdEAn2mvk36PvK5HnOchyWZ7afLEXqYCvPCrzuzQ==", + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-1.3.0.tgz", + "integrity": "sha512-UQMIo7pb8WRomKR1/+MFVLTroIvDVtMX3K6OUir8ynLyzB8Jeriont2bTAtmNPa1ekAgN7YPDyf6V+ygrdU+eQ==", "dev": true, "engines": { "node": ">=16" @@ -9893,14 +9922,14 @@ } }, "node_modules/typescript-eslint": { - "version": "8.14.0", - "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-8.14.0.tgz", - "integrity": "sha512-K8fBJHxVL3kxMmwByvz8hNdBJ8a0YqKzKDX6jRlrjMuNXyd5T2V02HIq37+OiWXvUUOXgOOGiSSOh26Mh8pC3w==", + "version": "8.12.0", + "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-8.12.0.tgz", + "integrity": "sha512-m8aQM4pqc17dcD3BsQzUqVXkcclCspuCCv7GhYlwMWNYAXFV8xJkn8vUM8YxoR78BY6S+NX/J7rfNVaGNLgXgQ==", "dev": true, "dependencies": { - "@typescript-eslint/eslint-plugin": "8.14.0", - "@typescript-eslint/parser": "8.14.0", - "@typescript-eslint/utils": "8.14.0" + "@typescript-eslint/eslint-plugin": "8.12.0", + "@typescript-eslint/parser": "8.12.0", + "@typescript-eslint/utils": "8.12.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" diff --git a/package.json b/package.json index 2d6d179..58f8c75 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "test": "npm run lint && npm run testonly", "lint": "eslint", "testonly": "jest", - "build": "rm -rf dist && tsc" + "build": "rm -rf dist && tsc --project tsconfig.build.json" }, "repository": { "type": "git", @@ -33,11 +33,10 @@ }, "homepage": "https://github.com/byteburgers/react-native-autocomplete-input#readme", "devDependencies": { - "@react-native/metro-config": "^0.76.1", - "@tsconfig/react-native": "^3.0.5", + "@react-native/typescript-config": "^0.76.1", + "@testing-library/react-native": "^12.8.1", "@types/jest": "^29.4.0", "@types/react": "^18.0.28", - "@types/react-test-renderer": "^18.0.0", "babel-jest": "^29.4.3", "eslint": "^9.11.1", "eslint-plugin-prettier": "^5.2.1", @@ -46,7 +45,6 @@ "prettier": "^3.3.3", "react": "^18.3.1", "react-native": "^0.76.1", - "react-test-renderer": "^18.2.0", "typescript": "^5.6.2", "typescript-eslint": "^8.8.0" }, diff --git a/tsconfig.build.json b/tsconfig.build.json new file mode 100644 index 0000000..e4bf39a --- /dev/null +++ b/tsconfig.build.json @@ -0,0 +1,10 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "noEmit": false, + "outDir": "./dist", + "declaration": true, + "allowImportingTsExtensions": false + }, + "include": ["index.tsx"] +} diff --git a/tsconfig.json b/tsconfig.json index b5956bb..61dffe1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,18 +1,6 @@ { - "extends": "@tsconfig/react-native/tsconfig.json", + "extends": "@react-native/typescript-config/tsconfig.json", "compilerOptions": { - "declaration": true, - "outDir": "dist", - "noEmit": false, - "target": "es2022", - "module": "esnext", - "esModuleInterop": true, - }, - "files": ["index.tsx", "types.d.ts"], - "exclude": [ - "__tests__", - "node_modules", - "babel.config.js", - "jest.config.js" - ] + "types": ["@testing-library/react-native/extend-expect", "jest", "./types.d.ts"] + } }