Skip to content

Commit

Permalink
Merge pull request #4047 from aryaemami59/bump-vitest
Browse files Browse the repository at this point in the history
Bump Vitest to latest version
  • Loading branch information
EskiMojo14 committed Jan 5, 2024
2 parents ed8282e + a65a81f commit ea1017f
Show file tree
Hide file tree
Showing 9 changed files with 678 additions and 32 deletions.
2 changes: 1 addition & 1 deletion packages/toolkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"tsup": "^7.2.0",
"tsx": "^3.12.2",
"typescript": "5.2",
"vitest": "^0.30.1",
"vitest": "^1.1.3",
"yargs": "^15.3.1"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/toolkit/src/query/tests/apiProvider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('ApiProvider', () => {
</Provider>
)
).toThrowErrorMatchingInlineSnapshot(
'"Existing Redux context detected. If you already have a store set up, please use the traditional Redux setup."'
`[Error: Existing Redux context detected. If you already have a store set up, please use the traditional Redux setup.]`
)
})
})
5 changes: 4 additions & 1 deletion packages/toolkit/src/query/tests/buildCreateApi.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ describe('buildCreateApi', () => {
}

expect(callBuildCreateApi).toThrowErrorMatchingInlineSnapshot(
`"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."`
`
[Error: When using custom hooks for context, all 3 hooks need to be provided: useDispatch, useSelector, useStore.
Hook useStore was either not provided or not a function.]
`
)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ test('string arg', () => {
endpointName,
queryArgs: 'arg',
})
).toMatchInlineSnapshot(`"test(\\"arg\\")"`)
).toMatchInlineSnapshot(`"test("arg")"`)
})

test('number arg', () => {
Expand All @@ -30,7 +30,7 @@ test('simple object arg is sorted', () => {
endpointName,
queryArgs: { name: 'arg', age: 5 },
})
).toMatchInlineSnapshot(`"test({\\"age\\":5,\\"name\\":\\"arg\\"})"`)
).toMatchInlineSnapshot(`"test({"age":5,"name":"arg"})"`)
})

test('nested object arg is sorted recursively', () => {
Expand All @@ -41,7 +41,7 @@ test('nested object arg is sorted recursively', () => {
queryArgs: { name: { last: 'Split', first: 'Banana' }, age: 5 },
})
).toMatchInlineSnapshot(
`"test({\\"age\\":5,\\"name\\":{\\"first\\":\\"Banana\\",\\"last\\":\\"Split\\"}})"`
`"test({"age":5,"name":{"first":"Banana","last":"Split"}})"`
)
})

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

Expand Down
16 changes: 8 additions & 8 deletions packages/toolkit/src/tests/createReducer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ describe('createReducer', () => {
)
)
expect(() => reducer(5, decrement(5))).toThrowErrorMatchingInlineSnapshot(
`"A case reducer on a non-draftable value must not return undefined"`
`[Error: A case reducer on a non-draftable value must not return undefined]`
)
})
test('allows you to return undefined if the state was null, thus skipping an update', () => {
Expand Down Expand Up @@ -354,7 +354,7 @@ describe('createReducer', () => {
.addCase(decrement, (state, action) => state - action.payload)
)
).toThrowErrorMatchingInlineSnapshot(
'"`builder.addCase` cannot be called with two reducers for the same action type \'increment\'"'
`[Error: \`builder.addCase\` cannot be called with two reducers for the same action type 'increment']`
)
expect(() =>
createReducer(0, (builder) =>
Expand All @@ -364,7 +364,7 @@ describe('createReducer', () => {
.addCase(decrement, (state, action) => state - action.payload)
)
).toThrowErrorMatchingInlineSnapshot(
'"`builder.addCase` cannot be called with two reducers for the same action type \'increment\'"'
`[Error: \`builder.addCase\` cannot be called with two reducers for the same action type 'increment']`
)
})

Expand All @@ -382,7 +382,7 @@ describe('createReducer', () => {
)
)
).toThrowErrorMatchingInlineSnapshot(
'"`builder.addCase` cannot be called with an empty action type"'
`[Error: \`builder.addCase\` cannot be called with an empty action type]`
)
})
})
Expand Down Expand Up @@ -507,14 +507,14 @@ describe('createReducer', () => {
.addCase(incrementBy, () => {})
)
).toThrowErrorMatchingInlineSnapshot(
`"\`builder.addCase\` should only be called before calling \`builder.addMatcher\`"`
`[Error: \`builder.addCase\` should only be called before calling \`builder.addMatcher\`]`
)
expect(() =>
createReducer(initialState, (builder: any) =>
builder.addDefaultCase(() => {}).addCase(incrementBy, () => {})
)
).toThrowErrorMatchingInlineSnapshot(
`"\`builder.addCase\` should only be called before calling \`builder.addDefaultCase\`"`
`[Error: \`builder.addCase\` should only be called before calling \`builder.addDefaultCase\`]`
)
expect(() =>
createReducer(initialState, (builder: any) =>
Expand All @@ -523,14 +523,14 @@ describe('createReducer', () => {
.addMatcher(numberActionMatcher, () => {})
)
).toThrowErrorMatchingInlineSnapshot(
`"\`builder.addMatcher\` should only be called before calling \`builder.addDefaultCase\`"`
`[Error: \`builder.addMatcher\` should only be called before calling \`builder.addDefaultCase\`]`
)
expect(() =>
createReducer(initialState, (builder: any) =>
builder.addDefaultCase(() => {}).addDefaultCase(() => {})
)
).toThrowErrorMatchingInlineSnapshot(
`"\`builder.addDefaultCase\` can only be called once"`
`[Error: \`builder.addDefaultCase\` can only be called once]`
)
})
})
Expand Down
6 changes: 3 additions & 3 deletions packages/toolkit/src/tests/createSlice.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ describe('createSlice', () => {
})
slice.reducer(undefined, { type: 'unrelated' })
}).toThrowErrorMatchingInlineSnapshot(
'"`builder.addCase` cannot be called with two reducers for the same action type \'increment\'"'
`[Error: \`builder.addCase\` cannot be called with two reducers for the same action type 'increment']`
)
})

