Skip to content

Commit a128c5e

Browse files
authored
Merge pull request #2129 from aryaemami59/migrate-typetests-to-vitest
2 parents 1af75b3 + 04a8c0b commit a128c5e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2209
-2159
lines changed

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"eslint:recommended",
3434
"plugin:import/recommended",
3535
"plugin:react/recommended",
36+
"plugin:react/jsx-runtime",
3637
"plugin:@typescript-eslint/recommended"
3738
],
3839
"rules": {
@@ -56,7 +57,7 @@
5657
},
5758
{
5859
"files": ["**/test/**/*.{ts,tsx}"],
59-
"parserOptions": { "project": "./test/tsconfig.test.json" }
60+
"parserOptions": { "project": true }
6061
}
6162
]
6263
}

.github/workflows/test.yml

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
name: Tests
22

3-
on:
4-
push:
5-
branches: [master]
6-
pull_request:
7-
branches: [master]
8-
workflow_dispatch:
3+
on: [push, pull_request, workflow_dispatch]
94

105
jobs:
116
build:
12-
name: Test Suite
7+
name: Build and run test Suite
138
runs-on: ubuntu-latest
149

1510
steps:
@@ -63,12 +58,24 @@ jobs:
6358
node-version: ${{ matrix.node }}
6459
cache: 'yarn'
6560

61+
- name: Download build artifact
62+
uses: actions/download-artifact@v4
63+
with:
64+
name: package
65+
path: .
66+
6667
- name: Install deps
6768
run: yarn install
6869

6970
- name: Install TypeScript ${{ matrix.ts }}
7071
run: yarn add typescript@${{ matrix.ts }}
7172

73+
- name: Install build artifact
74+
run: yarn add ./package.tgz
75+
76+
- name: Erase path aliases
77+
run: sed -i -e /@remap-prod-remove-line/d ./tsconfig.base.json ./vitest.config.mts
78+
7279
- name: Test types
7380
run: |
7481
yarn tsc --version
@@ -219,3 +226,42 @@ jobs:
219226

220227
- name: Build example
221228
run: yarn build
229+
230+
test-dist:
231+
name: Run local tests against build artifact
232+
needs: [build]
233+
runs-on: ubuntu-latest
234+
strategy:
235+
fail-fast: false
236+
matrix:
237+
node: ['20.x']
238+
steps:
239+
- name: Checkout repo
240+
uses: actions/checkout@v4
241+
242+
- name: Use node ${{ matrix.node }}
243+
uses: actions/setup-node@v4
244+
with:
245+
node-version: ${{ matrix.node }}
246+
cache: 'yarn'
247+
248+
- name: Install deps
249+
run: yarn install
250+
251+
- name: Download build artifact
252+
uses: actions/download-artifact@v4
253+
with:
254+
name: package
255+
path: .
256+
257+
- name: Check folder contents
258+
run: ls -lah
259+
260+
- name: Install build artifact
261+
run: yarn add ./package.tgz
262+
263+
- name: Erase path aliases
264+
run: sed -i -e /@remap-prod-remove-line/d ./tsconfig.base.json ./vitest.config.mts
265+
266+
- name: Run local tests against the build artifact
267+
run: yarn test

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,6 @@ website/translated_docs
3232
website/build/
3333
website/node_modules
3434
website/i18n/*
35+
36+
tsconfig.vitest-temp.json
37+

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,17 @@
3636
"dist"
3737
],
3838
"scripts": {
39-
"build": "tsup",
39+
"build": "yarn clean && tsup",
4040
"clean": "rimraf lib dist es coverage",
4141
"api-types": "api-extractor run --local",
4242
"format": "prettier --write \"{src,test}/**/*.{js,ts,tsx}\" \"docs/**/*.md\"",
4343
"lint": "eslint src test",
4444
"lint:fix": "eslint src test --fix",
4545
"prepare": "yarn clean && yarn build",
4646
"pretest": "yarn lint",
47-
"test": "vitest --run",
47+
"test": "vitest --run --typecheck",
4848
"test:watch": "vitest --watch",
49-
"type-tests": "yarn tsc -p test/typetests/tsconfig.json",
49+
"type-tests": "tsc --noEmit -p tsconfig.test.json",
5050
"coverage": "codecov"
5151
},
5252
"peerDependencies": {
@@ -104,8 +104,8 @@
104104
"redux": "^5.0.0",
105105
"rimraf": "^3.0.2",
106106
"tsup": "^7.0.0",
107-
"typescript": "^5.4.2",
108-
"vitest": "^1.2.1"
107+
"typescript": "^5.4.5",
108+
"vitest": "^1.6.0"
109109
},
110110
"packageManager": "[email protected]"
111111
}

