Skip to content

Commit

Permalink
Merge branch 'main' into fix/tsup-remove-experimental-entry
Browse files Browse the repository at this point in the history
  • Loading branch information
manudeli authored Oct 29, 2023
2 parents d4f4442 + 3c3ab44 commit 0c18ccf
Show file tree
Hide file tree
Showing 19 changed files with 117 additions and 89 deletions.
7 changes: 0 additions & 7 deletions .changeset/smooth-poets-glow.md

This file was deleted.

1 change: 0 additions & 1 deletion configs/test-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ 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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"husky": "^8.0.3",
"jsdom": "^22.1.0",
"lint-staged": "^13.2.2",
"ms": "^3.0.0-canary.1",
"packlint": "^0.2.4",
"prettier": "^2.8.8",
"publint": "^0.2.2",
Expand Down
6 changes: 6 additions & 0 deletions packages/react-await/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @suspensive/react-await

## 0.0.3

### Patch Changes

- 257b672: fix: add module field of package.json

## 0.0.2

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/react-await/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@suspensive/react-await",
"version": "0.0.2",
"version": "0.0.3",
"description": "Useful interfaces for React Suspense",
"keywords": [
"suspensive",
Expand Down
19 changes: 10 additions & 9 deletions packages/react-await/src/Await.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { ErrorBoundary, Suspense } from '@suspensive/react'
import { ERROR_MESSAGE, FALLBACK, MS_100, TEXT, delay } from '@suspensive/test-utils'
import { ERROR_MESSAGE, FALLBACK, TEXT, delay } from '@suspensive/test-utils'
import { act, render, screen, waitFor } from '@testing-library/react'
import ms from 'ms'
import { vi } from 'vitest'
import { Await, awaitClient, useAwait } from '.'

const key = (id: number) => ['key', id] as const

const AwaitSuccess = () => {
const awaited = useAwait({ key: key(1), fn: () => delay(MS_100).then(() => TEXT) })
const awaited = useAwait({ key: key(1), fn: () => delay(ms('0.1s')).then(() => TEXT) })

return (
<>
Expand All @@ -20,7 +21,7 @@ const AwaitSuccess = () => {
const AwaitFailure = () => {
const awaited = useAwait({
key: key(1),
fn: () => delay(MS_100).then(() => Promise.reject(new Error(ERROR_MESSAGE))),
fn: () => delay(ms('0.1s')).then(() => Promise.reject(new Error(ERROR_MESSAGE))),
})

return <>{awaited.data}</>
Expand Down Expand Up @@ -49,7 +50,7 @@ describe('useAwait', () => {
)
expect(screen.queryByText(FALLBACK)).toBeInTheDocument()

act(() => vi.advanceTimersByTime(MS_100))
act(() => vi.advanceTimersByTime(ms('0.1s')))
await waitFor(() => expect(screen.queryByText(TEXT)).toBeInTheDocument())

// success data cache test
Expand All @@ -73,7 +74,7 @@ describe('useAwait', () => {
</ErrorBoundary>
)
expect(screen.queryByText(FALLBACK)).toBeInTheDocument()
act(() => vi.advanceTimersByTime(MS_100))
act(() => vi.advanceTimersByTime(ms('0.1s')))
await waitFor(() => expect(screen.queryByText(ERROR_MESSAGE)).toBeInTheDocument())

// error cache test
Expand All @@ -97,7 +98,7 @@ describe('useAwait', () => {
</Suspense>
)
expect(screen.queryByText(FALLBACK)).toBeInTheDocument()
act(() => vi.advanceTimersByTime(MS_100))
act(() => vi.advanceTimersByTime(ms('0.1s')))
await waitFor(() => expect(screen.queryByText(TEXT)).toBeInTheDocument())
const resetButton = await screen.findByRole('button', { name: 'Try again' })
resetButton.click()
Expand All @@ -107,7 +108,7 @@ describe('useAwait', () => {
</Suspense>
)
expect(screen.queryByText(FALLBACK)).toBeInTheDocument()
act(() => vi.advanceTimersByTime(MS_100))
act(() => vi.advanceTimersByTime(ms('0.1s')))
await waitFor(() => expect(screen.queryByText(TEXT)).toBeInTheDocument())
})
})
Expand Down Expand Up @@ -187,7 +188,7 @@ describe('awaitClient', () => {
vi.useFakeTimers()
render(
<Suspense fallback={FALLBACK}>
<Await options={{ key: key(1), fn: () => delay(MS_100).then(() => TEXT) }}>
<Await options={{ key: key(1), fn: () => delay(ms('0.1s')).then(() => TEXT) }}>
{(awaited) => <>{awaited.data}</>}
</Await>
</Suspense>
Expand All @@ -196,7 +197,7 @@ describe('awaitClient', () => {
expect(screen.queryByText(FALLBACK)).toBeInTheDocument()
expect(screen.queryByText(TEXT)).not.toBeInTheDocument()
expect(awaitClient.getData(key(1))).toBeUndefined()
act(() => vi.advanceTimersByTime(MS_100))
act(() => vi.advanceTimersByTime(ms('0.1s')))
await waitFor(() => expect(screen.queryByText(TEXT)).toBeInTheDocument())
expect(screen.queryByText(FALLBACK)).not.toBeInTheDocument()
expect(awaitClient.getData(key(1))).toBe(TEXT)
Expand Down
8 changes: 8 additions & 0 deletions packages/react-query/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @suspensive/react-query

## 1.17.7

### Patch Changes

- 257b672: fix: add module field of package.json
- Updated dependencies [257b672]
- @suspensive/react@1.17.7

## 1.17.6

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/react-query/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@suspensive/react-query",
"version": "1.17.6",
"version": "1.17.7",
"description": "Useful helpers for @tanstack/react-query with suspense",
"keywords": [
"suspensive",
Expand Down Expand Up @@ -71,7 +71,7 @@
"tsd": "^0.28.1"
},
"peerDependencies": {
"@suspensive/react": "workspace:^1.17.6",
"@suspensive/react": "workspace:^1.17.7",
"@tanstack/react-query": "^4",
"react": "^16.8 || ^17 || ^18"
},
Expand Down
6 changes: 6 additions & 0 deletions packages/react/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @suspensive/react

## 1.17.7

### Patch Changes

- 257b672: fix: add module field of package.json

## 1.17.6

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@suspensive/react",
"version": "1.17.6",
"version": "1.17.7",
"description": "Useful interfaces for React Suspense",
"keywords": [
"suspensive",
Expand Down
11 changes: 6 additions & 5 deletions packages/react/src/AsyncBoundary.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ERROR_MESSAGE, FALLBACK, MS_100, Suspend, TEXT, ThrowError } from '@suspensive/test-utils'
import { ERROR_MESSAGE, FALLBACK, Suspend, TEXT, ThrowError } from '@suspensive/test-utils'
import { act, render, waitFor } from '@testing-library/react'
import ms from 'ms'
import type { ComponentProps } from 'react'
import { createElement } from 'react'
import { createRoot } from 'react-dom/client'
Expand Down Expand Up @@ -56,7 +57,7 @@ describe('<AsyncBoundary/>', () => {
rejectedFallback: ERROR_MESSAGE,
onError,
children: (
<ThrowError message={ERROR_MESSAGE} after={MS_100}>
<ThrowError message={ERROR_MESSAGE} after={ms('0.1s')}>
{TEXT}
</ThrowError>
),
Expand All @@ -65,7 +66,7 @@ describe('<AsyncBoundary/>', () => {
expect(container.textContent).not.toBe(FALLBACK)
expect(container.textContent).not.toBe(ERROR_MESSAGE)
expect(onError).toHaveBeenCalledTimes(0)
act(() => vi.advanceTimersByTime(MS_100))
act(() => vi.advanceTimersByTime(ms('0.1s')))
await waitFor(() => {
expect(container.textContent).toBe(ERROR_MESSAGE)
expect(container.textContent).not.toBe(TEXT)
Expand Down Expand Up @@ -116,7 +117,7 @@ describe('<AsyncBoundary.CSROnly/>', () => {
rejectedFallback: ERROR_MESSAGE,
onError,
children: (
<ThrowError message={ERROR_MESSAGE} after={MS_100}>
<ThrowError message={ERROR_MESSAGE} after={ms('0.1s')}>
{TEXT}
</ThrowError>
),
Expand All @@ -125,7 +126,7 @@ describe('<AsyncBoundary.CSROnly/>', () => {
expect(container.textContent).not.toBe(FALLBACK)
expect(container.textContent).not.toBe(ERROR_MESSAGE)
expect(onError).toHaveBeenCalledTimes(0)
act(() => vi.advanceTimersByTime(MS_100))
act(() => vi.advanceTimersByTime(ms('0.1s')))
await waitFor(() => {
expect(container.textContent).toBe(ERROR_MESSAGE)
expect(container.textContent).not.toBe(TEXT)
Expand Down
11 changes: 6 additions & 5 deletions packages/react/src/Delay.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { MS_100, TEXT } from '@suspensive/test-utils'
import { TEXT } from '@suspensive/test-utils'
import { act, render, screen, waitFor } from '@testing-library/react'
import ms from 'ms'
import { vi } from 'vitest'
import { Delay, withDelay } from '.'

describe('<Delay/>', () => {
it('should render the children after the delay', async () => {
vi.useFakeTimers()
render(<Delay ms={MS_100}>{TEXT}</Delay>)
render(<Delay ms={ms('0.1s')}>{TEXT}</Delay>)
expect(screen.queryByText(TEXT)).not.toBeInTheDocument()
act(() => vi.advanceTimersByTime(MS_100))
act(() => vi.advanceTimersByTime(ms('0.1s')))
await waitFor(() => expect(screen.queryByText(TEXT)).toBeInTheDocument())
})
it('should render the children directly if no ms prop', () => {
Expand All @@ -17,14 +18,14 @@ describe('<Delay/>', () => {
})
})

const TEXTAfterDelay100ms = withDelay(() => <>{TEXT}</>, { ms: MS_100 })
const TEXTAfterDelay100ms = withDelay(() => <>{TEXT}</>, { ms: ms('0.1s') })

describe('withDelay', () => {
it('renders the children after the delay with component', async () => {
vi.useFakeTimers()
render(<TEXTAfterDelay100ms />)
expect(screen.queryByText(TEXT)).not.toBeInTheDocument()
act(() => vi.advanceTimersByTime(MS_100))
act(() => vi.advanceTimersByTime(ms('0.1s')))
await waitFor(() => expect(screen.queryByText(TEXT)).toBeInTheDocument())
})

Expand Down
Loading

0 comments on commit 0c18ccf

Please sign in to comment.