Skip to content

Commit ea1017f

Browse files
authored
Merge pull request #4047 from aryaemami59/bump-vitest
Bump Vitest to latest version
2 parents ed8282e + a65a81f commit ea1017f

9 files changed

+678
-32
lines changed

packages/toolkit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
"tsup": "^7.2.0",
9191
"tsx": "^3.12.2",
9292
"typescript": "5.2",
93-
"vitest": "^0.30.1",
93+
"vitest": "^1.1.3",
9494
"yargs": "^15.3.1"
9595
},
9696
"scripts": {

packages/toolkit/src/query/tests/apiProvider.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ describe('ApiProvider', () => {
6767
</Provider>
6868
)
6969
).toThrowErrorMatchingInlineSnapshot(
70-
'"Existing Redux context detected. If you already have a store set up, please use the traditional Redux setup."'
70+
`[Error: Existing Redux context detected. If you already have a store set up, please use the traditional Redux setup.]`
7171
)
7272
})
7373
})

packages/toolkit/src/query/tests/buildCreateApi.test.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,10 @@ describe('buildCreateApi', () => {
120120
}
121121

122122
expect(callBuildCreateApi).toThrowErrorMatchingInlineSnapshot(
123-
`"When using custom hooks for context, all 3 hooks need to be provided: useDispatch, useSelector, useStore.\nHook useStore was either not provided or not a function."`
123+
`
124+
[Error: When using custom hooks for context, all 3 hooks need to be provided: useDispatch, useSelector, useStore.
125+
Hook useStore was either not provided or not a function.]
126+
`
124127
)
125128
})
126129
})

packages/toolkit/src/query/tests/defaultSerializeQueryArgs.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ test('string arg', () => {
1010
endpointName,
1111
queryArgs: 'arg',
1212
})
13-
).toMatchInlineSnapshot(`"test(\\"arg\\")"`)
13+
).toMatchInlineSnapshot(`"test("arg")"`)
1414
})
1515

1616
test('number arg', () => {
@@ -30,7 +30,7 @@ test('simple object arg is sorted', () => {
3030
endpointName,
3131
queryArgs: { name: 'arg', age: 5 },
3232
})
33-
).toMatchInlineSnapshot(`"test({\\"age\\":5,\\"name\\":\\"arg\\"})"`)
33+
).toMatchInlineSnapshot(`"test({"age":5,"name":"arg"})"`)
3434
})
3535

3636
test('nested object arg is sorted recursively', () => {
@@ -41,7 +41,7 @@ test('nested object arg is sorted recursively', () => {
4141
queryArgs: { name: { last: 'Split', first: 'Banana' }, age: 5 },
4242
})
4343
).toMatchInlineSnapshot(
44-
`"test({\\"age\\":5,\\"name\\":{\\"first\\":\\"Banana\\",\\"last\\":\\"Split\\"}})"`
44+
`"test({"age":5,"name":{"first":"Banana","last":"Split"}})"`
4545
)
4646
})
4747

@@ -70,7 +70,7 @@ test('Fully serializes a deeply nested object', () => {
7070
queryArgs: nestedObj,
7171
})
7272
expect(res).toMatchInlineSnapshot(
73-
`"test({\\"a\\":{\\"a1\\":{\\"a11\\":{\\"a111\\":1}}},\\"b\\":{\\"b1\\":{\\"b11\\":2},\\"b2\\":{\\"b21\\":3}}})"`
73+
`"test({"a":{"a1":{"a11":{"a111":1}}},"b":{"b1":{"b11":2},"b2":{"b21":3}}})"`
7474
)
7575
})
7676

