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

0 commit comments

Comments
 (0)