Skip to content

Commit c5a7c88

Browse files
authored
Merge pull request #4487 from reduxjs/feature/test-dist-ci
2 parents c3af089 + 4a35430 commit c5a7c88

27 files changed

+784
-1813
lines changed

.github/workflows/test.yaml

+8-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
name: Check for changes
77
runs-on: ubuntu-latest
88
outputs:
9-
toolkit: ${{ steps.filter.outputs.toolkit }}
9+
src: ${{ steps.filter.outputs.src }}
1010
steps:
1111
- uses: actions/checkout@v2
1212
- uses: dorny/paths-filter@v2
@@ -15,10 +15,11 @@ jobs:
1515
filters: |
1616
src:
1717
- 'src/**'
18+
- 'test/**'
1819
1920
build:
2021
needs: changes
21-
#if: ${{ needs.changes.outputs.src == 'true' }}
22+
if: ${{ needs.changes.outputs.src == 'true' }}
2223

2324
name: Lint, Test, Build & Pack on Node ${{ matrix.node }}
2425

@@ -40,6 +41,9 @@ jobs:
4041
- name: Install deps
4142
run: yarn install
4243

44+
- name: Build
45+
run: yarn build
46+
4347
- name: Pack
4448
run: yarn pack
4549

@@ -79,6 +83,8 @@ jobs:
7983
- name: Install build artifact
8084
run: yarn add ./package.tgz
8185

86+
- run: sed -i -e /@remap-prod-remove-line/d ./tsconfig.json ./vitest.config.ts ./test/tsconfig.json ./test/typescript/tsconfig.json
87+
8288
- name: Run tests, against dist
8389
run: yarn test
8490

docs/usage/MigratingToRedux.md

-35
This file was deleted.

jest.config.cjs

-15
This file was deleted.

package.json

+7-10
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@
4747
"format": "prettier --write \"{src,test}/**/*.{js,ts}\" \"**/*.md\"",
4848
"format:check": "prettier --list-different \"{src,test}/**/*.{js,ts}\" \"**/*.md\"",
4949
"lint": "eslint --ext js,ts src test",
50-
"check-types": "tsc --noEmit",
51-
"test": "jest",
52-
"test:types": "tsc -p test/typescript",
53-
"test:watch": "jest --watch",
54-
"test:cov": "jest --coverage",
50+
"check-types": "tsc --noEmit && echo \"Types compiled\"",
51+
"test": "vitest",
52+
"test:types": "tsc -p test/typescript && echo \"Typetests passed\"",
53+
"test:watch": "vitest --watch",
54+
"test:cov": "vitest --coverage",
5555
"build": "rollup -c",
5656
"prepublishOnly": "yarn clean && yan check-types && yarn format:check && yarn lint && yarn test",
5757
"examples:lint": "eslint --ext js,ts examples",
@@ -74,11 +74,9 @@
7474
"@rollup/plugin-node-resolve": "^15.0.1",
7575
"@rollup/plugin-replace": "^5.0.0",
7676
"@rollup/plugin-terser": "^0.4.0",
77-
"@types/jest": "29.0.0",
7877
"@types/node": "^18.7.16",
7978
"@typescript-eslint/eslint-plugin": "^5.36.2",
8079
"@typescript-eslint/parser": "^5.36.2",
81-
"babel-jest": "^29.0.3",
8280
"cross-env": "^7.0.3",
8381
"eslint": "^8.23.0",
8482
"eslint-config-react-app": "^7.0.1",
@@ -89,15 +87,14 @@
8987
"eslint-plugin-react": "^7.31.8",
9088
"eslint-plugin-react-hooks": "^4.6.0",
9189
"glob": "^8.0.3",
92-
"jest": "^29.0.3",
9390
"netlify-plugin-cache": "^1.0.3",
9491
"prettier": "^2.7.1",
9592
"rimraf": "^3.0.2",
9693
"rollup": "^3.12.0",
9794
"rollup-plugin-typescript2": "^0.34.1",
9895
"rxjs": "^7.5.6",
99-
"ts-jest": "^29.0.0",
100-
"typescript": "^4.8.3"
96+
"typescript": "^4.8.3",
97+
"vitest": "^0.27.2"
10198
},
10299
"npmName": "redux",
103100
"npmFileMap": [

test/applyMiddleware.spec.ts

+21-22
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {
77
Action,
88
Store,
99
Dispatch
10-
} from '../src'
10+
} from 'redux'
11+
import { vi } from 'vitest'
1112
import * as reducers from './helpers/reducers'
1213
import { addTodo, addTodoAsync, addTodoIfEmpty } from './helpers/actionCreators'
1314
import { thunk } from './helpers/middleware'
@@ -34,7 +35,7 @@ describe('applyMiddleware', () => {
3435
}
3536
}
3637