packages/toolkit/src/tests/createReducer.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ describe('createReducer', () => {
306306
)
307307
)
308308
expect(() => reducer(5, decrement(5))).toThrowErrorMatchingInlineSnapshot(
309-
`"A case reducer on a non-draftable value must not return undefined"`
309+
`[Error: A case reducer on a non-draftable value must not return undefined]`
310310
)
311311
})
312312
test('allows you to return undefined if the state was null, thus skipping an update', () => {
@@ -354,7 +354,7 @@ describe('createReducer', () => {
354354
.addCase(decrement, (state, action) => state - action.payload)
355355
)
356356
).toThrowErrorMatchingInlineSnapshot(
357-
'"`builder.addCase` cannot be called with two reducers for the same action type \'increment\'"'
357+
`[Error: \`builder.addCase\` cannot be called with two reducers for the same action type 'increment']`
358358
)
359359
expect(() =>
360360
createReducer(0, (builder) =>
@@ -364,7 +364,7 @@ describe('createReducer', () => {
364364
.addCase(decrement, (state, action) => state - action.payload)
365365
)
366366
).toThrowErrorMatchingInlineSnapshot(
367-
'"`builder.addCase` cannot be called with two reducers for the same action type \'increment\'"'
367+
`[Error: \`builder.addCase\` cannot be called with two reducers for the same action type 'increment']`
368368
)
369369
})
370370

@@ -382,7 +382,7 @@ describe('createReducer', () => {
382382
)
383383
)
384384
).toThrowErrorMatchingInlineSnapshot(
385-
'"`builder.addCase` cannot be called with an empty action type"'
385+
`[Error: \`builder.addCase\` cannot be called with an empty action type]`
386386
)
387387
})
388388
})
@@ -507,14 +507,14 @@ describe('createReducer', () => {
507507
.addCase(incrementBy, () => {})
508508
)
509509
).toThrowErrorMatchingInlineSnapshot(
510-
`"\`builder.addCase\` should only be called before calling \`builder.addMatcher\`"`
510+
`[Error: \`builder.addCase\` should only be called before calling \`builder.addMatcher\`]`
511511
)
512512
expect(() =>
513513
createReducer(initialState, (builder: any) =>
514514
builder.addDefaultCase(() => {}).addCase(incrementBy, () => {})
515515
)
516516
).toThrowErrorMatchingInlineSnapshot(
517-
`"\`builder.addCase\` should only be called before calling \`builder.addDefaultCase\`"`
517+
`[Error: \`builder.addCase\` should only be called before calling \`builder.addDefaultCase\`]`
518518
)
519519
expect(() =>
520520
createReducer(initialState, (builder: any) =>
@@ -523,14 +523,14 @@ describe('createReducer', () => {
523523
.addMatcher(numberActionMatcher, () => {})
524524
)
525525
).toThrowErrorMatchingInlineSnapshot(
526-
`"\`builder.addMatcher\` should only be called before calling \`builder.addDefaultCase\`"`
526+
`[Error: \`builder.addMatcher\` should only be called before calling \`builder.addDefaultCase\`]`
527527
)
528528
expect(() =>
529529
createReducer(initialState, (builder: any) =>
530530
builder.addDefaultCase(() => {}).addDefaultCase(() => {})
531531
)
532532
).toThrowErrorMatchingInlineSnapshot(
533-
`"\`builder.addDefaultCase\` can only be called once"`
533+
`[Error: \`builder.addDefaultCase\` can only be called once]`
534534
)
535535
})
536536
})

packages/toolkit/src/tests/createSlice.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ describe('createSlice', () => {
252252
})
253253
slice.reducer(undefined, { type: 'unrelated' })
254254
}).toThrowErrorMatchingInlineSnapshot(
255-
'"`builder.addCase` cannot be called with two reducers for the same action type \'increment\'"'
255+
`[Error: \`builder.addCase\` cannot be called with two reducers for the same action type 'increment']`
256256
)
257257
})
258258

