Skip to content

refactor: use react jsx transform #1492

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"react-native/no-inline-styles": "off",
"react-native-a11y/has-valid-accessibility-descriptors": "off",
"react-native-a11y/has-valid-accessibility-ignores-invert-colors": 0,
"react-native-a11y/has-valid-accessibility-value": "off"
"react-native-a11y/has-valid-accessibility-value": "off",
"react/react-in-jsx-scope": "off"
}
}
3 changes: 2 additions & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
module.exports = {
presets: [
'@babel/preset-typescript',
'@babel/preset-react',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this change will affect the output generated in the build folder and hence what's get packaged into NPM package. How would that affect our users.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are shipping some minimal JSX e.g. in detectHostComponents.

['@babel/preset-react', { runtime: 'automatic' }],
[
'@babel/preset-env',

{
targets: {
node: '14',
Expand Down
1 change: 0 additions & 1 deletion src/__tests__/fireEvent-textInput.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import { Text, TextInput, TextInputProps } from 'react-native';
import { render, fireEvent } from '..';

Expand Down
22 changes: 14 additions & 8 deletions src/__tests__/renderHook.test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import React, { ReactNode } from 'react';
import {
ReactNode,
createContext,
useContext,
useEffect,
useState,
} from 'react';
import TestRenderer from 'react-test-renderer';
import { renderHook } from '../pure';

test('gives comitted result', () => {
const { result } = renderHook(() => {
const [state, setState] = React.useState(1);
const [state, setState] = useState(1);

React.useEffect(() => {
useEffect(() => {
setState(2);
}, []);

Expand All @@ -19,8 +25,8 @@ test('gives comitted result', () => {
test('allows rerendering', () => {
const { result, rerender } = renderHook(
(props: { branch: 'left' | 'right' }) => {
const [left, setLeft] = React.useState('left');
const [right, setRight] = React.useState('right');
const [left, setLeft] = useState('left');
const [right, setRight] = useState('right');

// eslint-disable-next-line jest/no-if
switch (props.branch) {
Expand All @@ -46,13 +52,13 @@ test('allows rerendering', () => {
});

test('allows wrapper components', async () => {
const Context = React.createContext('default');
const Context = createContext('default');
function Wrapper({ children }: { children: ReactNode }) {
return <Context.Provider value="provided">{children}</Context.Provider>;
}
const { result } = renderHook(
() => {
return React.useContext(Context);
return useContext(Context);
},
{
wrapper: Wrapper,
Expand Down Expand Up @@ -106,7 +112,7 @@ test('does render only once', () => {
jest.spyOn(TestRenderer, 'create');

renderHook(() => {
const [state, setState] = React.useState(1);
const [state, setState] = useState(1);
return [state, setState];
});

Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/waitForElementToBeRemoved.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import { useState } from 'react';
import { View, Text, TouchableOpacity } from 'react-native';
import { render, fireEvent, waitForElementToBeRemoved } from '..';

Expand Down
1 change: 0 additions & 1 deletion src/helpers/__tests__/accessiblity.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import {
View,
Text,
Expand Down
1 change: 0 additions & 1 deletion src/helpers/__tests__/component-tree.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import { View, Text, TextInput } from 'react-native';
import { render } from '../..';
import {
Expand Down
1 change: 0 additions & 1 deletion src/helpers/__tests__/includeHiddenElements.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import { View } from 'react-native';
import { configure, render, screen } from '../..';

Expand Down
1 change: 0 additions & 1 deletion src/matchers/__tests__/to-be-checked.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import { type AccessibilityRole, View } from 'react-native';
import render from '../../render';
import { screen } from '../../screen';
Expand Down
1 change: 0 additions & 1 deletion src/matchers/__tests__/to-be-disabled.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import {
Button,
Pressable,
Expand Down
1 change: 0 additions & 1 deletion src/matchers/__tests__/to-be-empty-element.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import { View } from 'react-native';
import { render, screen } from '../..';
import '../extend-expect';
Expand Down
1 change: 0 additions & 1 deletion src/matchers/__tests__/to-be-partially-checked.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import { type AccessibilityRole, View } from 'react-native';
import render from '../../render';
import { screen } from '../../screen';
Expand Down
1 change: 0 additions & 1 deletion src/matchers/__tests__/to-have-prop.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import { View, Text, TextInput } from 'react-native';
import { render, screen } from '../..';
import '../extend-expect';
Expand Down
1 change: 0 additions & 1 deletion src/matchers/__tests__/utils.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import { View } from 'react-native';
import { render } from '../..';
import { formatElement, checkHostElement } from '../utils';
Expand Down
1 change: 0 additions & 1 deletion src/queries/__tests__/testId.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import { View, Text, TextInput, Button } from 'react-native';
import { render } from '../..';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import { Pressable, Text } from 'react-native';
import { render, screen } from '../../../pure';
import { userEvent } from '../..';
Expand Down
1 change: 0 additions & 1 deletion src/user-event/press/__tests__/longPress.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import { Pressable, Text } from 'react-native';
import { render, screen } from '../../../pure';
import { userEvent } from '../..';
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true,
"jsx": "react",
"jsx": "react-jsx",
"target": "ES2020",
"lib": ["ES2020", "DOM"],
"module": "commonjs",
Expand Down