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 60 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
2c451fc
Remove unnecessary `include` and `typecheck` from `vitest.config.mts`
aryaemami59 Feb 8, 2024
06145f6
Rename `test/tsconfig.json` to `tsconfig.test.json`
aryaemami59 Feb 8, 2024
48e7b81
Revamp type tests config
aryaemami59 Feb 8, 2024
89baf66
Update CI to include correct tsconfig
aryaemami59 Feb 8, 2024
409bf82
Fix `testTypes` import
aryaemami59 Feb 8, 2024
5b8faee
Convert `assertType` usages to `.toEqualTypeOf` calls
aryaemami59 Feb 8, 2024
c5f8f03
Simplify type tests in `createStructuredSelector.withTypes.test-d.ts`
aryaemami59 Feb 8, 2024
b781981
Simplify the type tests in `createStructuredSelector.test-d.ts`
aryaemami59 Feb 8, 2024
2fb9b58
Simplify the type tests inside `createSelector.withTypes.test-d.ts`
aryaemami59 Feb 8, 2024
1681375
Add more meaningful assertions to `deepNesting.test-d.ts`
aryaemami59 Feb 8, 2024
233367a
Remove `expectType` and `expectExactType`
aryaemami59 Feb 8, 2024
1feb590
Remove `argsMemoize.typetest.ts` file
aryaemami59 Feb 8, 2024
ebc915a
Replace `expectExactType` calls with `expectTypeOf().toEqualTypeOf()`
aryaemami59 Feb 8, 2024
448ff60
Remove duplicate tests for `typedStructuredSelectorCreator`
aryaemami59 Feb 8, 2024
ee226e6
Convert functions and lone-blocks to `test` blocks
aryaemami59 Feb 8, 2024
0ec452f
Move `test.ts` into `type-tests` folder
aryaemami59 Feb 8, 2024
1fe9770
Remove `typesTestUtils.ts` as it is no longer needed
aryaemami59 Feb 8, 2024
378acb0
Update `test` command in `package.json` to use `yarn bin vitest`
aryaemami59 Feb 8, 2024
6f7011f
Fix `test:typescript` command
aryaemami59 Feb 8, 2024
afd022d
Rename `test:typescript` command to `type-tests`
aryaemami59 Feb 8, 2024
313be9e
Fix imports inside test files
aryaemami59 Feb 8, 2024
65bd936
Fix type issues in `createSelector.withTypes.test-d.ts`
aryaemami59 Feb 8, 2024
047a564
Add `tsconfig.vitest-temp.json` to `.gitignore` file
aryaemami59 Feb 8, 2024
ad9ad27
Move "nested selector" type test to `deepNesting.test-d.ts`
aryaemami59 Feb 9, 2024
17f8b8f
Move `lruMemoize` type tests into its own file
aryaemami59 Feb 9, 2024
afe10bc
Move `createSelectorCreator` type tests into its own file
aryaemami59 Feb 9, 2024
c28daec
Remove duplicate`createStructuredSelector.withTypes()` type tests
aryaemami59 Feb 9, 2024
8c06726
Move `createStructuredSelector` type tests into its own file
aryaemami59 Feb 9, 2024
eb46ed1
Move `createSelector` type tests into its own file
aryaemami59 Feb 9, 2024
09ebd58
Move some more `lruMemoize` type tests into its own file
aryaemami59 Feb 9, 2024
be27163
Move some more `createSelectorCreator` type tests into its own file
aryaemami59 Feb 9, 2024
e994832
Move type tests inside `test.ts` into their respective files
aryaemami59 Feb 9, 2024
05bc1d1
Remove `test.ts`
aryaemami59 Feb 9, 2024
c910805
Make `describe` titles more consistent across type tests
aryaemami59 Feb 9, 2024
2ad733d
De-duplicate `AnyFunction` definitions
aryaemami59 Feb 9, 2024
b67abce
Fix type issues in `scripts/writeGitVersion.mjs`
aryaemami59 Feb 21, 2024
8e0abec
Rename `setup.vitest.ts` to `setup.ts`
aryaemami59 Feb 21, 2024
c67ae78
Change `setupFiles` to `['test/setup.ts']`
aryaemami59 Feb 21, 2024
273f163
Replace references of `typescript_test` to `type-tests`
aryaemami59 Feb 21, 2024
2c06cc3
Remove Node ESM setup from `vitest.config.mts`
aryaemami59 Feb 24, 2024
fd8456c
Provide the correct `tsconfig` file to `tsup`
aryaemami59 Sep 17, 2024
8db970b
Add `yalc` to `.gitignore`
aryaemami59 Apr 29, 2024
dae5530
Run both runtime and type tests against the `dist` folder during CI
aryaemami59 Feb 8, 2024
c44cc25
Remove dead code from `computationComparisons.spec.tsx`
aryaemami59 May 10, 2024
eeb7c58
Remove unnecessary test from `computationComparisons.spec.tsx`
aryaemami59 May 10, 2024
1145ebd
Remove unnecessary `async` keyword
aryaemami59 May 10, 2024
c426272
Fix some issues that were left over from the switch to `weakMapMemoize`
aryaemami59 May 10, 2024
b75daaa
Disable `watch` by default
aryaemami59 May 10, 2024
bc1bee6
Migrate type tests in `lruMemoize.test-d.ts` to Vitest
aryaemami59 May 16, 2024
fcec478
Migrate some assertions in `createSelectorCreator.test-d.ts` to Vitest
aryaemami59 May 16, 2024
58daa41
Migrate some assertions in `createSelector.test-d.ts` to Vitest
aryaemami59 May 16, 2024
6433a6a
Migrate some assertions in `createSelector.test-d.ts` to Vitest
aryaemami59 May 16, 2024
cbf01c4
Migrate the rest of the type tests in `argsMemoize.test-d.ts` to Vitest
aryaemami59 May 31, 2024
d8f569c
Set `pool` to `threads` for performance tests
aryaemami59 Aug 21, 2024
a6a5ad9
Remove `esbuild` from `resolutions` field
aryaemami59 Sep 12, 2024
eefd5f0
Silence `console` output by disabling `identityFunctionCheck`
aryaemami59 Sep 12, 2024
d9a3502
Correct minor spelling issues
aryaemami59 Dec 31, 2024
cb3779d
Bump `vitest` to version 3.1.1
aryaemami59 Aug 21, 2024
be7877c
Migrate remaining type tests to `vitest`
aryaemami59 Feb 28, 2025
5cad3ef
Add `@types/node` to `devDependencies`
aryaemami59 Feb 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .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 Down
86 changes: 63 additions & 23 deletions .github/workflows/build-and-test-types.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: CI

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

jobs:
build:
Expand Down Expand Up @@ -65,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 @@ -110,7 +112,8 @@ jobs:
node-version: ${{ matrix.node }}
cache: 'yarn'

- uses: actions/download-artifact@v4
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: package
path: .
Expand Down Expand Up @@ -152,6 +155,12 @@ 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 .

Expand Down Expand Up @@ -181,17 +190,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 @@ -201,3 +199,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
14 changes: 6 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
"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": "^22.14.0",
"@types/react": "^18.2.38",
"@types/react-dom": "^18.2.17",
"@types/shelljs": "^0.8.11",
Expand All @@ -82,10 +83,7 @@
"shelljs": "^0.8.5",
"tsup": "^8.2.4",
"typescript": "^5.8.2",
"vitest": "^1.6.0"
},
"resolutions": {
"esbuild": "0.23.0"
"vitest": "^3.1.1"
},
"packageManager": "yarn@4.4.1"
}
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 * as fs from 'node:fs'
import * as 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))
Loading