37-
const spy = jest.fn()
38+
const spy = vi.fn()
3839
const store = applyMiddleware(test(spy), thunk)(createStore)(reducers.todos)
3940

4041
store.dispatch(addTodo('Use Redux'))
@@ -59,7 +60,7 @@ describe('applyMiddleware', () => {
5960
}
6061
}
6162

62-
const spy = jest.fn()
63+
const spy = vi.fn()
6364
const store = applyMiddleware(test(spy), thunk)(createStore)(reducers.todos)
6465

6566
// the typing for redux-thunk is super complex, so we will use an as unknown hack
@@ -71,7 +72,7 @@ describe('applyMiddleware', () => {
7172
})
7273
})
7374

74-
it('works with thunk middleware', done => {
75+
it('works with thunk middleware', async () => {
7576
const store = applyMiddleware(thunk)(createStore)(reducers.todos)
7677

7778
store.dispatch(addTodoIfEmpty('Hello') as any)
@@ -106,27 +107,25 @@ describe('applyMiddleware', () => {
106107
const dispatchedValue = store.dispatch(
107108
addTodoAsync('Maybe') as any
108109
) as unknown as Promise<void>
109-
dispatchedValue.then(() => {
110-
expect(store.getState()).toEqual([
111-
{
112-
id: 1,
113-
text: 'Hello'
114-
},
115-
{
116-
id: 2,
117-
text: 'World'
118-
},
119-
{
120-
id: 3,
121-
text: 'Maybe'
122-
}
123-
])
124-
done()
125-
})
110+
await dispatchedValue
111+
expect(store.getState()).toEqual([
112+
{
113+
id: 1,
114+
text: 'Hello'
115+
},
116+
{
117+
id: 2,
118+
text: 'World'
119+
},
120+
{
121+
id: 3,
122+
text: 'Maybe'
123+
}
124+
])
126125
})
127126

128127
it('passes through all arguments of dispatch calls from within middleware', () => {
129-
const spy = jest.fn()
128+
const spy = vi.fn()
130129
const testCallArgs = ['test']
131130

132131
interface MultiDispatch<A extends Action = AnyAction> {

test/combineReducers.spec.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import {
55
Reducer,
66
AnyAction,
77
__DO_NOT_USE__ActionTypes as ActionTypes
8-
} from '../src'
8+
} from 'redux'
9+
import { vi } from 'vitest'
910

1011
describe('Utils', () => {
1112
describe('combineReducers', () => {
@@ -39,7 +40,7 @@ describe('Utils', () => {
3940

4041
it('warns if a reducer prop is undefined', () => {
4142
const preSpy = console.error
42-
const spy = jest.fn()
43+
const spy = vi.fn()
4344
console.error = spy
4445

4546
let isNotDefined: any
@@ -199,7 +200,7 @@ describe('Utils', () => {
199200

200201
it('warns if no reducers are passed to combineReducers', () => {
201202
const preSpy = console.error
202-
const spy = jest.fn()
203+
const spy = vi.fn()
203204
console.error = spy
204205

205206
const reducer = combineReducers({})
@@ -214,7 +215,7 @@ describe('Utils', () => {
214215

215216
it('warns if input state does not match reducer shape', () => {
216217
const preSpy = console.error
217-
const spy = jest.fn()
218+
const spy = vi.fn()
218219
const nullAction = undefined as unknown as AnyAction
219220
console.error = spy
220221

@@ -287,7 +288,7 @@ describe('Utils', () => {
287288

288289
it('only warns for unexpected keys once', () => {
289290
const preSpy = console.error
290-
const spy = jest.fn()
291+
const spy = vi.fn()
291292
console.error = spy
292293
const nullAction = { type: '' }
293294

0 commit comments

Comments
 (0)