@@ -587,7 +587,7 @@ describe('createSlice', () => {
587587
reducers: (create) => ({ thunk: create.asyncThunk(() => {}) }),
588588
})
589589
).toThrowErrorMatchingInlineSnapshot(
590-
'"Cannot use `create.asyncThunk` in the built-in `createSlice`. Use `buildCreateSlice({ creators: { asyncThunk: asyncThunkCreator } })` to create a customised version of `createSlice`."'
590+
`[Error: Cannot use \`create.asyncThunk\` in the built-in \`createSlice\`. Use \`buildCreateSlice({ creators: { asyncThunk: asyncThunkCreator } })\` to create a customised version of \`createSlice\`.]`
591591
)
592592
})
593593
const createAppSlice = buildCreateSlice({
@@ -826,7 +826,7 @@ describe('createSlice', () => {
826826
}),
827827
})
828828
).toThrowErrorMatchingInlineSnapshot(
829-
`"Please use the \`create.preparedReducer\` notation for prepared action creators with the \`create\` notation."`
829+
`[Error: Please use the \`create.preparedReducer\` notation for prepared action creators with the \`create\` notation.]`
830830
)
831831
})
832832
})

packages/toolkit/src/tests/serializableStateInvariantMiddleware.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ describe('serializableStateInvariantMiddleware', () => {
112112
expect(getLog().log).toMatchInlineSnapshot(`
113113
"A non-serializable value was detected in an action, in the path: \`payload\`. Value: Symbol(SOME_CONSTANT)
114114
Take a look at the logic that dispatched this action: Object {
115-
\\"payload\\": Symbol(SOME_CONSTANT),
116-
\\"type\\": \\"an-action\\",
115+
"payload": Symbol(SOME_CONSTANT),
116+
"type": "an-action",
117117
}
118118
(See https://redux.js.org/faq/actions#why-should-type-be-a-string-or-at-least-serializable-why-should-my-action-types-be-constants)
119119
(To allow non-serializable values see: https://redux-toolkit.js.org/usage/usage-guide#working-with-non-serializable-data)"
@@ -369,10 +369,10 @@ describe('serializableStateInvariantMiddleware', () => {
369369
expect(getLog().log).toMatchInlineSnapshot(`
370370
"A non-serializable value was detected in an action, in the path: \`meta.arg\`. Value: Map {}
371371
Take a look at the logic that dispatched this action: Object {
372-
\\"meta\\": Object {
373-
\\"arg\\": Map {},
372+
"meta": Object {
373+
"arg": Map {},
374374
},
375-
\\"type\\": \\"test\\",
375+
"type": "test",
376376
}
377377
(See https://redux.js.org/faq/actions#why-should-type-be-a-string-or-at-least-serializable-why-should-my-action-types-be-constants)
378378
(To allow non-serializable values see: https://redux-toolkit.js.org/usage/usage-guide#working-with-non-serializable-data)"

packages/toolkit/vitest.config.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
import { defineConfig } from 'vitest/config'
22

3+
import path from 'path'
4+
import { fileURLToPath } from 'url'
5+
6+
// No __dirname under Node ESM
7+
const __filename = fileURLToPath(import.meta.url)
8+
const __dirname = path.dirname(__filename)
9+
310
export default defineConfig({
411
test: {
512
globals: true,
613
environment: 'jsdom',
714
setupFiles: ['./vitest.setup.js'],
815
include: ['./src/**/*.(spec|test).[jt]s?(x)'],
916
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/react': './src/index.ts', // @remap-prod-remove-line
13-
'@reduxjs/toolkit': './src/index.ts', // @remap-prod-remove-line
17+
'@reduxjs/toolkit/query/react': path.join(__dirname,'./src/query/react/index.ts'), // @remap-prod-remove-line
18+
'@reduxjs/toolkit/query': path.join(__dirname, './src/query/index.ts'), // @remap-prod-remove-line
19+
'@reduxjs/toolkit/react': path.join(__dirname, './src/index.ts'), // @remap-prod-remove-line
20+
'@reduxjs/toolkit': path.join(__dirname, './src/index.ts'), // @remap-prod-remove-line
1421

1522
// 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
1623
//'^@reduxjs/toolkit/dist/(.*)$': '<rootDir>/src/*',
17-
'@internal/': './src/',
24+
'@internal': path.join(__dirname, './src'),
1825
},
1926
deps: {
2027
interopDefault: true,

0 commit comments

Comments
 (0)