Skip to content

Commit 34ce9b5

Browse files
committed
Replace Jest config with Vitest config
1 parent b13958a commit 34ce9b5

File tree

5 files changed

+30
-28
lines changed

5 files changed

+30
-28
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ jobs:
8282
- name: Install build artifact
8383
run: yarn workspace @reduxjs/toolkit add $(pwd)/package.tgz
8484

85-
- run: sed -i -e /@remap-prod-remove-line/d ./tsconfig.base.json ./jest.config.js ./src/tests/*.* ./src/query/tests/*.*
85+
- run: sed -i -e /@remap-prod-remove-line/d ./tsconfig.base.json ./vitest.config.ts ./src/tests/*.* ./src/query/tests/*.*
8686

8787
- name: Run tests, against dist
8888
run: yarn test
@@ -121,7 +121,7 @@ jobs:
121121
- name: Install build artifact
122122
run: yarn add ./package.tgz
123123

124-
- run: sed -i -e /@remap-prod-remove-line/d ./tsconfig.base.json ./jest.config.js ./src/tests/*.* ./src/query/tests/*.*
124+
- run: sed -i -e /@remap-prod-remove-line/d ./tsconfig.base.json ./vitest.config.ts ./src/tests/*.* ./src/query/tests/*.*
125125

126126
- name: Test types
127127
run: |

packages/toolkit/jest.config.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

packages/toolkit/tsconfig.base.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"allowSyntheticDefaultImports": true,
3131
"emitDeclarationOnly": true,
3232
"baseUrl": ".",
33+
"types": ["vitest/globals"],
3334
"paths": {
3435
"@reduxjs/toolkit": ["src/index.ts"], // @remap-prod-remove-line
3536
"@reduxjs/toolkit/query": ["src/query/index.ts"], // @remap-prod-remove-line

packages/toolkit/vitest.config.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { defineConfig } from 'vitest/config'
2+
3+
export default defineConfig({
4+
test: {
5+
globals: true,
6+
environment: 'jsdom',
7+
setupFiles: ['./vitest.setup.js'],
8+
include: ['./src/**/*.(spec|test).[jt]s?(x)'],
9+
alias: {
10+
'@reduxjs/toolkit/query/react': './src/query/react/index.ts', // @remap-prod-remove-line
11+
'@reduxjs/toolkit/query': './src/query/index.ts', // @remap-prod-remove-line
12+
'@reduxjs/toolkit': './src/index.ts', // @remap-prod-remove-line
13+
14+
// this mapping is disabled as we want `dist` imports in the tests only to be used for "type-only" imports which don't play a role for jest
15+
//'^@reduxjs/toolkit/dist/(.*)$': '<rootDir>/src/*',
16+
'@internal/': './src/',
17+
},
18+
deps: {
19+
interopDefault: true,
20+
},
21+
},
22+
})

packages/toolkit/jest.setup.js renamed to packages/toolkit/vitest.setup.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
//@ts-ignore
2-
const nodeFetch = require('node-fetch')
2+
import nodeFetch from 'node-fetch'
33
//@ts-ignore
4-
global.fetch = nodeFetch
4+
globalThis.fetch = nodeFetch
55
//@ts-ignore
6-
global.Request = nodeFetch.Request
7-
const { server } = require('./src/query/tests/mocks/server')
6+
globalThis.Request = nodeFetch.Request
7+
globalThis.Headers = nodeFetch.Headers
8+
import { server } from './src/query/tests/mocks/server'
89

910
beforeAll(() => server.listen({ onUnhandledRequest: 'error' }))
1011
afterEach(() => server.resetHandlers())

0 commit comments

Comments
 (0)