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

Merged
merged 43 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
3843506
Bump Vitest
aryaemami59 Feb 24, 2024
fd2b480
Bump typescript
aryaemami59 Feb 24, 2024
3bc821a
Rename `vitest.config.ts` to `vitest.config.mts`
aryaemami59 Feb 24, 2024
c308b50
Remove `typescript_test\typescript_extended\tsconfig.json`
aryaemami59 Feb 24, 2024
24ae054
Remove `deps.interopDefault: true` as it is the default
aryaemami59 Feb 24, 2024
950ca91
Fix NPM scripts
aryaemami59 Feb 24, 2024
2fe062c
Include type checking with Vitest
aryaemami59 Feb 24, 2024
3e044e8
Fix aliases in `vitest.config.mts`
aryaemami59 Feb 24, 2024
ad7af30
Rename `typescript_test/tsconfig.json` to `tsconfig.test.json`
aryaemami59 Feb 24, 2024
e2d6d5f
Remove `tsconfig.json` from `test` folder
aryaemami59 Feb 24, 2024
0e8aaae
Add `tsconfig.base.json` file
aryaemami59 Feb 24, 2024
c6e0b85
Add `tsconfig.build.json` file
aryaemami59 Feb 24, 2024
0dea0e2
Fix `tsconfig.test.json`
aryaemami59 Feb 24, 2024
dc2dcb5
Fix `tsconfig.json` file
aryaemami59 Feb 24, 2024
d4e428d
Fix `tsup.config.ts` file
aryaemami59 Feb 24, 2024
e7b3abf
Change `test:typescript` to `type-tests` to stay consistent with RTK
aryaemami59 Feb 24, 2024
a63138d
Add `@types/node` to dev dependencies
aryaemami59 Feb 24, 2024
71b0bab
Rename `test.ts` to `index.test.ts`
aryaemami59 Feb 24, 2024
52430e2
Rename `typescript.ts` to `index.test-d.ts`
aryaemami59 Feb 24, 2024
2c71c6a
Convert some of the type tests to Vitest
aryaemami59 Feb 24, 2024
a4e0bd8
Fix type issues in JS files
aryaemami59 Feb 24, 2024
07e68d7
Fix test types command in CI
aryaemami59 Feb 24, 2024
e951f7e
Remove `rootDir` from `tsconfig.test.json`
aryaemami59 Feb 24, 2024
06254a1
Add `test-dist` CI step
aryaemami59 Feb 24, 2024
b953572
Add `tsconfig.vitest-temp.json` to `.gitignore`
aryaemami59 Feb 24, 2024
0bbb2af
Merge branch 'master' of https://github.com/reduxjs/redux-thunk into …
aryaemami59 Mar 9, 2024
a400de5
Reorder imports in `index.ts`
aryaemami59 Mar 9, 2024
abd8d18
Update GitHub Actions versions
aryaemami59 Mar 9, 2024
057004c
Merge branch 'master' of https://github.com/reduxjs/redux-thunk into …
aryaemami59 Mar 10, 2024
487bca3
Merge branch 'master' of https://github.com/reduxjs/redux-thunk into …
aryaemami59 Mar 11, 2024
e6b9329
Fix `tsconfig.json`
aryaemami59 Mar 16, 2024
9d2c654
Bump `vitest` to latest version
aryaemami59 Mar 16, 2024
df2cb06
Merge branch 'master' of https://github.com/reduxjs/redux-thunk into …
aryaemami59 Mar 21, 2024
3882793
Merge branch 'master' of https://github.com/reduxjs/redux-thunk into …
aryaemami59 Mar 22, 2024
b0be54f
Bump `vitest`
aryaemami59 Apr 17, 2024
a79e88f
Bump TypeScript
aryaemami59 Apr 17, 2024
dd165a9
Bump `vitest` to version 1.5.3
aryaemami59 May 1, 2024
02ee058
Bump `vitest` to version 1.6.0
aryaemami59 May 6, 2024
6ceb26d
Update lockfile
aryaemami59 Jun 24, 2024
af3b7b6
Add `.vscode` to `.gitignore`
aryaemami59 Jun 24, 2024
f51b119
Fix CI tests
aryaemami59 Jun 24, 2024
fc3e747
Migrate remaining type tests to Vitest
aryaemami59 Jul 12, 2024
1e0865c
Update lockfile
aryaemami59 Jul 12, 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
65 changes: 56 additions & 9 deletions .github/workflows/test.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 @@ -37,9 +33,6 @@ jobs:
- name: Run linter
run: yarn lint

- name: Run tests
run: yarn test

- name: Pack
run: yarn pack

Expand All @@ -48,6 +41,46 @@ jobs:
name: package
path: ./package.tgz

test-dist:
name: Test against dist
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 deps
run: yarn install

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

- 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 tests, against dist
env:
TEST_DIST: true
run: yarn test

test-types:
name: Test Types with TypeScript ${{ matrix.ts }}
needs: [build]
Expand All @@ -69,16 +102,30 @@ 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

