-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(test-utils): add package for test utils (#256)
# Overview <!-- A clear and concise description of what this pr is about. --> I add new dev package @suspensive/test-utils to gather test-utils resolve #234 (comment) ## PR Checklist - [x] I did below actions if need 1. I read the [Contributing Guide](https://github.com/suspensive/react/blob/main/CONTRIBUTING.md) 2. I added documents and tests.
- Loading branch information
Showing
21 changed files
with
136 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@suspensive/react-await": patch | ||
"@suspensive/react": patch | ||
--- | ||
|
||
refactor: add @suspensive/test-utils as dev dependency to remove unnecessary repetitive code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** @type {import('eslint').Linter.Config} */ | ||
module.exports = { | ||
root: true, | ||
extends: ['@suspensive/eslint-config/react-ts'], | ||
ignorePatterns: ['*.js*', 'dist', 'coverage'], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "@suspensive/test-utils", | ||
"version": "0.0.0", | ||
"private": true, | ||
"funding": { | ||
"type": "github", | ||
"url": "https://github.com/sponsors/manudeli" | ||
}, | ||
"license": "MIT", | ||
"author": { | ||
"name": "Jonghyeon Ko", | ||
"email": "[email protected]" | ||
}, | ||
"sideEffects": false, | ||
"type": "module", | ||
"main": "src/index.ts", | ||
"scripts": { | ||
"lint": "eslint \"**/*.ts*\"", | ||
"type:check": "tsc --noEmit" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "^18.2.0", | ||
"react": "^18.2.0" | ||
}, | ||
"peerDependencies": { | ||
"react": "^16.8 || ^17 || ^18" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import type { PropsWithChildren } from 'react' | ||
import { useEffect, useState } from 'react' | ||
|
||
const useSetTimeout = (fn: (...args: []) => void, delay: number) => | ||
useEffect(() => { | ||
const timeout = setTimeout(fn, delay) | ||
return () => clearTimeout(timeout) | ||
}, [fn, delay]) | ||
|
||
const throwErrorIsNeed = { current: false } | ||
type ThrowErrorProps = PropsWithChildren<{ message: string; after?: number }> | ||
export const ThrowError = ({ message, after = 0, children }: ThrowErrorProps) => { | ||
const [isNeedError, setIsNeedError] = useState(after === 0 ? true : throwErrorIsNeed.current) | ||
if (isNeedError) { | ||
throw new Error(message) | ||
} | ||
useSetTimeout(() => setIsNeedError(true), after) | ||
return <>{children}</> | ||
} | ||
|
||
type ThrowNullProps = PropsWithChildren<{ after: number }> | ||
export const ThrowNull = ({ after, children }: ThrowNullProps) => { | ||
const [isNeedError, setIsNeedError] = useState(throwErrorIsNeed.current) | ||
if (isNeedError) { | ||
throw null | ||
} | ||
useSetTimeout(() => setIsNeedError(true), after) | ||
return <>{children}</> | ||
} | ||
|
||
ThrowError.reset = () => { | ||
throwErrorIsNeed.current = false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const delay = (ms: number) => new Promise((resolve) => setTimeout(() => resolve('done'), ms)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export { Suspend } from './Suspend' | ||
export { ThrowError, ThrowNull } from './ThrowError' | ||
export { delay } from './delay' | ||
export const TEXT = 'TEXT' as const | ||
export const ERROR_MESSAGE = 'ERROR_MESSAGE' as const | ||
export const FALLBACK = 'FALLBACK' as const | ||
export const MS_100 = 100 as const |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "@suspensive/tsconfig/react-library.json", | ||
"include": ["."], | ||
"compilerOptions": { | ||
"types": ["@testing-library/jest-dom"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters