Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

Commit

Permalink
refactor: extract test code to test dir
Browse files Browse the repository at this point in the history
  • Loading branch information
hyochan committed Nov 27, 2022
1 parent a8c6e45 commit eb79c71
Show file tree
Hide file tree
Showing 14 changed files with 23 additions and 24 deletions.
6 changes: 3 additions & 3 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = {
coverageDirectory: './coverage/',
coveragePathIgnorePatterns: [
'/node_modules/',
'/test/',
'/test/utils',
'/dist/',
'src/models',
'src/stores',
Expand All @@ -19,12 +19,12 @@ module.exports = {
],
collectCoverage: true,
moduleDirectories: ['node_modules', 'src'],
setupFiles: ['./test/jestSetup.ts'],
setupFiles: ['./test/utils/jestSetup.ts'],
transform: {
...tsJestConfig.transform,
'^.+\\.(ts|tsx)$': 'ts-jest',
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
'<rootDir>/test/fileTransformer.js',
'<rootDir>/test/utils/fileTransformer.js',
},
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(js?|jsx?|ts?|tsx?)$',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import React from 'react';
import type {RenderResult} from '@testing-library/react';
import RootProvider from '../../../src/providers';
import SwitchNavigator from '../../../src/components/navigations/SwitchNavigator';
import {render} from '@testing-library/react';

import React from 'react';
import RootProvider from '../../../providers/index';
import SwitchNavigator from '../SwitchNavigator';

const props = {};

const component = (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as renderer from 'react-test-renderer';

import type {RenderResult} from '@testing-library/react';
import {act, cleanup, fireEvent, render} from '@testing-library/react';

import Button from '../../uis/Button';
import Intro from '../Intro';
import Button from '../../../src/components/uis/Button';
import Intro from '../../../src/components/pages/Intro';
import React from 'react';
import {createTestElement} from '../../../../test/testUtils';
import type {RenderResult} from '@testing-library/react';
import {createTestElement} from '../../utils/testUtils';

const props = {};
const component = createTestElement(<Intro {...props} />);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type * as ReactRouterDom from 'react-router-dom';
import * as renderer from 'react-test-renderer';

import type {RenderResult} from '@testing-library/react';
import {fireEvent, render} from '@testing-library/react';

import React from 'react';
import Temp from '../Temp';
import {createTestElement} from '../../../../test/testUtils';
import type {RenderResult} from '@testing-library/react';
import Temp from '../../../src/components/pages/Temp';
import {createTestElement} from '../../utils/testUtils';

const props = {};
const component = createTestElement(<Temp {...props} />);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import * as renderer from 'react-test-renderer';

import type {ReactElement} from 'react';
import Button from '../../../src/components/uis/Button';
import {IC_FACEBOOK_W} from '../../../src/utils/Icons';
import React from 'react';

import Button from '../Button';
import {IC_FACEBOOK_W} from '../../../utils/Icons';
import type {ReactElement} from 'react';

// test for the pure component
describe('[Button] shared component test', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as renderer from 'react-test-renderer';

import React from 'react';
import UserCard from '../UserCard';
import {createTestElement} from '../../../../test/testUtils';
import UserCard from '../../../src/components/uis/UserCard';
import {createTestElement} from '../../utils/testUtils';

const props = {};
const component = createTestElement(<UserCard {...props} />);
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion test/jestSetup.ts → test/utils/jestSetup.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import dotenv from 'dotenv';
import { initFbt } from '../src/utils/fbt';
import {initFbt} from '../../src/utils/fbt';

dotenv.config();

Expand Down
7 changes: 4 additions & 3 deletions test/testUtils.tsx → test/utils/testUtils.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {BrowserRouter, Route, Routes} from 'react-router-dom';
import React, {ReactElement} from 'react';

import RootProvider from '../src/providers';
import {ThemeType} from '../src/types';
import React from 'react';
import type {ReactElement} from 'react';
import RootProvider from '../../src/providers';
import type {ThemeType} from '../../src/types';

export const createTestElement = (
child: ReactElement,
Expand Down

0 comments on commit eb79c71

Please sign in to comment.