Skip to content

Commit bf04cf7

Browse files
authored
Migrate type tests to Vitest (#367)
1 parent c403cf7 commit bf04cf7

18 files changed

+1070
-490
lines changed

.github/workflows/test.yml

+56-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
name: CI
22

3-
on:
4-
push:
5-
branches: [master]
6-
pull_request:
7-
branches: [master]
3+
on: [push, pull_request, workflow_dispatch]
84

95
jobs:
106
build:
@@ -37,9 +33,6 @@ jobs:
3733
- name: Run linter
3834
run: yarn lint
3935

40-
- name: Run tests
41-
run: yarn test
42-
4336
- name: Pack
4437
run: yarn pack
4538

@@ -48,6 +41,46 @@ jobs:
4841
name: package
4942
path: ./package.tgz
5043

44+
test-dist:
45+
name: Test against dist
46+
needs: [build]
47+
runs-on: ubuntu-latest
48+
strategy:
49+
fail-fast: false
50+
matrix:
51+
node: ['20.x']
52+
steps:
53+
- name: Checkout repo
54+
uses: actions/checkout@v4
55+
56+
- name: Use node ${{ matrix.node }}
57+
uses: actions/setup-node@v4
58+
with:
59+
node-version: ${{ matrix.node }}
60+
cache: 'yarn'
61+
62+
- name: Install deps
63+
run: yarn install
64+
65+
- name: Download build artifact
66+
uses: actions/download-artifact@v4
67+
with:
68+
name: package
69+
path: .
70+
71+
- run: ls -lah
72+
73+
- name: Install build artifact
74+
run: yarn add ./package.tgz
75+
76+
- name: Erase path aliases
77+
run: sed -i -e /@remap-prod-remove-line/d ./tsconfig.base.json
78+
79+
- name: Run tests, against dist
80+
env:
81+
TEST_DIST: true
82+
run: yarn test
83+
5184
test-types:
5285
name: Test Types with TypeScript ${{ matrix.ts }}
5386
needs: [build]
@@ -69,16 +102,30 @@ jobs:
69102
node-version: ${{ matrix.node }}
70103
cache: 'yarn'
71104

105+
- name: Download build artifact
106+
uses: actions/download-artifact@v4
107+
with:
108+
name: package
109+
path: .
110+
72111
- name: Install deps
73112
run: yarn install
74113

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

117+
- name: Install build artifact
118+
run: yarn add ./package.tgz
119+
120+
- name: Erase path aliases
121+
run: sed -i -e /@remap-prod-remove-line/d ./tsconfig.base.json
122+
78123
- name: Test types
124+
env:
125+
TEST_DIST: true
79126
run: |
80127
yarn tsc --version
81-
yarn test:typescript
128+
yarn type-tests
82129
83130
test-published-artifact:
84131
name: Test Published Artifact ${{ matrix.example }}

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ dist
66
es
77
builds/
88

9-
109
typesversions
1110
.cache
1211
.yarnrc
@@ -18,3 +17,7 @@ typesversions
1817
!.yarn/versions
1918
.pnp.*
2019
*.tgz
20+
21+
tsconfig.vitest-temp.json
22+
23+
.vscode

package.json

+8-6
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,18 @@
3737
"format": "prettier --write \"{src,test,typescript_test}/**/*.{js,ts}\"",
3838
"format:check": "prettier --check \"{src,test,typescript_test}/**/*.{js,ts}\"",
3939
"lint": "eslint \"{src,test,typescript_test}/**/*.{js,ts}\"",
40-
"test": "vitest run",
41-
"test:cov": "vitest run --coverage",
42-
"test:typescript": "tsc --noEmit -p typescript_test/tsconfig.json",
43-
"build": "tsup",
40+
"test": "vitest --run --typecheck",
41+
"test:watch": "vitest --watch",
42+
"test:cov": "vitest --run --coverage",
43+
"type-tests": "tsc --noEmit -p tsconfig.test.json",
44+
"build": "yarn clean && tsup",
4445
"prepack": "yarn build"
4546
},
4647
"peerDependencies": {
4748
"redux": "^5.0.0"
4849
},
4950
"devDependencies": {
51+
"@types/node": "^20.11.20",
5052
"@typescript-eslint/eslint-plugin": "^5.1.0",
5153
"@typescript-eslint/parser": "^5.1.0",
5254
"cross-env": "^7.0.3",
@@ -56,8 +58,8 @@
5658
"redux": "^5",
5759
"rimraf": "^3.0.2",
5860
"tsup": "7.0.0",
59-
"typescript": "^5.4.2",
60-
"vitest": "^0.32.0"
61+
"typescript": "^5.4.5",
62+
"vitest": "^1.6.0"
6163
},
6264
"packageManager": "[email protected]"
6365
}