src/components/Provider.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ function Provider<A extends Action<string> = UnknownAction, S = unknown>({
9191

9292
const Context = context || ReactReduxContext
9393

94-
// @ts-ignore 'AnyAction' is assignable to the constraint of type 'A', but 'A' could be instantiated with a different subtype
9594
return <Context.Provider value={contextValue}>{children}</Context.Provider>
9695
}
9796

src/components/connect.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,6 @@ function connect<
519519
WrappedComponent,
520520
// @ts-ignore
521521
initMapStateToProps,
522-
// @ts-ignore
523522
initMapDispatchToProps,
524523
initMergeProps,
525524
areStatesEqual,

src/hooks/useSelector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export function createSelectorHook(
142142
? useDefaultReduxContext
143143
: createReduxContextHook(context)
144144

145-
const useSelector = <TState, Selected extends unknown>(
145+
const useSelector = <TState, Selected>(
146146
selector: (state: TState) => Selected,
147147
equalityFnOrOptions:
148148
| EqualityFn<NoInfer<Selected>>

src/index-rsc.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,25 @@ const _check2: typeof rsc = {} as typeof normal
1010

1111
// -------------------------------------------------------------------------------------
1212

13-
function throwNotSupportedError(
13+
const throwNotSupportedError = ((
1414
// eslint-disable-next-line @typescript-eslint/no-unused-vars
1515
...args: any[]
16-
): any {
16+
): any => {
1717
throw new Error(
1818
'This function is not supported in React Server Components. Please only use this export in a Client Component.',
1919
)
20-
}
20+
}) as any
2121

2222
export {
23-
throwNotSupportedError as batch,
2423
throwNotSupportedError as Provider,
24+
throwNotSupportedError as batch,
2525
throwNotSupportedError as connect,
26-
throwNotSupportedError as useSelector,
27-
throwNotSupportedError as useDispatch,
28-
throwNotSupportedError as useStore,
2926
throwNotSupportedError as createDispatchHook,
3027
throwNotSupportedError as createSelectorHook,
3128
throwNotSupportedError as createStoreHook,
29+
throwNotSupportedError as useDispatch,
30+
throwNotSupportedError as useSelector,
31+
throwNotSupportedError as useStore,
3232
}
3333
export const ReactReduxContext = {} as any
3434
export { default as shallowEqual } from './utils/shallowEqual'

src/utils/react.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import * as ReactOriginal from 'react'
21
import type * as ReactNamespace from 'react'
2+
import * as ReactOriginal from 'react'
33

44
export const React: typeof ReactNamespace =
55
// prettier-ignore
6-
// @ts-ignore
76
'default' in ReactOriginal ? ReactOriginal['default'] : ReactOriginal as any

test/components/Provider.spec.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import * as rtl from '@testing-library/react'
44
import type { Dispatch, JSX } from 'react'
55
import React, { Component } from 'react'
6+
import type { ReactReduxContextValue } from 'react-redux'
7+
import { Provider, ReactReduxContext, connect } from 'react-redux'
68
import type { Store } from 'redux'
79
import { createStore } from 'redux'
8-
import type { ReactReduxContextValue } from '../../src'
9-
import { Provider, ReactReduxContext, connect } from '../../src/index'
1010

1111
import * as ReactDOM from 'react-dom'
1212

test/components/connect.spec.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
/*eslint-disable react/prop-types*/
22

33
import * as rtl from '@testing-library/react'
4-
import type { Dispatch, ElementType, MouseEvent, ReactNode, JSX } from 'react'
4+
import type { Dispatch, ElementType, JSX, MouseEvent, ReactNode } from 'react'
55
import React, { Component } from 'react'
6+
import type { ReactReduxContextValue } from 'react-redux'
7+
import { Provider as ProviderMock, connect } from 'react-redux'
68
import type {
79
Action,
810
AnyAction,
@@ -12,8 +14,6 @@ import type {
1214
UnknownAction,
1315
} from 'redux'
1416
import { applyMiddleware, createStore } from 'redux'
15-
import type { ReactReduxContextValue } from '../../src/index'
16-
import { Provider as ProviderMock, connect } from '../../src/index'
1717

1818
const IS_REACT_18 = React.version.startsWith('18')
1919

test/components/hooks.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
import * as rtl from '@testing-library/react'
44
import React from 'react'
5+
import { Provider as ProviderMock, connect } from 'react-redux'
56
import type { AnyAction } from 'redux'
67
import { createStore } from 'redux'
7-
import { Provider as ProviderMock, connect } from '../../src/index'
88

99
const IS_REACT_18 = React.version.startsWith('18')
1010

test/hooks/hooks.withTypes.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Action, ThunkAction } from '@reduxjs/toolkit'
22
import { configureStore, createAsyncThunk, createSlice } from '@reduxjs/toolkit'
3-
import { useDispatch, useSelector, useStore } from '../../src'
3+
import { useDispatch, useSelector, useStore } from 'react-redux'
44

55
export interface CounterState {
66
counter: number

test/hooks/useDispatch.spec.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import React from 'react'
2-
import { createStore } from 'redux'
31
import { renderHook } from '@testing-library/react-hooks'
2+
import React from 'react'
3+
import type { ProviderProps, ReactReduxContextValue } from 'react-redux'
44
import {
5+
createDispatchHook,
56
Provider as ProviderMock,
67
useDispatch,
7-
createDispatchHook,
8-
} from '../../src/index'
9-
import type { ProviderProps, ReactReduxContextValue } from '../../src/'
8+
} from 'react-redux'
9+
import { createStore } from 'redux'
1010

1111
const store = createStore((c: number = 1): number => c + 1)
1212
const store2 = createStore((c: number = 1): number => c + 2)

test/hooks/useReduxContext.spec.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { renderHook } from '@testing-library/react-hooks'
2-
import { createContext } from 'react'
3-
import type { ReactReduxContextValue } from '../../src/components/Context'
41
import {
52
createReduxContextHook,
63
useReduxContext,
7-
} from '../../src/hooks/useReduxContext'
4+
} from '@internal/hooks/useReduxContext'
5+
import { renderHook } from '@testing-library/react-hooks'
6+
import { createContext } from 'react'
7+
import type { ReactReduxContextValue } from 'react-redux'
88

99
describe('React', () => {
1010
describe('hooks', () => {
@@ -14,7 +14,7 @@ describe('React', () => {
1414

1515
const { result } = renderHook(() => useReduxContext())
1616

17-
expect(result.error.message).toMatch(
17+
expect(result.error?.message).toMatch(
1818
/could not find react-redux context value/,
1919
)
2020

@@ -29,7 +29,7 @@ describe('React', () => {
2929

3030
const { result } = renderHook(() => useCustomReduxContext())
3131

32-
expect(result.error.message).toMatch(
32+
expect(result.error?.message).toMatch(
3333
/could not find react-redux context value/,
3434
)
3535

test/hooks/useSelector.spec.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*eslint-disable react/prop-types*/
22

3+
import type { UseSelectorOptions } from '@internal/hooks/useSelector'
34
import * as rtl from '@testing-library/react'
45
import type { DispatchWithoutAction, FunctionComponent, ReactNode } from 'react'
56
import React, {
@@ -11,15 +12,12 @@ import React, {
1112
useReducer,
1213
useState,
1314
} from 'react'
14-
import type { Action, AnyAction, Store } from 'redux'
15-
import { createStore } from 'redux'
16-
import type { UseSelectorOptions } from '../../src/hooks/useSelector'
1715
import type {
1816
ProviderProps,
1917
ReactReduxContextValue,
2018
Subscription,
2119
TypedUseSelectorHook,
22-
} from '../../src/index'
20+
} from 'react-redux'
2321
import {
2422
Provider,
2523
ReactReduxContext,
@@ -28,7 +26,9 @@ import {
2826
shallowEqual,
2927
useDispatch,
3028
useSelector,
31-
} from '../../src/index'
29+
} from 'react-redux'
30+
import type { Action, AnyAction, Store } from 'redux'
31+
import { createStore } from 'redux'
3232

3333
// disable checks by default
3434
function ProviderMock<A extends Action<any> = AnyAction, S = unknown>({

test/integration/dynamic-reducers.spec.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import * as rtl from '@testing-library/react'
44
import type { ReactNode } from 'react'
55
import React from 'react'
66
import ReactDOMServer from 'react-dom/server'
7+
import type { ReactReduxContextValue } from 'react-redux'
8+
import { Provider, ReactReduxContext, connect } from 'react-redux'
79
import type { Store } from 'redux'
810
import { combineReducers, createStore } from 'redux'
9-
import type { ReactReduxContextValue } from '../../src/index'
10-
import { Provider, ReactReduxContext, connect } from '../../src/index'
1111

1212
describe('React', () => {
1313
/*
@@ -180,10 +180,7 @@ describe('React', () => {
180180
// This generates errors for using useLayoutEffect in v7
181181
// We hide that error by disabling console.error here
182182

183-
vi.spyOn(console, 'error')
184-
// eslint-disable-next-line no-console
185-
// @ts-ignore
186-
console.error.mockImplementation(() => {})
183+
const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {})
187184

188185
const markup = ReactDOMServer.renderToString(
189186
<Provider store={store}>
@@ -199,9 +196,7 @@ describe('React', () => {
199196
expect(markup).toContain('Hello world')
200197
expect(markup).toContain('Hello dynamic world')
201198

202-
// eslint-disable-next-line no-console
203-
// @ts-ignore
204-
console.error.mockRestore()
199+
consoleErrorSpy.mockRestore()
205200
})
206201
})
207202
})

test/integration/server-rendering.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import type { PayloadAction } from '@reduxjs/toolkit'
1212
import type { FunctionComponent } from 'react'
1313
import React from 'react'
1414
import { renderToString } from 'react-dom/server'
15+
import { Provider, connect } from 'react-redux'
1516
import type { Dispatch, Store } from 'redux'
1617
import { createStore } from 'redux'
17-
import { Provider, connect } from '../../src/index'
1818

1919
describe('React', () => {
2020
describe('server rendering', () => {

0 commit comments

Comments
 (0)