-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add ability to override testplane storyfile configs #33
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
feat: add ability to override testplane storyfile configs #33
Conversation
25e007b to
dea2030
Compare
dea2030 to
f01ca4d
Compare
a654a6f to
1ba50d6
Compare
| "eslint": "^7.32.0", | ||
| "eslint-config-gemini-testing": "^3.0.0", | ||
| "jest": "^27.5.1", | ||
| "jest": "^29.7.0", |
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.
Old jest didn't knew about "structuredClone" or "satisfies"
| const rawAutoScreenshotGlobalSets = extractInheritedValue( | ||
| story.autoScreenshotStorybookGlobals, |
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.
Here story.autoScreenshotStorybookGlobals is Inheritable<AutoScreenshotStorybookGlobals>
More about Inheritable at inheritable-values.ts
| // Acts like "Object.assign", but: | ||
| // - Does not mutate arguments | ||
| // - Supports functions (previousValue) => nextValue | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| export function inheritValue<T extends Record<any, any>>( |
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.
Is used to mix functions and objects to calculate result value.
So, if you have:
- Object Zero
- Object A
- Function B
- Object C
- Function D
inheritValue(A, B, C, D) would work this way:
- Object A would be merged with Object Zero (with Object A having higher priority)
- Object A would be passed into Function B
- Its result will be merged with Object C (with Object C having higher priorify)
- Its result will be passed into Function D
- At the end we would receive a function, which receives
Object Zeroand returns merged object, while keeping Object Zero, Object A and Object C untouched
inheritValue(A, C) would simply return object, just like Object.assign(A,C)
extractInheritedValue is a funciton, which receives result of inheritValue and Object Zero in order to create result object
Object Zerois value from plugin's configObject A/Function Bis a value from storyfile's default exportObject C/Function Dis a value from storyfile's named export
| story.autoScreenshotStorybookGlobals = | ||
| inheritValue( | ||
| storyExtendedBaseConfig.autoScreenshotStorybookGlobals, | ||
| storyTestplaneDefaultConfigs.autoScreenshotStorybookGlobals, | ||
| storyTestlaneConfigs.autoScreenshotStorybookGlobals, | ||
| ) || {}; |
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.
Now, when we have multiple layers of overriding, its important that these values can't be mutated.
With "autoScreenshotStorybookGlobals can be a function" (which is required to be able to overwrite without overriding), it can no longer be done with just "Object.assign", so i made "./inheritable-values.ts" module, which resolves the problem
| expect(extendedStories[0].browserIds).toBe(null); | ||
| }); | ||
|
|
||
| it("should overlay story configs / file confifs / default configs", () => { |
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.
it would be better to split asserts about default/story config
current check is too difficult to understand right now
12ec028 to
9442716
Compare
9442716 to
3a94059
Compare
PR for docs at gemini-testing/testplane-docs#57