scripts/writeGitVersion.mjs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import path from 'path'
2-
import fs from 'fs'
1+
import fs from 'node:fs'
2+
import path from 'node:path'
33
import { fileURLToPath } from 'node:url'
44

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

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

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

src/index.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import type { Action, AnyAction } from 'redux'
2-
32
import type { ThunkMiddleware } from './types'
43

54
export type {
65
ThunkAction,
7-
ThunkDispatch,
86
ThunkActionDispatch,
7+
ThunkDispatch,
98
ThunkMiddleware
109
} from './types'
1110

test/test.ts test/index.test.ts

File renamed without changes.

test/tsconfig.json

-9
This file was deleted.

tsconfig.base.json

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"compilerOptions": {
3+
"allowSyntheticDefaultImports": true,
4+
"declaration": true,
5+
"downlevelIteration": false,
6+
"esModuleInterop": true,
7+
"forceConsistentCasingInFileNames": true,
8+
"importHelpers": true,
9+
"isolatedModules": true,
10+
"jsx": "react",
11+
"lib": ["DOM", "ESNext"],
12+
"module": "ESnext",
13+
"moduleResolution": "Node",
14+
"noErrorTruncation": true,
15+
"noFallthroughCasesInSwitch": true,
16+
"noUnusedLocals": false,
17+
"noUnusedParameters": false,
18+
"paths": {
19+
"@internal/*": ["./src/*"],
20+
"redux-thunk": ["./src/index.ts"] // @remap-prod-remove-line
21+
},
22+
"resolveJsonModule": true,
23+
"skipLibCheck": true,
24+
"strict": true,
25+
"target": "ESnext",
26+
"types": ["vitest/globals", "vitest/importMeta"]
27+
},
28+
"exclude": ["dist"]
29+
}

tsconfig.build.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
// For building the library.
3+
"extends": "./tsconfig.base.json",
4+
"compilerOptions": {
5+
"emitDeclarationOnly": true,
6+
"outDir": "dist",
7+
"rootDir": "./src"
8+
},
9+
"include": ["src"]
10+
}

tsconfig.json

+7-20
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,12 @@
11
{
2+
// For general development and intellisense.
3+
// Scans the entire source code against the current TS version
4+
// we are using during development.
5+
"extends": "./tsconfig.test.json",
26
"compilerOptions": {
3-
"strict": true,
4-
"target": "ESNext",
5-
"module": "ESNext",
6-
"moduleResolution": "Node",
7-
"esModuleInterop": true,
8-
"skipLibCheck": true,
97
"allowJs": true,
10-
"jsx": "react",
11-
"declaration": true,
12-
"emitDeclarationOnly": true,
13-
"forceConsistentCasingInFileNames": true,
14-
"experimentalDecorators": true,
15-
"rootDirs": ["./src", "./test"],
16-
"types": ["vitest/globals"],
17-
"baseUrl": ".",
18-
"paths": {
19-
"redux-thunk": ["src/index.ts"], // @remap-prod-remove-line
20-
"@internal/*": ["src/*"]
21-
}
8+
"checkJs": true,
9+
"rootDir": "."
2210
},
23-
"include": ["src/**/*"],
24-
"exclude": ["node_modules", "dist"]
11+
"include": ["."]
2512
}

tsconfig.test.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
// For runtime and type tests during CI.
3+
"extends": "./tsconfig.base.json",
4+
"compilerOptions": {
5+
"noEmit": true,
6+
"jsx": "react-jsx",
7+
"noImplicitReturns": false
8+
},
9+
"include": ["typescript_test"]
10+
}

tsup.config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export default defineConfig(options => {
66
entry: {
77
'redux-thunk': 'src/index.ts'
88
},
9+
tsconfig: 'tsconfig.build.json',
910
...options
1011
}
1112

0 commit comments

Comments
 (0)