Expand Down Expand Up @@ -587,7 +587,7 @@ describe('createSlice', () => {
reducers: (create) => ({ thunk: create.asyncThunk(() => {}) }),
})
).toThrowErrorMatchingInlineSnapshot(
'"Cannot use `create.asyncThunk` in the built-in `createSlice`. Use `buildCreateSlice({ creators: { asyncThunk: asyncThunkCreator } })` to create a customised version of `createSlice`."'
`[Error: Cannot use \`create.asyncThunk\` in the built-in \`createSlice\`. Use \`buildCreateSlice({ creators: { asyncThunk: asyncThunkCreator } })\` to create a customised version of \`createSlice\`.]`
)
})
const createAppSlice = buildCreateSlice({
Expand Down Expand Up @@ -826,7 +826,7 @@ describe('createSlice', () => {
}),
})
).toThrowErrorMatchingInlineSnapshot(
`"Please use the \`create.preparedReducer\` notation for prepared action creators with the \`create\` notation."`
`[Error: Please use the \`create.preparedReducer\` notation for prepared action creators with the \`create\` notation.]`
)
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ describe('serializableStateInvariantMiddleware', () => {
expect(getLog().log).toMatchInlineSnapshot(`
"A non-serializable value was detected in an action, in the path: \`payload\`. Value: Symbol(SOME_CONSTANT)
Take a look at the logic that dispatched this action: Object {
\\"payload\\": Symbol(SOME_CONSTANT),
\\"type\\": \\"an-action\\",
"payload": Symbol(SOME_CONSTANT),
"type": "an-action",
}
(See https://redux.js.org/faq/actions#why-should-type-be-a-string-or-at-least-serializable-why-should-my-action-types-be-constants)
(To allow non-serializable values see: https://redux-toolkit.js.org/usage/usage-guide#working-with-non-serializable-data)"
Expand Down Expand Up @@ -369,10 +369,10 @@ describe('serializableStateInvariantMiddleware', () => {
expect(getLog().log).toMatchInlineSnapshot(`
"A non-serializable value was detected in an action, in the path: \`meta.arg\`. Value: Map {}
Take a look at the logic that dispatched this action: Object {
\\"meta\\": Object {
\\"arg\\": Map {},
"meta": Object {
"arg": Map {},
},
\\"type\\": \\"test\\",
"type": "test",
}
(See https://redux.js.org/faq/actions#why-should-type-be-a-string-or-at-least-serializable-why-should-my-action-types-be-constants)
(To allow non-serializable values see: https://redux-toolkit.js.org/usage/usage-guide#working-with-non-serializable-data)"
Expand Down
17 changes: 12 additions & 5 deletions packages/toolkit/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
import { defineConfig } from 'vitest/config'

import path from 'path'
import { fileURLToPath } from 'url'

// No __dirname under Node ESM
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)

export default defineConfig({
test: {
globals: true,
environment: 'jsdom',
setupFiles: ['./vitest.setup.js'],
include: ['./src/**/*.(spec|test).[jt]s?(x)'],
alias: {
'@reduxjs/toolkit/query/react': './src/query/react/index.ts', // @remap-prod-remove-line
'@reduxjs/toolkit/query': './src/query/index.ts', // @remap-prod-remove-line
'@reduxjs/toolkit/react': './src/index.ts', // @remap-prod-remove-line
'@reduxjs/toolkit': './src/index.ts', // @remap-prod-remove-line
'@reduxjs/toolkit/query/react': path.join(__dirname,'./src/query/react/index.ts'), // @remap-prod-remove-line
'@reduxjs/toolkit/query': path.join(__dirname, './src/query/index.ts'), // @remap-prod-remove-line
'@reduxjs/toolkit/react': path.join(__dirname, './src/index.ts'), // @remap-prod-remove-line
'@reduxjs/toolkit': path.join(__dirname, './src/index.ts'), // @remap-prod-remove-line

// 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
//'^@reduxjs/toolkit/dist/(.*)$': '<rootDir>/src/*',
'@internal/': './src/',
'@internal': path.join(__dirname, './src'),
},
deps: {
interopDefault: true,
Expand Down

0 comments on commit ea1017f

Please sign in to comment.