Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate type tests to Vitest #2129

Merged
merged 74 commits into from May 9, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
50c72d5
Rename `connect-mapstate-mapdispatch.tsx` to `connect-mapstate-mapdis…
aryaemami59 Jan 29, 2024
beaaca5
Rename `connect-options-and-issues.tsx` to `connect-options-and-issue…
aryaemami59 Jan 29, 2024
3630e05
Rename `hooks.tsx` to `hooks.test-d.tsx`
aryaemami59 Jan 29, 2024
5e76256
Rename `provider.tsx` to `provider.test-d.tsx`
aryaemami59 Jan 29, 2024
0b2c461
Rename `react-redux-types.typetest.tsx` to `react-redux-types.test-d.…
aryaemami59 Jan 29, 2024
fc46a79
MIgrate type tests for `connect-options-and-issues.test-d.tsx` to Vitest
aryaemami59 Jan 29, 2024
8fe27c3
Fix minor issues in some test files
aryaemami59 Jan 29, 2024
e2777b7
Extend from the root `tsconfig.json`
aryaemami59 Jan 29, 2024
2c79718
Fix `exclude` in `tsconfig.test.json`
aryaemami59 Jan 29, 2024
2957c5f
Convert functions to `test` blocks in `connect-mapstate-mapdispatch.t…
aryaemami59 Jan 29, 2024
1fc684b
MIgrate type tests for `react-redux-types.test-d.tsx` to Vitest
aryaemami59 Feb 8, 2024
8e4e87d
MIgrate type tests for `hooks.test-d.tsx` to Vitest
aryaemami59 Feb 8, 2024
81c536e
Add `plugin:react/jsx-runtime` to ESLint extends
aryaemami59 Feb 8, 2024
4bf1c8e
Add `"jsx": "react-jsx"` to `tsconfig.test.json`
aryaemami59 Feb 8, 2024
31e1002
MIgrate type tests for `hooks.withTypes.test-d.tsx` to Vitest
aryaemami59 Feb 8, 2024
e813464
MIgrate type tests for `provider.test-d.tsx` to Vitest
aryaemami59 Feb 8, 2024
32a83c7
Fix some of type tests in `react-redux-types.test-d.tsx`
aryaemami59 Feb 8, 2024
a74b7b4
Remove `expectType` and `expectExactType`
aryaemami59 Feb 8, 2024
185903c
Bump typescript and vitest
aryaemami59 Feb 8, 2024
656d657
Remove wrong alias from `vitest.config.mts`
aryaemami59 Feb 8, 2024
0e138ca
Fix `CustomContext` in `connect-mapstate-mapdispatch.test-d.tsx`
aryaemami59 Feb 8, 2024
7db40df
Fix `React` imports in `connect-mapstate-mapdispatch.test-d.tsx`
aryaemami59 Feb 8, 2024
9b6df99
Fix `CustomContext` in `connect-options-and-issues.test-d.tsx`
aryaemami59 Feb 8, 2024
f379646
Merge branch 'master' of https://github.com/reduxjs/react-redux into …
aryaemami59 Feb 8, 2024
bcc5864
Merge branch 'master' of https://github.com/reduxjs/react-redux into …
aryaemami59 Feb 9, 2024
dd89f15
Fix `tsup.config.ts`
aryaemami59 Feb 9, 2024
e2484ef
Move `tsconfig.test.json` from the `test` folder to the root folder
aryaemami59 Feb 9, 2024
70481af
Revamp type tests config
aryaemami59 Feb 9, 2024
3b199ba
Fix `type-tests` command
aryaemami59 Feb 9, 2024
d887a9c
Provide the correct `tsconfig` to tsup
aryaemami59 Feb 9, 2024
656f731
Insert `any` assertion to silence TS errors
aryaemami59 Feb 9, 2024
325c8fd
Fix `tsconfig.test.json`
aryaemami59 Feb 9, 2024
68aa808
Fix ESLint issue
aryaemami59 Feb 9, 2024
8ead8e2
Remove `expectType`
aryaemami59 Feb 9, 2024
69d35c3
Fix titles of type tests
aryaemami59 Feb 9, 2024
3dbf659
Fix tsconfigs to match RTK's
aryaemami59 Feb 21, 2024
e7c4005
Add `tsconfig.vitest-temp.json` to `.gitignore` file
aryaemami59 Feb 21, 2024
f1bba5e
Remove `typecheck` field from `vitest.config.mts`
aryaemami59 Feb 21, 2024
8f52019
Run type checker alongside runtime tests
aryaemami59 Feb 21, 2024
e1a335d
Move test setup file into `test` folder
aryaemami59 Feb 21, 2024
bdeb473
Bump Vitest
aryaemami59 Feb 24, 2024
e62f478
Add path aliases and test against dist
aryaemami59 Feb 24, 2024
8e6add0
Trigger CI
aryaemami59 Feb 24, 2024
35dd78e
Remove Node ESM setup from `vitest.config.mts`
aryaemami59 Feb 24, 2024
047a071
Remove Node ESM setup from `tsup.config.ts`
aryaemami59 Feb 24, 2024
d337a31
Change CI Node version to 20
aryaemami59 Feb 24, 2024
ab44f2b
Change CI Node version to 20
aryaemami59 Feb 24, 2024
86448eb
Remove `import.meta.dirname` from `tsup.config.ts`
aryaemami59 Feb 24, 2024
1f8dcd7
Merge branch 'master' of https://github.com/reduxjs/react-redux into …
aryaemami59 Mar 8, 2024
d1380fa
Merge branch 'master' of https://github.com/reduxjs/react-redux into …
aryaemami59 Mar 10, 2024
42a6202
Fix lockfile
aryaemami59 Mar 10, 2024
6e4d4fd
Update GitHub Actions versions
aryaemami59 Mar 10, 2024
584ee8a
Merge branch 'master' of https://github.com/reduxjs/react-redux into …
aryaemami59 Mar 11, 2024
327d7cc
Bump `vitest` to latest version
aryaemami59 Mar 16, 2024
890aa40
Merge branch 'master' of https://github.com/reduxjs/react-redux into …
aryaemami59 Mar 21, 2024
d35255c
Merge branch 'master' of https://github.com/reduxjs/react-redux into …
aryaemami59 Mar 21, 2024
d69e108
Merge branch 'master' of https://github.com/reduxjs/react-redux into …
aryaemami59 Apr 7, 2024
8c073e2
Merge branch 'master' of https://github.com/reduxjs/react-redux into …
aryaemami59 Apr 9, 2024
ac8af6e
Merge branch 'master' of https://github.com/reduxjs/react-redux into …
aryaemami59 Apr 15, 2024
ae2e174
Merge branch 'master' of https://github.com/reduxjs/react-redux into …
aryaemami59 Apr 30, 2024
8a111a9
Merge branch 'master' of https://github.com/reduxjs/react-redux into …
aryaemami59 May 1, 2024
8f0824a
Merge branch 'migrate-typetests-to-vitest' of https://github.com/arya…
aryaemami59 May 2, 2024
3a453ac
Merge branch 'master' of https://github.com/reduxjs/react-redux into …
aryaemami59 May 2, 2024
6092181
Bump `vitest` to version 1.5.3
aryaemami59 May 2, 2024
6daba94
Merge branch 'master' of https://github.com/reduxjs/react-redux into …
aryaemami59 May 2, 2024
4d30e85
Bump TypeScript version to 5.4.5
aryaemami59 May 2, 2024
3fe18e7
Copy changes from #2168
aryaemami59 May 3, 2024
11e7a50
Bump `vitest` to version 1.6.0
aryaemami59 May 6, 2024
1e6a99e
Fix type issues in `tsup.config.ts`
aryaemami59 May 7, 2024
106f8fc
Remove `dist` folder before `build` command
aryaemami59 May 7, 2024
1836455
Run both runtime and type tests against the `dist` folder during CI
aryaemami59 May 7, 2024
1269bf4
Format files
aryaemami59 May 7, 2024
cf676e8
Distinguish between external and internal imports in tests
aryaemami59 May 7, 2024
04a8c0b
Remove some `// @ts-ignore` directives
aryaemami59 May 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.json
Expand Up @@ -33,6 +33,7 @@
"eslint:recommended",
"plugin:import/recommended",
"plugin:react/recommended",
"plugin:react/jsx-runtime",
"plugin:@typescript-eslint/recommended"
],
"rules": {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -107,7 +107,7 @@
"redux": "^5.0.0",
"rimraf": "^3.0.2",
"tsup": "^7.0.0",
"typescript": "^5.0",
"vitest": "^1.2.1"
"typescript": "^5.3.3",
"vitest": "^1.2.2"
}
}
2 changes: 1 addition & 1 deletion src/hooks/useSelector.ts
Expand Up @@ -142,7 +142,7 @@ export function createSelectorHook(
? useDefaultReduxContext
: createReduxContextHook(context)

const useSelector = <TState, Selected extends unknown>(
const useSelector = <TState, Selected>(
selector: (state: TState) => Selected,
equalityFnOrOptions:
| EqualityFn<NoInfer<Selected>>
Expand Down
2 changes: 1 addition & 1 deletion test/components/Provider.spec.tsx
Expand Up @@ -169,7 +169,7 @@ describe('React', () => {
action.type === 'INC' ? state + 1 : state

const innerStore = createStore(reducer)
const innerMapStateToProps = vi.fn<TStateProps, [number]>((state) => ({
const innerMapStateToProps = vi.fn<[number], TStateProps>((state) => ({
count: state,
}))
class Inner extends Component<TStateProps> {
Expand Down
4 changes: 2 additions & 2 deletions test/hooks/useReduxContext.spec.tsx
Expand Up @@ -14,7 +14,7 @@ describe('React', () => {

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

expect(result.error.message).toMatch(
expect(result.error?.message).toMatch(
/could not find react-redux context value/,
)

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

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

expect(result.error.message).toMatch(
expect(result.error?.message).toMatch(
/could not find react-redux context value/,
)

Expand Down
8 changes: 5 additions & 3 deletions test/tsconfig.test.json
@@ -1,4 +1,5 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
Expand All @@ -9,10 +10,11 @@
"strict": true,
"noEmit": true,
"target": "es2018",
"jsx": "react",
"jsx": "react-jsx",
"baseUrl": ".",
"skipLibCheck": true,
"noImplicitReturns": false,
"experimentalDecorators": true,
}
"experimentalDecorators": true
},
"exclude": []
}
49 changes: 0 additions & 49 deletions test/typeTestHelpers.ts
Expand Up @@ -22,12 +22,6 @@ export function expectType<T>(t: T): T {
return t
}

type Equals<T, U> = IsAny<
T,
never,
IsAny<U, never, [T] extends [U] ? ([U] extends [T] ? any : never) : never>
>

export type IsEqual<A, B> = (<G>() => G extends A ? 1 : 2) extends <
G,
>() => G extends B ? 1 : 2
Expand All @@ -40,46 +34,3 @@ export type IfEquals<
TypeIfEquals = unknown,
TypeIfNotEquals = never,
> = IsEqual<T, U> extends true ? TypeIfEquals : TypeIfNotEquals

export declare const exactType: <T, U>(
draft: T & IfEquals<T, U>,
expected: U & IfEquals<T, U>,
) => IfEquals<T, U>

export function expectExactType<T>(t: T) {
return <U extends T>(u: U & Equals<T, U>) => {}
}

type EnsureUnknown<T> = IsUnknown<T, any, never>
export function expectUnknown<T extends EnsureUnknown<T>>(t: T) {
return t
}

type EnsureAny<T> = IsAny<T, any, never>
export function expectExactAny<T extends EnsureAny<T>>(t: T) {
return t
}

type IsNotAny<T> = IsAny<T, never, any>
export function expectNotAny<T extends IsNotAny<T>>(t: T): T {
return t
}

expectType<string>('5' as string)
expectType<string>('5' as const)
expectType<string>('5' as any)
expectExactType('5' as const)('5' as const)
// @ts-expect-error
expectExactType('5' as string)('5' as const)
// @ts-expect-error
expectExactType('5' as any)('5' as const)
expectUnknown('5' as unknown)
// @ts-expect-error
expectUnknown('5' as const)
// @ts-expect-error
expectUnknown('5' as any)
expectExactAny('5' as any)
// @ts-expect-error
expectExactAny('5' as const)
// @ts-expect-error
expectExactAny('5' as unknown)