-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
separate test and default data providers #10001
separate test and default data providers #10001
Conversation
Hi @Nilegfx and thanks for your contribution 👍 We used to type result as import {
CreateResult,
DataProvider,
DeleteResult,
GetOneResult,
UpdateResult,
} from '../types';
export const defaultDataProvider: DataProvider = {
create: () => Promise.resolve<CreateResult>({ data: null }),
delete: () => Promise.resolve<DeleteResult>({ data: null }),
deleteMany: () => Promise.resolve({ data: [] }),
getList: () => Promise.resolve({ data: [], total: 0 }),
getMany: () => Promise.resolve({ data: [] }),
getManyReference: () => Promise.resolve({ data: [], total: 0 }),
getOne: () => Promise.resolve<GetOneResult>({ data: null }),
update: () => Promise.resolve<UpdateResult>({ data: null }),
updateMany: () => Promise.resolve({ data: [] }),
}; What do you think about that @djhi ? |
getList: () => Promise.resolve({ data: [], total: 0 }), | ||
getMany: () => Promise.resolve({ data: [] }), | ||
getManyReference: () => Promise.resolve({ data: [], total: 0 }), | ||
getOne: () => Promise.resolve({ data: { id: 'o' } }), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: why { data: { id: 'o' } }
instead of { data: null }
like the others?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, that was committed by mistake, I will remove it.
Awaiting further approval |
Problem
defaultDataProvider behaviour changed in V5. the change was intended to just support the tests. this affect the end users if they use the exported
defaultDataProvider
in their implementation which means one extra migration step for them and one extra migration documentation entry point react-admin team has to add.Solution
Implement testing-related changes for the
defaultDataProvider
in the right placetestDataProvider
and revert thedefaultDataProvider
to its original behaviour (which is dummy responses but at least it doesn't throw)Struggles/Challenges
I implemented the refactoring in 30 seconds, then I spent almost half an hour trying to make the
defaultDataProvider
work with theDataProvider
type but I failed. I would appreciate if one of the core members can explain to me what I miss here or how to correctly type thedefaultDataProvider
.you can reproduce the issue by just changing
export const defaultDataProvider = {
toexport const defaultDataProvider:DataProvider = {
(and of course import theDataProvider
type.I used a workaround
export const defaultDataProvider: DataProvider = {} as DataProvider
but I don't like this. I am still interested to understand this TypeError (I used AI but it couldn't give me logical answer)How To Test
giving that this change was intended to keep everything as the same, I assumed that the current tests should be enough for this simple and small refactoring
Additional Checks
master
for a bugfix, ornext
for a featureAlso, please make sure to read the contributing guidelines.