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 #697

Open
wants to merge 103 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
eefc3e7
Bump Vitest
aryaemami59 Feb 8, 2024
2b06586
Bump typescript
aryaemami59 Feb 8, 2024
dd7f959
Update `tsup.config.ts`
aryaemami59 Feb 8, 2024
20fa0ad
Update `vitest.config.mts`
aryaemami59 Feb 8, 2024
bba8240
Rename `test/tsconfig.json` to `tsconfig.test.json`
aryaemami59 Feb 8, 2024
b98b9d4
Revamp type tests config
aryaemami59 Feb 8, 2024
200c901
Update CI to include correct tsconfig
aryaemami59 Feb 8, 2024
3fa6c97
Fix `tsconfig.json`
aryaemami59 Feb 8, 2024
ffbe2a9
Fix `testTypes` import
aryaemami59 Feb 8, 2024
0547da2
Remove Vitest explicit imports
aryaemami59 Feb 8, 2024
0efbf8c
Convert `assertType` calls to `.toEqualTypeOf` calls in `argsMemoize.…
aryaemami59 Feb 8, 2024
88fde7c
Simplify the type tests inside `createStructuredSelector.withTypes.te…
aryaemami59 Feb 8, 2024
dcb9358
Simplify the type tests in `createStructuredSelector.test-d.ts`
aryaemami59 Feb 8, 2024
378759c
Simplify the type tests inside `createSelector.withTypes.test-d.ts`
aryaemami59 Feb 8, 2024
9150d5b
Add more meaningful assertions to `deepNesting.test-d.ts`
aryaemami59 Feb 8, 2024
6649df2
Remove `expectType` and `expectExactType`
aryaemami59 Feb 8, 2024
f85eccb
Remove `argsMemoize.typetest.ts` file
aryaemami59 Feb 8, 2024
58a8183
Replace `expectExactType` calls with `expectTypeOf().toEqualTypeOf()`
aryaemami59 Feb 8, 2024
75c8e1d
Remove duplicate tests for `typedStructuredSelectorCreator`
aryaemami59 Feb 8, 2024
aaff023
Convert functions and lone-blocks to `test` blocks
aryaemami59 Feb 8, 2024
a65ac57
Move `test.ts` into `type-tests` folder
aryaemami59 Feb 8, 2024
e3f4193
Move `typesTestUtils.ts` into `type-tests` folder
aryaemami59 Feb 8, 2024
7bc2feb
Fix `test` command
aryaemami59 Feb 8, 2024
115ad1c
Fix `test:typescript` command
aryaemami59 Feb 8, 2024
40a4e77
Rename `test:typescript` command to `type-tests` to be more consisten…
aryaemami59 Feb 8, 2024
3c76cb5
Fix type tests tsconfig
aryaemami59 Feb 8, 2024
c5811f1
Fix imports inside test files
aryaemami59 Feb 8, 2024
454c380
Skip CI step where source files are deleted
aryaemami59 Feb 8, 2024
5ccf4ce
Fix test command
aryaemami59 Feb 8, 2024
6a4735f
Fix type issues in `createSelector.withTypes.test-d.ts`
aryaemami59 Feb 8, 2024
bbe1532
Add `tsconfig.vitest-temp.json` to `.gitignore` file
aryaemami59 Feb 8, 2024
9877f4f
Exclude benchmarks from type tests
aryaemami59 Feb 8, 2024
6f4fcd8
Fix ESLint issue
aryaemami59 Feb 8, 2024
c700d54
Add `global` declaration for TS 4.8
aryaemami59 Feb 8, 2024
94442c2
Turn off `fileParallelism` to improve performance in unit tests
aryaemami59 Feb 8, 2024
a3dac0d
Exclude `src` folder during type checking
aryaemami59 Feb 8, 2024
c7abb19
Exclude `test` folder during type checking
aryaemami59 Feb 8, 2024
a0d2259
Remove `exclude` from `tsconfig.test.json`
aryaemami59 Feb 9, 2024
0607e28
Remove unnecessary `exclude` from `tsconfig.build.json`
aryaemami59 Feb 9, 2024
7f767ed
Remove unnecessary `exclude` from `tsconfig.json`
aryaemami59 Feb 9, 2024
bef0034
Add `allowJs` to `tsconfig.json`
aryaemami59 Feb 9, 2024
98d1ad4
Remove unnecessary `skipLibCheck` from `tsconfig.test.json`
aryaemami59 Feb 9, 2024
fe2c48d
Remove commented out lines from `build-and-test-types.yml`
aryaemami59 Feb 9, 2024
4248cb7
Move "nested selector" type test from test.ts to `deepNesting.test-d.ts`
aryaemami59 Feb 9, 2024
0683065
Move `lruMemoize` type tests into its own file
aryaemami59 Feb 9, 2024
edd839a
Move `createSelectorCreator` type tests into its own file
aryaemami59 Feb 9, 2024
576d178
Remove duplicate`createStructuredSelector.withTypes()` type tests
aryaemami59 Feb 9, 2024
f0da207
Move `createStructuredSelector` type tests into its own file
aryaemami59 Feb 9, 2024
85c8658
Move `createSelector` type tests into its own file
aryaemami59 Feb 9, 2024
45fda62
Move some more `lruMemoize` type tests into its own file
aryaemami59 Feb 9, 2024
abae24a
Move some more `createSelectorCreator` type tests into its own file
aryaemami59 Feb 9, 2024
18ee065
Move type tests inside `test.ts` into their respective files
aryaemami59 Feb 9, 2024
b424fff
Remove `test.ts`
aryaemami59 Feb 9, 2024
e966597
Fix Build command
aryaemami59 Feb 9, 2024
47f7283
Remove unnecessary `include` from `vitest.config.mts`
aryaemami59 Feb 9, 2024
3eb19ee
Add `noErrorTruncation` to `tsconfig.base.json`
aryaemami59 Feb 9, 2024
9abf178
Remove `baseUrl` from `tsconfig.base.json`
aryaemami59 Feb 9, 2024
dbb29ea
Fix `tsup.config.ts`
aryaemami59 Feb 9, 2024
b048cbc
Make `describe` titles more consistent across type tests
aryaemami59 Feb 9, 2024
3ca30d9
De-duplicate `AnyFunction` definitions
aryaemami59 Feb 9, 2024
ed0cfc9
Merged with master
aryaemami59 Feb 21, 2024
2c114af
Merge branch 'master' of https://github.com/reduxjs/reselect into mig…
aryaemami59 Feb 21, 2024
835d86d
Make tsconfig files match RTK's
aryaemami59 Feb 21, 2024
a7add95
Fix type errors in JS files
aryaemami59 Feb 21, 2024
319052f
Fix problem with `rootDir`
aryaemami59 Feb 21, 2024
2a47b14
Rename `setup.vitest.ts` to `setup.ts`
aryaemami59 Feb 21, 2024
46f7435
Change `setupFiles` to `['test/setup.ts']`
aryaemami59 Feb 21, 2024
4e7dd99
Replace references of `typescript_test` to `type-tests`
aryaemami59 Feb 21, 2024
039b492
Bump Vitest
aryaemami59 Feb 21, 2024
ec80439
Fix type issues regarding fixtures and test contexts
aryaemami59 Feb 21, 2024
e5cd421
sort tsconfig files
aryaemami59 Feb 21, 2024
1c6b1fe
Add `@types/node` to dev dependencies
aryaemami59 Feb 24, 2024
061e0aa
Remove Node ESM setup
aryaemami59 Feb 24, 2024
1e8909a
Change Node version to 20 in CI
aryaemami59 Feb 24, 2024
41f04e4
Merge branch 'master' of https://github.com/reduxjs/reselect into mig…
aryaemami59 Mar 8, 2024
df8650a
Merge branch 'master' of https://github.com/reduxjs/reselect into mig…
aryaemami59 Mar 11, 2024
76ed223
Bump `vitest` to latest version
aryaemami59 Mar 16, 2024
642ce73
Bump TypeScript to 5.4.3
aryaemami59 Mar 26, 2024
a059368
Bump `vitest`
aryaemami59 Apr 17, 2024
ada2a5d
Bump TypeScript
aryaemami59 Apr 17, 2024
8675427
Add `yalc` to `.gitignore`
aryaemami59 Apr 29, 2024
014ea82
Bump `vitest` to version 1.5.2
aryaemami59 Apr 29, 2024
eeb78fc
Bump `vitest` to version 1.5.3
aryaemami59 Apr 30, 2024
e3ce59b
Merge branch 'master' of https://github.com/reduxjs/reselect into mig…
aryaemami59 May 1, 2024
eb79ff3
Bump `vitest` to version 1.6.0
aryaemami59 May 6, 2024
b44c7e5
Run both runtime and type tests against the `dist` folder during CI
aryaemami59 May 7, 2024
b2e50c8
Remove dead code from `computationComparisons.spec.tsx`
aryaemami59 May 10, 2024
a758283
Remove unnecessary test from `computationComparisons.spec.tsx`
aryaemami59 May 10, 2024
62feb04
Remove unnecessary `async` keyword
aryaemami59 May 10, 2024
8fb0975
Fix some issues that were left over from the switch to `weakMapMemoize`
aryaemami59 May 10, 2024
7c15754
Revert "Turn off `fileParallelism` to improve performance in unit tests"
aryaemami59 May 10, 2024
9dc1ecb
Disable `watch` by default
aryaemami59 May 10, 2024
8943a55
Update `test` command in `package.json` to use `yarn bin vitest`
aryaemami59 May 10, 2024
c8c0da6
Migrate type tests in `lruMemoize.test-d.ts` to Vitest
aryaemami59 May 16, 2024
6a93ab8
Migrate some assertions in `createSelectorCreator.test-d.ts` to Vitest
aryaemami59 May 16, 2024
dde1555
Migrate some assertions in `createSelector.test-d.ts` to Vitest
aryaemami59 May 16, 2024
e644b54
Migrate some assertions in `createSelector.test-d.ts` to Vitest
aryaemami59 May 16, 2024
7e224bd
Migrate the rest of the type tests in `argsMemoize.test-d.ts` to Vitest
aryaemami59 May 31, 2024
e92072a
Fix some type issues in `tsup.config.ts`
aryaemami59 Jun 1, 2024
455cd2b
Merge branch 'master' of https://github.com/reduxjs/reselect into mig…
aryaemami59 Jun 1, 2024
876dc69
Merge branch 'master' of https://github.com/reduxjs/reselect into mig…
aryaemami59 Jun 19, 2024
c3194c6
De-duplicate dependencies
aryaemami59 Jun 19, 2024
f5ffebb
Fix CI
aryaemami59 Jun 21, 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
8 changes: 6 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
}
},
{
"files": ["**/test/**/*.ts", "**/typescript_test/**/*.ts"],
"files": ["**/test/**/*.ts", "**/type-test/**/*.ts"],
"rules": {
"consistent-return": "off",
"max-lines": "off",
Expand All @@ -70,7 +70,11 @@
"@typescript-eslint/no-floating-promises": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-shadow": "off"
"@typescript-eslint/no-shadow": "off",
"@typescript-eslint/no-namespace": [
2,
{ "allowDeclarations": true, "allowDefinitionFiles": true }
]
}
},
{
Expand Down
108 changes: 66 additions & 42 deletions .github/workflows/build-and-test-types.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
name: CI

on:
push:
branches: [master]
pull_request:
branches: [master]
on: [push, pull_request, workflow_dispatch]

jobs:
build:
Expand Down Expand Up @@ -69,31 +65,33 @@ jobs:
node-version: ${{ matrix.node }}
cache: 'yarn'

- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: package
path: .

- name: Install deps
run: yarn install

# Build with the actual TS version in the repo
- name: Pack
run: yarn build && yarn pack

- name: Install build artifact
run: yarn add ./package.tgz

# Then install the specific version to test against
- name: Install TypeScript ${{ matrix.ts }}
run: yarn add --dev typescript@${{ matrix.ts }}

- name: 'Remove source to ensure packaged types are used'
run: rm -rf src

# Remove config line that points "reselect" to the `src` folder,
# so that the typetest will use the installed version instead
- run: sed -i -e /@remap-prod-remove-line/d ./typescript_test/tsconfig.json vitest.config.mts
- name: Erase path aliases
run: sed -i -e /@remap-prod-remove-line/d tsconfig.base.json

- name: Test types
env:
TEST_DIST: true
run: |
./node_modules/.bin/tsc --version
yarn test:typescript
yarn tsc --version
yarn type-tests

are-the-types-wrong:
name: Check package config with are-the-types-wrong
Expand All @@ -108,7 +106,8 @@ jobs:
- name: Checkout repo
uses: actions/checkout@v4

- uses: actions/download-artifact@v4
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: package
path: .
Expand Down Expand Up @@ -150,29 +149,23 @@ jobs:
- name: Clone RTK repo
run: git clone https://github.com/reduxjs/redux-toolkit.git ./redux-toolkit

- name: Cache example deps
uses: actions/cache@v4
with:
path: ./redux-toolkit/examples/publish-ci/${{ matrix.example }}/node_modules
key: test-published-artifact-${{ matrix.example }}-node_modules

- name: Check folder contents
run: ls -l .

# Some weird install diffs with cloning this repo and installing.
# Just kill the lockfiles for this repo and RTK and reinstall

- name: Remove top lockfile
run: rm yarn.lock && rm package.json

- name: Remove RTK lockfile
working-directory: ./redux-toolkit
run: rm yarn.lock && rm package.json

- name: Install deps
- name: Install example deps
working-directory: ./redux-toolkit/examples/publish-ci/${{ matrix.example }}
env:
YARN_ENABLE_IMMUTABLE_INSTALLS: false
run: rm yarn.lock && yarn install
run: yarn install

- name: Install Playwright browser if necessary
working-directory: ./redux-toolkit/examples/publish-ci/${{ matrix.example }}
continue-on-error: true
run: yarn playwright install
run: yarn playwright install || true

- uses: actions/download-artifact@v4
with:
Expand All @@ -191,17 +184,6 @@ jobs:
working-directory: ./redux-toolkit/examples/publish-ci/${{ matrix.example }}
run: yarn info reselect && yarn why reselect

- name: Set up JDK 17 for React Native build
if: matrix.example == 'react-native'
uses: actions/setup-java@v4
with:
java-version: '17.x'
distribution: 'temurin'

- name: Check MSW version
working-directory: ./redux-toolkit/examples/publish-ci/${{ matrix.example }}
run: yarn why msw

- name: Build example
working-directory: ./redux-toolkit/examples/publish-ci/${{ matrix.example }}
env:
Expand All @@ -211,3 +193,45 @@ jobs:
- name: Run test step
working-directory: ./redux-toolkit/examples/publish-ci/${{ matrix.example }}
run: yarn test

test-dist:
name: Run local tests against build artifact
needs: [build]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node: ['20.x']

steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Use node ${{ matrix.node }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
cache: 'yarn'

- name: Install dependencies
run: yarn install

- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: package
path: .

- name: Check folder contents
run: ls -lah

- name: Install build artifact
run: yarn add ./package.tgz

- name: Erase path aliases
run: sed -i -e /@remap-prod-remove-line/d tsconfig.base.json

- name: Run local tests against the build artifact
env:
TEST_DIST: true
run: yarn test
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ dist
es
.vscode
.idea
typescript_test/should_compile/index.js
typescript_test/should_not_compile/index.js
typescript_test/common.js
flow_test/should_fail/flow-typed/index.js.flow
flow_test/should_pass/flow-typed/index.js.flow
reselect-builds/
Expand All @@ -34,3 +31,8 @@ website/.yarn/

docs/examples/**/*.js
docs/examples/**/*.jsx

tsconfig.vitest-temp.json

.yalc
yalc.lock
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@
"url": "https://github.com/reduxjs/reselect/issues"
},
"scripts": {
"build": "tsup",
"build": "yarn clean && tsup",
"clean": "rimraf dist",
"format": "prettier --write \"{src,test}/**/*.{js,ts}\" \"docs/**/*.md\"",
"lint": "eslint src test",
"prepack": "yarn build",
"bench": "vitest --run bench --mode production",
"test": "node --expose-gc ./node_modules/vitest/dist/cli-wrapper.js --run && vitest --run --typecheck.only",
"test:watch": "node --expose-gc ./node_modules/vitest/dist/cli-wrapper.js --watch",
"test": "node --expose-gc $(yarn bin vitest) --run --typecheck",
"test:watch": "node --expose-gc $(yarn bin vitest) --watch",
"test:cov": "vitest run --coverage",
"type-check": "vitest --run --typecheck.only",
"type-check:trace": "vitest --run --typecheck.only && tsc --noEmit -p typescript_test/tsconfig.json --generateTrace trace && npx @typescript/analyze-trace trace && rimraf trace",
"test:typescript": "tsc --noEmit -p typescript_test/tsconfig.json",
"type-check:trace": "vitest --run --typecheck.only && tsc --noEmit -p tsconfig.test.json --generateTrace trace && npx @typescript/analyze-trace trace && rimraf trace",
"type-tests": "tsc --noEmit -p tsconfig.test.json",
"docs:start": "yarn --cwd website start",
"docs:build": "yarn --cwd website build",
"docs:clear": "yarn --cwd website clear",
Expand All @@ -58,6 +58,7 @@
"@reduxjs/toolkit": "^2.0.1",
"@testing-library/react": "^14.1.2",
"@types/lodash": "^4.14.175",
"@types/node": "^20.11.20",
"@types/react": "^18.2.38",
"@types/react-dom": "^18.2.17",
"@types/shelljs": "^0.8.11",
Expand All @@ -81,7 +82,7 @@
"rimraf": "^3.0.2",
"shelljs": "^0.8.5",
"tsup": "^6.7.0",
"typescript": "^5.4.2",
"typescript": "^5.4.5",
"vitest": "^1.6.0"
},
"packageManager": "[email protected]"
Expand Down
12 changes: 4 additions & 8 deletions scripts/writeGitVersion.mjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import path from 'path'
import fs from 'fs'
import { fileURLToPath } from 'node:url'

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
import fs from 'node:fs'
import path from 'node:path'

const gitRev = process.argv[2]

const packagePath = path.join(__dirname, '../package.json')
const pkg = JSON.parse(fs.readFileSync(packagePath))
const packagePath = path.join(import.meta.dirname, '../package.json')
const pkg = JSON.parse(fs.readFileSync(packagePath, 'utf-8'))

pkg.version = `${pkg.version}-${gitRev}`
fs.writeFileSync(packagePath, JSON.stringify(pkg, null, 2))