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 58 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
41f8645
Remove unnecessary `include` and `typecheck` from `vitest.config.mts`
aryaemami59 Feb 8, 2024
3da8b97
Rename `test/tsconfig.json` to `tsconfig.test.json`
aryaemami59 Feb 8, 2024
a3b5c6e
Revamp type tests config
aryaemami59 Feb 8, 2024
e718860
Update CI to include correct tsconfig
aryaemami59 Feb 8, 2024
2367961
Fix `testTypes` import
aryaemami59 Feb 8, 2024
5d8151c
Convert `assertType` usages to `.toEqualTypeOf` calls
aryaemami59 Feb 8, 2024
418dceb
Simplify type tests in `createStructuredSelector.withTypes.test-d.ts`
aryaemami59 Feb 8, 2024
8504022
Simplify the type tests in `createStructuredSelector.test-d.ts`
aryaemami59 Feb 8, 2024
a9e1bef
Simplify the type tests inside `createSelector.withTypes.test-d.ts`
aryaemami59 Feb 8, 2024
16dd2ed
Add more meaningful assertions to `deepNesting.test-d.ts`
aryaemami59 Feb 8, 2024
23e991d
Remove `expectType` and `expectExactType`
aryaemami59 Feb 8, 2024
5af2f31
Remove `argsMemoize.typetest.ts` file
aryaemami59 Feb 8, 2024
c041ec6
Replace `expectExactType` calls with `expectTypeOf().toEqualTypeOf()`
aryaemami59 Feb 8, 2024
d3be62c
Remove duplicate tests for `typedStructuredSelectorCreator`
aryaemami59 Feb 8, 2024
d426d2c
Convert functions and lone-blocks to `test` blocks
aryaemami59 Feb 8, 2024
4aeea48
Move `test.ts` into `type-tests` folder
aryaemami59 Feb 8, 2024
91203e0
Remove `typesTestUtils.ts` as it is no longer needed
aryaemami59 Feb 8, 2024
187bf5f
Update `test` command in `package.json` to use `yarn bin vitest`
aryaemami59 Feb 8, 2024
7cd1179
Fix `test:typescript` command
aryaemami59 Feb 8, 2024
6c42f2e
Rename `test:typescript` command to `type-tests`
aryaemami59 Feb 8, 2024
37b3fb8
Fix imports inside test files
aryaemami59 Feb 8, 2024
a62c7da
Fix type issues in `createSelector.withTypes.test-d.ts`
aryaemami59 Feb 8, 2024
c8f7cd3
Add `tsconfig.vitest-temp.json` to `.gitignore` file
aryaemami59 Feb 8, 2024
8f88ac3
Move "nested selector" type test to `deepNesting.test-d.ts`
aryaemami59 Feb 9, 2024
448c238
Move `lruMemoize` type tests into its own file
aryaemami59 Feb 9, 2024
6ecbde6
Move `createSelectorCreator` type tests into its own file
aryaemami59 Feb 9, 2024
0b27be9
Remove duplicate`createStructuredSelector.withTypes()` type tests
aryaemami59 Feb 9, 2024
d5217f7
Move `createStructuredSelector` type tests into its own file
aryaemami59 Feb 9, 2024
910fe9d
Move `createSelector` type tests into its own file
aryaemami59 Feb 9, 2024
9b5b733
Move some more `lruMemoize` type tests into its own file
aryaemami59 Feb 9, 2024
6ed0e71
Move some more `createSelectorCreator` type tests into its own file
aryaemami59 Feb 9, 2024
922bf4b
Move type tests inside `test.ts` into their respective files
aryaemami59 Feb 9, 2024
52a7863
Remove `test.ts`
aryaemami59 Feb 9, 2024
a4f0059
Make `describe` titles more consistent across type tests
aryaemami59 Feb 9, 2024
5bc347a
De-duplicate `AnyFunction` definitions
aryaemami59 Feb 9, 2024
e122b87
Fix type issues in `scripts/writeGitVersion.mjs`
aryaemami59 Feb 21, 2024
2bca06c
Rename `setup.vitest.ts` to `setup.ts`
aryaemami59 Feb 21, 2024
118f868
Change `setupFiles` to `['test/setup.ts']`
aryaemami59 Feb 21, 2024
2f2ede7
Replace references of `typescript_test` to `type-tests`
aryaemami59 Feb 21, 2024
4857c28
Remove Node ESM setup from `vitest.config.mts`
aryaemami59 Feb 24, 2024
50bd1d6
Provide the correct `tsconfig` file to `tsup`
aryaemami59 Sep 17, 2024
0916b42
Add `yalc` to `.gitignore`
aryaemami59 Apr 29, 2024
818c7e6
Run both runtime and type tests against the `dist` folder during CI
aryaemami59 Feb 8, 2024
4a522f8
Remove dead code from `computationComparisons.spec.tsx`
aryaemami59 May 10, 2024
2e42780
Remove unnecessary test from `computationComparisons.spec.tsx`
aryaemami59 May 10, 2024
3a04f9a
Remove unnecessary `async` keyword
aryaemami59 May 10, 2024
e6db620
Fix some issues that were left over from the switch to `weakMapMemoize`
aryaemami59 May 10, 2024
af9a468
Disable `watch` by default
aryaemami59 May 10, 2024
aec409e
Migrate type tests in `lruMemoize.test-d.ts` to Vitest
aryaemami59 May 16, 2024
2fe9ffd
Migrate some assertions in `createSelectorCreator.test-d.ts` to Vitest
aryaemami59 May 16, 2024
0eb2ca5
Migrate some assertions in `createSelector.test-d.ts` to Vitest
aryaemami59 May 16, 2024
f000321
Migrate some assertions in `createSelector.test-d.ts` to Vitest
aryaemami59 May 16, 2024
6413a9c
Migrate the rest of the type tests in `argsMemoize.test-d.ts` to Vitest
aryaemami59 May 31, 2024
c068d89
Set `pool` to `threads` for performance tests
aryaemami59 Aug 21, 2024
ebbd49c
Remove `esbuild` from `resolutions` field
aryaemami59 Sep 12, 2024
9f531d1
Silence `console` output by disabling `identityFunctionCheck`
aryaemami59 Sep 12, 2024
b8107e3
Bump `vitest` to version 2.1.5
aryaemami59 Aug 21, 2024
a1804e0
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 @@ -104,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 @@ -146,6 +149,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 @@ -175,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 @@ -195,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
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.9.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.4.2",
"vitest": "^1.6.0"
},
"resolutions": {
"esbuild": "0.23.0"
"vitest": "^2.1.5"
},
"packageManager": "[email protected]"
}
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