- name: Install TypeScript ${{ matrix.ts }}
run: yarn add typescript@${{ matrix.ts }}

- 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: Test types
env:
TEST_DIST: true
run: |
yarn tsc --version
yarn test:typescript
yarn type-tests

test-published-artifact:
name: Test Published Artifact ${{ matrix.example }}
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ dist
es
builds/


typesversions
.cache
.yarnrc
Expand All @@ -18,3 +17,7 @@ typesversions
!.yarn/versions
.pnp.*
*.tgz

tsconfig.vitest-temp.json

.vscode
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,18 @@
"format": "prettier --write \"{src,test,typescript_test}/**/*.{js,ts}\"",
"format:check": "prettier --check \"{src,test,typescript_test}/**/*.{js,ts}\"",
"lint": "eslint \"{src,test,typescript_test}/**/*.{js,ts}\"",
"test": "vitest run",
"test:cov": "vitest run --coverage",
"test:typescript": "tsc --noEmit -p typescript_test/tsconfig.json",
"build": "tsup",
"test": "vitest --run --typecheck",
"test:watch": "vitest --watch",
"test:cov": "vitest --run --coverage",
"type-tests": "tsc --noEmit -p tsconfig.test.json",
"build": "yarn clean && tsup",
"prepack": "yarn build"
},
"peerDependencies": {
"redux": "^5.0.0"
},
"devDependencies": {
"@types/node": "^20.11.20",
"@typescript-eslint/eslint-plugin": "^5.1.0",
"@typescript-eslint/parser": "^5.1.0",
"cross-env": "^7.0.3",
Expand All @@ -56,8 +58,8 @@
"redux": "^5",
"rimraf": "^3.0.2",
"tsup": "7.0.0",
"typescript": "^5.4.2",
"vitest": "^0.32.0"
"typescript": "^5.4.5",
"vitest": "^1.6.0"
},
"packageManager": "[email protected]"
}
6 changes: 3 additions & 3 deletions scripts/writeGitVersion.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'path'
import fs from 'fs'
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'

const __filename = fileURLToPath(import.meta.url)
Expand All @@ -8,7 +8,7 @@ const __dirname = path.dirname(__filename)
const gitRev = process.argv[2]

const packagePath = path.join(__dirname, '../package.json')
const pkg = JSON.parse(fs.readFileSync(packagePath))
const pkg = JSON.parse(fs.readFileSync(packagePath, 'utf8'))

pkg.version = `${pkg.version}-${gitRev}`
fs.writeFileSync(packagePath, JSON.stringify(pkg, null, 2))
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import type { Action, AnyAction } from 'redux'

import type { ThunkMiddleware } from './types'

export type {
ThunkAction,
ThunkDispatch,
ThunkActionDispatch,
ThunkDispatch,
ThunkMiddleware
} from './types'

Expand Down
File renamed without changes.
9 changes: 0 additions & 9 deletions test/tsconfig.json

This file was deleted.

29 changes: 29 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"declaration": true,
"downlevelIteration": false,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"importHelpers": true,
"isolatedModules": true,
"jsx": "react",
"lib": ["DOM", "ESNext"],
"module": "ESnext",
"moduleResolution": "Node",
"noErrorTruncation": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"paths": {
"@internal/*": ["./src/*"],
"redux-thunk": ["./src/index.ts"] // @remap-prod-remove-line
},
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true,
"target": "ESnext",
"types": ["vitest/globals", "vitest/importMeta"]
},
"exclude": ["dist"]
}
10 changes: 10 additions & 0 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
// For building the library.
"extends": "./tsconfig.base.json",
"compilerOptions": {
"emitDeclarationOnly": true,
"outDir": "dist",
"rootDir": "./src"
},
"include": ["src"]
}
27 changes: 7 additions & 20 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
{
// For general development and intellisense.
// Scans the entire source code against the current TS version
// we are using during development.
"extends": "./tsconfig.test.json",
"compilerOptions": {
"strict": true,
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Node",
"esModuleInterop": true,
"skipLibCheck": true,
"allowJs": true,
"jsx": "react",
"declaration": true,
"emitDeclarationOnly": true,
"forceConsistentCasingInFileNames": true,
"experimentalDecorators": true,
"rootDirs": ["./src", "./test"],
"types": ["vitest/globals"],
"baseUrl": ".",
"paths": {
"redux-thunk": ["src/index.ts"], // @remap-prod-remove-line
"@internal/*": ["src/*"]
}
"checkJs": true,
"rootDir": "."
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
"include": ["."]
}
10 changes: 10 additions & 0 deletions tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
// For runtime and type tests during CI.
"extends": "./tsconfig.base.json",
"compilerOptions": {
"noEmit": true,
"jsx": "react-jsx",
"noImplicitReturns": false
},
"include": ["typescript_test"]
}
1 change: 1 addition & 0 deletions tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default defineConfig(options => {
entry: {
'redux-thunk': 'src/index.ts'
},
tsconfig: 'tsconfig.build.json',
...options
}

Expand Down
Loading